3

I use linq to access a table from my DB using Entity Framework

MyDBEntities context = new MyDBEntities;
int id = 111;
var item = context.MyTable.Where(i => i.id == id).Single();

This works fine but now I create a method I wish to use instead of the id check:

bool AreNear(string Adress, object Adress)

I'd like to use that way

 string adress = "...";
 var item = context.MyTable.Where(i => AreNear(i.adress,adress) ).Single();

but I get an error at the execution saying I can't use the method in my query is there a way to make it work?

1
  • You are using EF, the queries (Where) have to be converted to SQL... Commented May 26, 2011 at 14:23

1 Answer 1

1

Unfortunately, there is no way to make it work.
The reason for this is that the LINQ query isn't really executed as .NET code but it is translated into SQL by the EF provider. This EF provider doesn't know how to translate AreNear into SQL, so it fails.

Sign up to request clarification or add additional context in comments.

1 Comment

Then tell "why" or make it a comment.

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.