INNER JOIN in EF 4

吃可爱长大的小学妹 提交于 2019-12-11 03:37:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!