Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何映射m-to-m关系?_C#_Entity Framework_Entity Framework Core_Entity_Automapper - Fatal编程技术网

C# 如何映射m-to-m关系?

C# 如何映射m-to-m关系?,c#,entity-framework,entity-framework-core,entity,automapper,C#,Entity Framework,Entity Framework Core,Entity,Automapper,有两个表Products和Category,它们由ProductCategory链接 我有一个产品存储库,我想在其中显示类别 public async Task<IList<Product>> GetAllWithCategoryAsync(int offset, int limit, string searchProperty, string searchValue, string orderBy, bool desc) { return awa

有两个表Products和Category,它们由ProductCategory链接

我有一个产品存储库,我想在其中显示类别

public async Task<IList<Product>> GetAllWithCategoryAsync(int offset, int limit,
    string searchProperty, string searchValue,
    string orderBy, bool desc)
{
    return await _context.Set<Product>()
        .Include(property => property.ProductCategories)
        .ThenInclude(property => property.Category)
        .ApplyFiltering(searchProperty, searchValue)
        .ApplyOrdering(orderBy, desc)
        .Skip(offset)
        .Take(limit)
        .ToListAsync();
}
类别:

public class CategoryDto
    {
        public int Id { get; set; }

        public string Label { get; set; }

        public string Thumbnail { get; set; }
    }

public class ProductCategoryDto
    {
        public int Id { get; set; }

        public string Label { get; set; }

        public double Price { get; set; }

        public string Description { get; set; }

        public string Thumbnail { get; set; }

        public int CategoryId { get; set; }
    
        public string CategoryLabel { get; set; }
    }
public class ProductDto
{
    public int Id { get; set; }

    public string Label { get; set; }

    public double Price { get; set; }

    public string Description { get; set; }

    public string Thumbnail { get; set; }
}
public class CategoryDto
    {
        public int Id { get; set; }

        public string Label { get; set; }

        public string Thumbnail { get; set; }
    }

public class ProductCategoryDto
    {
        public int Id { get; set; }

        public string Label { get; set; }

        public double Price { get; set; }

        public string Description { get; set; }

        public string Thumbnail { get; set; }

        public int CategoryId { get; set; }
    
        public string CategoryLabel { get; set; }
    }