【发布时间】:2015-09-27 23:53:50
【问题描述】:
我有两个不同的类,如下所示:
public class ProductDto : IDto
{
public int Parentproductid { get; set; }
public string Parentproductnumber { get; set; }
public int Supplierid { get; set; }
//More properties
}
public class OrderItemsDto : IDto
{
public int Poid { get; set; }
public System.DateTime Createddate { get; set; }
public int Parentproductid { get; set; }
public int Variationid { get; set; }
public System.DateTime Deliverydate { get; set; }
//More properties
}
我需要做的基本上是在 parentproductid 上加入 List<OrderItemsDto> 和 List<ProductDto>(就像它们是数据库表一样)并生成另一个列表。
我尝试过使用Union,如下所示:
List<ProductDto> productParents = productManager.getList();
List<OrderItemsDto> orderItemsList = ordermanager.getList();
gvPurchaseOrderItems.DataSource = orderItemsList.Select(o => o.Parentproductid).Union(productParents.Select(pp => pp.parentproductid));
但这只会给我一个List<int> parentproductids 的结果,在这两个列表中我需要具有两个类的属性(上述情况下为列)的东西。而且我找不到如何使用 Select 扩展方法选择多个属性(我是初学者)
我知道我可以创建一个新类并手动映射属性,但我真的很好奇如何使用 lambda 表达式或 linq 来做到这一点。这可能吗,如果您能给我指明方向,我将不胜感激。谢谢。
【问题讨论】:
标签: c# linq list generics lambda