zoukankan      html  css  js  c++  java
  • Linq 中使用Join into Aggregate,Left out join,

    问题:

        Products={{ID=1,Name=ProductName_1},{ID=2,Name=ProductName_2},......,{ID=n,Name=ProductName_n}},

        Orders ={{ID=1,ProductID=ProductID_1,CustomerName=CustomerName_1},......,{ID=m,ProductID=ProductID_m,CustomerName=CustomerName_m}}

        怎样产生

        ProductSummary={{ProductName=ProductName1 , Customs="CustomerName_i1,....,CustomerName_is1,"},.....,{ProductName=ProductNamen , Customs="CustomerName_in,....,CustomerName_isn,"}}

       其中CustomerName_in,....,CustomerName_isn,是所有购买了Product n的客户名字。 如果一个产品没有人订 CustomerName="无人问津"

    解决办法:

       var query = from p in Products

                         join o in Orders on p.ID=o.ProductID into og

                         select new { ProductName = p.Name, Customers=og.DefaultIfEmpty(new Order { CustomerName="无人问津"}).Aggregate("",(x,y)=>x+y.CustomerName+",")};

    推广:可以使用Aggregate来计算更多的统计信息,如总销量....

  • 相关阅读:
    flex-grow带来的排版问题
    css文本样式,空格
    第八周作业
    JSON简介
    Ajax
    java applet小程序
    java ee 部分分析
    xml相关知识
    JAVA EE体系结构图
    java EE初次理解
  • 原文地址:https://www.cnblogs.com/mjgb/p/2113840.html
Copyright © 2011-2022 走看看