点符号相当于JOIN

时间:2010-09-13 10:54:52

标签: linq syntax c#-3.0

string[] names = { "Burke", "Connor", "Frank", 
   "Albert", "George", "Harris", "David" };

peoples[] people = {
                   new peoples("Connor",20),
                   new peoples("John",22),
                   new peoples("Merry",33),
                   new peoples("Frank",65),
                   new peoples("Frank",34),
                   new peoples("George",19)
               };

var query = from n in names
            join p in people on n equals p.Name into matching
            select new { Name = n, Count = matching.Count() };

请告诉我这个查询的点符号。 感谢。

1 个答案:

答案 0 :(得分:2)

连接的点符号取决于它后面的内容以及您是否有“into”子句(对于组连接)。在这种情况下,它将是:

var query = names.GroupJoin(people, n => n, p => p.Name,
                   (n, matching) => new { Name = n, Count = matching.Count() });
  • 如果您没有使用“into”,则会使用Join代替GroupJoin
  • 如果你之后只有“选择”以外的任何东西,它会引入一个新的透明标识符,以保持“(n,匹配)”作为元组,有效。