Ivan
Ivan

Reputation: 7746

Fast join on Multiple IEnumerable

Whith s_records, q_records, d_records, i_records all of type IEnumerable<MyRecord>, querytwo works just as expected. But what if I want to join multiple IEnumerable on the same equality of the same fields?

        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());

This query doesn't work I am trying to do the same as in querytwo, but join on multiple 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 };

Upvotes: 1

Views: 94

Answers (1)

Ousmane D.
Ousmane D.

Reputation: 56393

Your syntax is to off to some extent. it should be:

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 
               };

Upvotes: 2

Related Questions