I have those methods:
public int count(
Guid companyId, Expression> isMatch)
{
var filters = new Expression&
When using linq-to-entities you cannot use arbitrary .NET methods in query. Each method used in the query must be translatable to SQL. It will not help you to return Expession
because where condition must be evaluated for each record on the database server.
For EF your code means something like:
SELECT COUNT(*)
FROM ...
LEFT JOIN ...
WHERE IsMatch(....)
Because EF validates function names passed to the query it will throw exception because it doesn't know IsMatch equivalent on SQL server.
The only possible functions which can be used in Linq-to-entities are:
EdmFunctions
EdmFunctions are methods marked with EdmFunctionAttribute
which maps .NET function to SQL counterpart. Those functions usually cannot be executed in common .NET code because they do nothing or throw exception. They are only function place holder for Linq-to-entities. Available EdmFunctions are:
System.Data.Objects.EntityFunctions
System.Data.Objects.SqlClient.SqlFunctions
EdmFunction
attribute to the SQL function imported to designer.I have already described how to create model defined function in another answer. Creating mapped SQL function is pretty similar. Instead of manually creating Function
element in EDMX you will map EdmFunctionAttribute
properties to imported SQL function.