Hello dear experts! I want to ask a question on the Entity Framework. For example, I have this code
return from city in context.City where SomeFunc(city, id, name) select new City(city); bool SomeFunc(City city, int id, int name) { return city.Id == id || city.Name == name || city.Code == name; } when I execute code I get such an exception
This method cannot be translated to a store expression.
On the Internet, it is advised to use the AsEnumerable method
return from city in context.City.AsEnumerable() where SomeFunc(city, id, name) select new City(city); It works but very slowly because context.City.AsEnumerable () gives me all the cities from the table at once and then performs the function SomeFunc for them
You can write this:
return from city in context.City where city.Id == id || city.Name == name || city.Code == name select new City(city); and everything will work quickly. But then such a problem will turn out - this condition can be used even in some method and then it will be necessary to duplicate this code which is not good. How to be? Maybe in the Entity Framework there is some way to avoid duplicating code and fulfilling conditions in SQL and not in C #? Thank you in advance!