C# 如何映射m-to-m关系?
有两个表Products和Category,它们由ProductCategory链接 我有一个产品存储库,我想在其中显示类别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
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; }
}