在多个IEnumerable上快速加入

时间:2018-12-02 21:39:29

标签: c# linq

s_records, q_records, d_records, i_records类型为IEnumerable<MyRecord>querytwo的所有类型均按预期工作。但是,如果我想在相同字段的相同相等性上加入多个IEnumerable,该怎么办?

        var querytwo = from a in s_records
                       join b in q_records
                       on a.date equals b.date
                       select new { s_line = a.line, q_line = b.line };

        Console.WriteLine(querytwo.Count());

query无效,我尝试与querytwo中的操作相同,但是要加入多个IEnumerable<MyRecord>

        var query = from a in s_records
                    join b in q_records                       
                    join c in d_records
                    join d in i_records
                    on a.date equals b.date equals c.date equals d.date
                       select new { s_line = a.line, q_line = b.line, d_line = c.line, i_line = d.line };

1 个答案:

答案 0 :(得分:2)

您的语法在某种程度上不正确。应该是:

var querytwo = from a in s_records             
               join b in q_records on a.date equals b.date 
               join c in d_records on b.date equals c.date
               join d in i_records on c.date equals  d.date
               select new { 
                   s_line = a.line, 
                   q_line = b.line, 
                   d_line = c.line,
                   i_line = d.line 
               };