开发者

how to use a method with 2 parameters in my lambda expression

开发者 https://www.devze.com 2023-03-08 09:12 出处:网络
I use linq to access a table from my DB using Entity Framework MyDBEntities context = new MyDBEntities;

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消