加入2个表后我有以下列表
Id Name IsActive FeeName Amount
1 Test 1 Fee1 100
1 Test 1 Fee2 200
1 Test 1 Fee3 300
我有一个叫做产品的课程
public class Products
{
public int Id { get; set; }
public string ProductName { get; set; }
public bool IsActive { get; set; }
public List<ProductFee> ProductFunding { get; set; }
}
产品费用类有FeeName和amount属性,
我需要创建一个类似于上面类的对象 1,test,1,ProductFee列表
答案 0 :(得分:1)
var products = results.GroupBy(r => new { r.Id, r.Name, r.IsActive }).Select(g => new Products(){ Id = g.Key.Id, ProductName = g.Key.Name, IsActive = g.Key.IsActive, ProductFunding = g.Select(p => new ProductFee(){ FeeName = p.FeeName, Amount = p.Amount }).ToList() });