Linq: Filtering on related entity

Posts   
 
    
pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 15-Jul-2008 12:44:47   

Hi,

I guess I'm not sure how to filter on related entities with Linq to LLBLGen:

This: int value =3; var q = (from c in metaData.Assignment where c.Group2AssignmentItem.Where(o => o.GroupId== value) select c);

Produces: Error 5 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<DAL.EntityClasses.Group2AssignmentEntity>' to 'bool'

Thanks for your hep, Patrick

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39866
Joined: 17-Aug-2003
# Posted on: 15-Jul-2008 13:09:05   

Please use the latest build of the runtimes, and if you're not sure, please post the runtime lib version here (build nr. see guidelines in this forum how to obtain it).

Frans Bouma | Lead developer LLBLGen Pro
pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 15-Jul-2008 19:26:45   

Otis wrote:

Please use the latest build of the runtimes, and if you're not sure, please post the runtime lib version here (build nr. see guidelines in this forum how to obtain it).

So you seem to say that the code should be running if I had the right version?

I thought my syntax was wrong.

I updated my signature: LLBLGen 2.6 - June-6-2008, Runtime Library v2.6.08.0709, SQL 2005, C#, .NET 3.5, Adapter Template

Thanks, Patrick

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39866
Joined: 17-Aug-2003
# Posted on: 15-Jul-2008 19:32:34   

The first thing always is to check whether the customer has teh right runtime library as it might be that it's already fixed so we can save each other some time simple_smile

Your syntax is indeed wrong: var q = (from c in metaData.Assignment ** where c.Group2AssignmentItem.Where(o => o.GroupId== value)** select c);

the 'where' keyword requires a boolean expression. However c.Group2AssignmentItem.Where(o => o.GroupId== value) returns 0 or more entities. You should use .Any instead of .Where

Frans Bouma | Lead developer LLBLGen Pro