Linq – How do i get an inner join in a WCF Data Service

linqodatawcf-data-services

Lets say i have 2 tables, table1 and table2, with a shared key "id"

if i want an inner join of those two tables using sql, i'd do something like

select id, x, y, z
from table1
inner join table2
on table1.id = table2.id

I now get rows in table 1 that only intersect occur in table 2.

how do i get the equivalent in wcf data service/odata linq syntax?

i'm expecting something like:

var q = (from t in svc.Table1.Expand("Table2")
    where t.Table2.Any()
    select t) as DataServiceQuery<Table1>;

but that gets me an exception about Any().
I've tried .Join and that isn't supported either.
I've tried .Count and that fails too.
.Intersect looks like it only takes another enumerable, so that doesn't look like what i want…

i think i'm missing something really obvious or simple…

Edit: this appears to be a dup of this How do I use OData Expand like a SQL join?

Best Answer

Take a look at the answers to this type of question. The current version of WCF Data Services (OData) does not support joins even if your underlying data contract does (i.e. if you're layering on top of Entity Framework 4 for instance).

Related Topic