J
Jason Butera
I'm new to Entity Framework switching over from Linq to SQL. It's all
making sense to me, except for querying join tables. For example,
Entertainer (EntertainerID, EntertainerTypeID, Name, etc..) <-- Table
A
Genre (GenreID, Name) <-- Table B
EntertainerGenre(EntertainerID, GenreID) <-- Join table
I'm trying to get the lambda expression to find all entertainers
having a specific genre, but starting from the entertainer end because
I am building up my IQueryable with a search criteria object like
this:
IQueryable<Entertainer> result = ObjectContext.Entertainers;
if (Criteria.EntertainerID > 0)
result = result.Where(e => e.EntertainerID ==
Criteria.EntertainerID);
if (Criteria.EntertainerTypeID > 0)
result = result.Where(e => e.EntertainerType.EntertainerTypeID ==
Criteria.EntertainerTypeID);
if (Criteria.GenreID > 0)
result = result.???? <-- How do I filter entertainers by GenreID in
Entity Framework?
In LINQ to SQL I would do something like this:
result = ObjectContext.Genres.Join(result, g => g.EntertainerID, e =>
EntertainerID, (g,e) => g);
I need to rework my thinking since Entity Framework doesn't generated
the join table object. I'm sure the answer is easy. I just need a
little nudge.
making sense to me, except for querying join tables. For example,
Entertainer (EntertainerID, EntertainerTypeID, Name, etc..) <-- Table
A
Genre (GenreID, Name) <-- Table B
EntertainerGenre(EntertainerID, GenreID) <-- Join table
I'm trying to get the lambda expression to find all entertainers
having a specific genre, but starting from the entertainer end because
I am building up my IQueryable with a search criteria object like
this:
IQueryable<Entertainer> result = ObjectContext.Entertainers;
if (Criteria.EntertainerID > 0)
result = result.Where(e => e.EntertainerID ==
Criteria.EntertainerID);
if (Criteria.EntertainerTypeID > 0)
result = result.Where(e => e.EntertainerType.EntertainerTypeID ==
Criteria.EntertainerTypeID);
if (Criteria.GenreID > 0)
result = result.???? <-- How do I filter entertainers by GenreID in
Entity Framework?
In LINQ to SQL I would do something like this:
result = ObjectContext.Genres.Join(result, g => g.EntertainerID, e =>
EntertainerID, (g,e) => g);
I need to rework my thinking since Entity Framework doesn't generated
the join table object. I'm sure the answer is easy. I just need a
little nudge.