Linq做连表查询,可以先查出A、B表,然后再join A、B表,操作A、B组合的匿名表X
var table1=from r in shiti.a() from y in r.years where y>2010 select new { year=y, name=r.FirstName }; var table2=from t in shiti.b() from y in t.years where y>2010 select new { year=y, name=t.name } 然后根据这两个查询再通过子句join t in table1 on r.years equals t.years var tablesum=from r in table1 join t in table2 on r.years equals t.years select new { years=r.year, teams=r.name, racer=t.name }
还可以直接就写在一起
时间: 2024-11-05 15:47:39