System.InvalidCastException on FilterOn

Posts   
 
    
neilx
User
Posts: 267
Joined: 02-Nov-2007
# Posted on: 30-Aug-2012 23:49:36   

3.1.11.706 Final (SD.LLBLGen.Pro.DQE.SqlServer.NET20.dll) 3.1.12.0222 (SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll 3.1.12.216 (SD.LLBLGen.Pro.LinqSupportClasses.NET35) DotNet 4.0 vs2010 project Adapter template

I think am doing something dumb but I can't see it at the moment. I get a

System.InvalidCastException: Unable to cast object of type 'System.Linq.Expressions.PropertyExpression' to type 'SD.LLBLGen.Pro.LinqSupportClasses.ExpressionClasses.SetExpression'.

when running this code to return an IQueryable<CustomerEntity> with an Orders Prefetch path filtered on where the employee is in Madrid:

var  = metaData.Customer.Select(a => a)
     .WithPath(b => b.Prefetch<OrderEntity>(c => c.Orders)
        .FilterOn(d => metaData.Employee.Any(e => e.EmployeeId ==d.EmployeeId &&  e.City == "Madrid")));

I think I have used the metadata.Entity syntax in a FilterOn before, so what am I doing wrong here?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 31-Aug-2012 06:57:39   

The query must be executed correctly. You are using some old runtime libraries, please update to the latest one, as some improvements had been made around Linq aliasing.

Then, the query could be written in a clearer way, and easy to the framework and sql to produce:

var x = metaData.Customer.Select(a => a)
                .WithPath(b => b.Prefetch<OrderEntity>(c => c.Orders)
                    .FilterOn(o => o.Employee.City == "Madrid"));

            var results = x.ToList();
David Elizondo | LLBLGen Support Team
neilx
User
Posts: 267
Joined: 02-Nov-2007
# Posted on: 31-Aug-2012 14:38:51   

That worked. Thanks very much:-)