score:9

Accepted answer

i believe this is what you are looking for

var innerjoin =
    from rr1 in r1
    join rr2 in r2 on new {rr1.month, rr1.id} equals new {rr2.month, rr2.id}
    select new { r1 = rr1, r2 = rr2 };

the new anonymous object can be any type and has access to any properties that are available for the two collections being joined.

for a left outer join this is how it would be done

var leftjoin = 
    from rr1 in r1
    join rr2 in r2 on new {rr1.month, rr1.id} equals new {rr2.month, rr2.id} into ps
    from rr2 in ps.defaultifempty()
    select new { r1 = rr1, r2 = rr2 }; 

score:-1

if you want to join two table with some same of one column fkid is same then used following code two join both table and access to get desired result otherwise ignore.

following db is the database entities object.

note: in your code you join different entities month and id are different in data that reason you get empty result used following code

var v = (from a in db.r1.tolist()
         join b in db.r2.tolist() on a.month equals b.id

         select new
          {
            id = a.id,
            month = b.month // or a.month as you want,
            values = a.values
          });

by using these you access both table value and get accepted result. thank if it is usable for you.

score:3

this is the chain version of your query.

var delreport= r1.join(r2, l => l.id, r => r.id, (l, r) => new { lft = l, rght = r })
    .where(x => x.lft.month == x.rght.month)
    .select(_ => new{ _.rght.id, _.rght.month}).tolist();

it is tested and works with your data.


Related Query

More Query from same tag