Relations and Linq

Posts   
 
    
ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 11-Aug-2008 21:12:24   

How would I convert this to a simple Linq expression? I got a bit confused on the edges and subpaths.


            RelationPredicateBucket bucket = new RelationPredicateBucket();
            bucket.Relations.AddRange(CompanyEntity.Relations.GetAllRelations());
            bucket.PredicateExpression.AddWithAnd(NameFields.Name == Name);
            bucket.PredicateExpression.AddWithAnd(LocationFields.LocationAddress == Street);
            bucket.PredicateExpression.AddWithAnd(LocationFields.LocationCity == City);
            bucket.PredicateExpression.AddWithAnd(LocationFields.LocationState == State);

Company's have Names and Locations.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39866
Joined: 17-Aug-2003
# Posted on: 11-Aug-2008 21:29:46   

Prefetch paths are for fetching graphs in 1 go. filtering on related entities is something else: you want to fetch a single set, and limit that set on related entities.

Say I want to fetch all orders, from customers which are from Germany:

var q = from o in metaData.Order where o.Customer.Country=="Germany" select o;

here, I navigate over 'Customer', and the provider knows what relation that is and does the join for you simple_smile

With this info, could you formulate the query yourself, or did you run into a wall while trying?

Frans Bouma | Lead developer LLBLGen Pro
ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 11-Aug-2008 21:33:44   

Ah.

I thought I have to add Relations with prefetches in Linq.

It seems I was making the simple complex.

Ian