C# 映射 List GroupBy

问题描述 投票:0回答:0

我有两节课,我想上Dto。在存储库中,我使用了 GroupBy,并且在 dto 中有列表。我需要绘制这个

public class FactoryDto
{
    public int Id { get; set; }
    public string? Name { get; set; }
    public string? Description { get; set; }
    public List<ProductDto> ProductDto { get; set; }
}

public class ProductDto
{
    public int Id { get; set; }
    public int FactoryId { get; set; }
    public int OrderNumber { get; set; }
    public string Name { get; set; }
}

它在我的存储库中:

public async Task<IEnumerable<IGrouping<string, Product>>> GetList()
{
    var list = await _dbContext.database
        .Include(x => x.Lcsdefinition)
        .ToListAsync();

    var listGrouped = list.GroupBy(x => x.Product.Name);

    return listGrouped;
}

public class Factory
{
    public int Id { get; set; }
    public string? Name { get; set; }
    public string Manager { get; set; }

    public virtual ICollection<Product> Products { get; set; } = new List<Product>();
}

public class Product
{
    public int Id { get; set; }
    public int FactoryId { get; set; }
    public string Name { get; set; }
    public int OrderNumber { get; set; }
    public string Discout { get; set; }
}

我想将其从listGrouped映射到DTO?我使用了映射器,但我不知道如何使用这个分组和列表来实现它

c# list grouping automapper dto
© www.soinside.com 2019 - 2024. All rights reserved.