问题
i have 2 tables master and details, in EF 4 i want to write a query to retrieve a data like this t-sql
SELECT Table1.Table1ID, Table1.A, Table2.Table2ID, Table2.B
FROM Table1 INNER JOIN
Table2 ON Table1.Table1ID = Table2.Table1Id
i use this :
using(var context =new context())
{
var p = (from i in context.Table1.Include("Table2") select i);
}
but it returns rows in table1 how can i change it to retrieve rows in table2 and have my join?
thanks
回答1:
I think you are looking for this:
var query = from a in context.Table1
join b in context.Table2 on a.Table1ID equals b.Table1Id
select new
{
a.Table1ID,
a.A,
b.Table2ID,
b.B,
};
来源:https://stackoverflow.com/questions/9501489/inner-join-in-ef-4