-2

I have to Records Set as a C# lists for two different Classes:

class Foo{
   string A1;
   string B1;
   string A2;
   string B2;
}

class Faa{
   string A;
   string B;
   string C;
}

The main idea is to Join Faa and Foo with booth (A, B) and the result will be (A1,B1,C1,A2,B2,C2) The C1 and C2 are the respective equivalent of couple (A1,B1) and (A2,B2) in the Faa records.

I would like to do this join using Linq to Object.

Thanks

  • 2
    Possible duplicate of [How to do joins in LINQ on multiple fields in single join](https://stackoverflow.com/questions/373541/how-to-do-joins-in-linq-on-multiple-fields-in-single-join) – Kenneth K. Jan 12 '18 at 16:21
  • 1
    Do you know how to do a single join? If so just do that twice... – Chris Jan 12 '18 at 16:24
  • 1
    A list of things you want isn't a question. *What's your question*? – Eric Lippert Jan 12 '18 at 18:20

1 Answers1

0

You just need to join twice to the record set containing Faas:

var ans = from ro in rFoos
          join ra1 in rFaas on new { A = ro.A1, B = ro.B1 } equals new { ra1.A, ra1.B }
          join ra2 in rFaas on new { A = ro.A2, B = ro.B2 } equals new { ra2.A, ra2.B }
          select new { ro.A1, ro.B1, C1 = ra1.C, ro.A2, ro.B2, C2 = ra2.C };
NetMage
  • 26,163
  • 3
  • 34
  • 55