1

I have a query that's something like this.

Select a.*
from table1 a
inner join table2 b on a.field1 = b.field1
inner join table3 c on b.field2 = c.field2
where b.field4 = beta and c.field5 = gamma.

On LINQ, I tried to do that this way:

var query = (from a in table1
             join b in table2 on a["field1"] equals b["field1"]
             join c in table3 on b["field2"] equals c["field2"]
             where (b["field4"] == beta && c["field5"] == gamma)
             select a).ToList();

But for some reason, when I try to do this I get an error that says that the entity "table2" doesn't have the field Name = "field5", as though as the where clause was all about the last joined table and the other ones were unaccessible. Furthermore, the compiler doesn't seem to notice neither, because it lets me write c["field5"] == gamma with no warning.

Any ideas? Am I writing this wrong?

Thanks

Heathcliff
  • 3,048
  • 4
  • 25
  • 44

1 Answers1

0

See these links:
How to: Perform Inner Joins (C# Programming Guide)
What is the syntax for an inner join in linq to sql?
Why you don't create View in database, and Select your data from View in LINQ?

Community
  • 1
  • 1
Vahid Farahmandian
  • 6,081
  • 7
  • 42
  • 62