更新时间:1970-01-01 07:55:12
如果要扁平化"可枚举的枚举,则SelectMany
扩展方法可以解决问题.
If you want to "flatten" enumerable of enumerables, theSelectMany
extension method will do the trick.
var orders = new List<Order>();
var distinctOrderLines = orders.SelectMany(order => order.OrderLines).Distinct();
朋友,
据我了解,.. Iam为您的问题提供了一个小型且***的解决方案
下面的QueryExpression可以解决您的问题
//第一步:从订单中获取订单行
var OrderLines =从objOrder.OrderLines.ToList()中的pc1开始 选择pc1;
//step2:获取不同的产品代码
var productCodes =(来自OrderLines中的p1
选择新的{p1.ProductCode}).Distinct();
//Step3:将不同的产品代码绑定到GridView
gvOrderLines.DataSource = productCodes;
gvOrderLines.DataBind();
希望以上代码对您有所帮助.
祝一切顺利...编码愉快.
***的问候,
Venkatesh velpula.
Hi Friend,
According to my knowledge..here Iam giving a small and best solution for your problem
The below QueryExpression can solve your problem
//Step1: Get the OrderLines from Orders
var OrderLines = from pc1 in objOrder.OrderLines.ToList()
select pc1;
//step2: Get the Distinct ProductCodes
var productCodes = (from p1 in OrderLines
select new { p1.ProductCode }).Distinct();
//Step3: Bind the Dictinct ProductCodes to GridView
gvOrderLines.DataSource = productCodes;
gvOrderLines.DataBind();
I hope above code will help you.
All the Best...Happy Coding.
Best Regards,
Venkatesh velpula.
您是否尝试过在没有"as"的情况下进行操作?我认为var的全部要点是您不需要指定类型吗?如果使用调试器,则c的类型是什么?
Have you tried doing it without the ''as'' ? The whole point of var, I thought, was that you don''t need to specify the type ? If you use the debugger, what IS the type of c ?