2

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

Aducci
  • 26,101
  • 8
  • 63
  • 67
motevalizadeh
  • 5,244
  • 14
  • 61
  • 108

1 Answers1

6

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,  
            };
Aducci
  • 26,101
  • 8
  • 63
  • 67