How can I do the following in linq to entities for entity framework::
public static Expression<Func<T, bool>> IsOk<T>(long? entityId)
{
return x => (!entityId.HasValue || entityId.Value == x.GetEntityId());
}
The x.GetEntityId() returns an exception since it doesn’t recognize the method.
You cannot – your database cannot run
GetEntityId()(since it does not understand it) hence your Linq provider cannot translate it.UPDATE
So how can you solve it:
GetEntityId()) then this needs to be done at the client: return all rows and do the filtering in C# subsequently. Of course it is needless to say what it is gonna do to your performance.