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 ExpessionNET code because they do nothing or throw exception.
They are only function place holder for Linq-to-entities. Available EdmFunctions are: Predefined EdmFunctions in System.Data.Objects. EntityFunctions Predefined EdmFunctions for SQL Server (not compact) in System.Data.Objects.SqlClient.
SqlFunctions Custom mapped SQL functions - import wizard in Entity designer allows you import SQL functions (except table valued functions). You can after that write custom static . NET function and map it by EdmFunction attribute to the SQL function imported to designer Custom model defined functions - this is special function written manually in EDMX file (opened as XML).
It is custom reusable part of Entity SQL 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.
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: Cannonical functions with predefined mapping to SQL equivalent 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: Predefined EdmFunctions in System.Data.Objects. EntityFunctions Predefined EdmFunctions for SQL Server (not compact) in System.Data.Objects.SqlClient. SqlFunctions Custom mapped SQL functions - import wizard in Entity designer allows you import SQL functions (except table valued functions).
You can after that write custom static . NET function and map it by EdmFunction attribute to the SQL function imported to designer. Custom model defined functions - this is special function written manually in EDMX file (opened as XML).
It is custom reusable part of Entity SQL. 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.
You're passing an expression that calls a function named IsMatch. LINQ to Entities doesn't know what to do with this function.
™¦: I updated the question.. – Naor May 1 at 2:29 LINQ to Entities doesn' know how to turn IsMatch into SQL. You need to replace it with an expression tree. – SLaks?
May 1 at 2:31 ♦: What do you mean by "replace it with an expression tree"? – Naor May 1 at 2:34.
I was dealing with similar problem. Working solution was using .AsEnumerable() before trying to use my custom method. You can take a look at it here.
Adding AsEnumerable will load the whole table to memory and after the filter of companyId I still have a lot of results.. – Naor May 1 at 2:42 @Naor: Ok then, it worked for me becuase I was working with few results. Didn't know about yours. – Dampe May 1 at 2:53.
Actualy, what you are passing to count look like this function: bool anonymous_delagate#123(T entity) { return entity. IsMatch(a,b,c,d) } But, this would require EF to know, what really method IsMatch, that is called on this entity, means. Only thing I can think about recomending now is to use some kind of dynamic expression-forging to create this query dynamicaly.
Or rework your design to somethign different. Actualy, there is easier and normal method, that requires few steps to acomplish. Make method IsMatch static.
Return Expression directly from IsMatch. Pass it like : ({your entity here}. IsMatch({parameters})) Rest can remain same as you have now.
Edit: Example This will work with specific entity, so I will asume your entity is Order. Substitute your own entity. Public static Expression> IsMatch(int id, ...) // static method, that returns filtering expression { return I => i.Id == id; // create the filtering criteria } Then call it like: count(some_guid, Order.
IsMatch(entityId, inviterId, routeId, luggageTypeId)).
I didn;t understand your last two steps. – Naor May 1 at 12:54 Does the static IsMatch method you wrote must return delegate that NOT based on other functions? Can I use for example " return I => i.
MyMethod(id);"? – Naor May 2 at 3:03 No. You must use eiter create it completly as expression or like Ladislav says, map your functions to stored procedures.
– Euphoric May 2 at 6:23.
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. Because EF validates function names passed to the query it will throw exception because it doesn't know IsMatch equivalent on SQL server. 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. Predefined EdmFunctions in System.Data.Objects. Predefined EdmFunctions for SQL Server (not compact) in System.Data.Objects.SqlClient.
Custom mapped SQL functions - import wizard in Entity designer allows you import SQL functions (except table valued functions). You can after that write custom static . NET function and map it by EdmFunction attribute to the SQL function imported to designer.
Custom model defined functions - this is special function written manually in EDMX file (opened as XML). It is custom reusable part of Entity SQL. 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.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.