0

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
  • What is IsValid()? You might be able to rewrite it as an expression, which would work. Depends on what it contains. Commented May 12, 2010 at 14:22

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

1 Comment

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 :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.