views:

26

answers:

2

Hi

I have following entities

A_Entity
-----------
AId

AB_Entity
-----------
AId
BId

B_Entity
-----------
BId

I have a function that helps in building the query based on the input provided. In this case I have to build a query to fetch all A_Entities that have matching BId (provided as input to the function)

public static IQueryable<A_Entity> BuildQuery(IQueryable<A_Entity> query, int BId)
{
   // Something like query.where(a => a.select_all_a_that_have corresponding_b_with_Id_equalto_BId)
}

I know there has to be join between AB_Entity and A_Entity but dont know how to apply it to build IQueryable and return back.

Thanks

+1  A: 
query = query.Where(a => a.AB_Entities.Any(ab => ab.BId == BId));
return query;
JeffN825
@JeffN825: This will not work since AB_Entities is a EntitySet<AB_Entity>
stackoverflowuser
Sorry. Stupid mistake.
JeffN825
A: 
var result = from a in query
             from b in AB_Entities
             where a.Id = b.AId && b.BId = BId
             select a;
Hasan Khan