views:

66

answers:

1

Hello All:

I am trying to run following query in entity framework 3.5

var test = from e in customers where IsValid(e) select e;

Here IsValid function takes current customer and validate against some conditions and returns false or true. But when I am trying to run the query it is giving error "LINQ Method cannot be translated into a store expression." Can any body tell me any other approach?

One approach I can think of is to write all validation conditions here, but that will make the code difficult to read.

Thanks Ashwani

+1  A: 

As the error text implies, the EF Linq provider can not translate the IsValid method into SQL.

If you want the query to execcute in the DB, then you would have to write your validation conditions in the linq statement.

Or if you simply want to fetch all customers and then check if they are valid you could do:

var test = from e in customers.ToList() //execute the query directly w/o conditions
           where IsValid(e)
           select(e);
Roger Alsing
Yea currently I am following the approach suggested by you, but it will fetch all data, then it will apply the filtering logic thus impacting the performance :(
Ashwani K