How to use a method with two parameters in my lambda expression

I am using 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 am creating a method that I want to use instead of checking id:

bool AreNear(string Adress, object Adress)

I would like to use this method

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

but I get an error on execution saying that I can’t use the method in my request, is there a way to make it work?

+3
source share
1 answer

Unfortunately, there is no way to make it work.
The reason for this is that the LINQ query is not actually executed as .NET code, but it is translated into SQL by the EF provider. This EF provider does not know how to translate AreNearto SQL, so it fails.

+1
source

All Articles