alex
alex

Reputation: 720

Using PredicateBuilder in Projections with child collections

I'm using PredicateBuilder ( From LinqKit).

This is my code :

Dim mylist as IQueryable(of MyObj1)
Dim pred1 = PredicateBuilder.True(Of Myobj1)()
Dim pred2 = PredicateBuilder.True(Of ch1)()
Dim pred3 = PredicateBuilder.True(Of ch2)()
pred1=pred1.And(Function(t) t.id=5)
pred2=pred2.And(Function(t1) t1.vl1>=7)
pred3=pred3.And(Function(t2) t2.quantity<=4)
mylist = (From t In context.Myobj1s.Where(pred1)Select New With { _
     .Parent = t, _
    .child1 = t.ch1s.AsQueryable.Where(pred2), _
.child2 = t.ch2s.Asqueryable.Where(pred3) _
 }).ToList

But I'm getting this error :

The LINQ expression node type 'Invoke' is not supported in LINQ to Entities.

I try also to use AsExpandable instead of AsQueryable, but the problem is not resolved.

Upvotes: 1

Views: 809

Answers (1)

Gert Arnold
Gert Arnold

Reputation: 109079

There is an alternative to Linqkit's PredicateBuilder that doesn't use Expression.Invoke. This makes it far more suitable for predicates that are to be translated by a SQL provider.

If you use this predicate builder you can use your code without any changes.

Upvotes: 1

Related Questions