views:

72

answers:

3

Sometimes I get an exception like this: "This method cannot be translated into a store expression". Is there any list what EF 4.0 supports and what doesn't? I have just googled, but nothing ;(.

+1  A: 

Supported and Unsupported LINQ Methods (LINQ to Entities)
http://msdn.microsoft.com/en-us/library/bb738550.aspx

Robert Harvey
Your link only mentions query operators. What about methods/properties like `String.Length`, `String.Contains`, and so on?
Gabe
Gabe +1, looking for the same.
Overdose
@Gabe: I pasted the link to that in my answer.
Reed Copsey
A: 

By design, LINQ to Entities requires the whole LINQ query expression to be translated to a server query. Only a few uncorrelated subexpressions (expressions in the query that do not depend on the results from the server) are evaluated on the client before the query is translated. Arbitrary method invocations that do not have a known translation are NOT supported. To be more specific, LINQ to Entities only support Parameterless constructors and Initializers. Please take a look at LINQ to Entities, what is not supported? for more info.

Morteza Manavi
+2  A: 

The following lists the LINQ methods which are supported.

LINQ To Entities also provides the following Canonical Function Mapping for CLR type operations to SQL functions. These are the methods that should be supported, by default, by all providers. For example, String.Contains should always map to a LIKE statement in SQL, or an IndexOf statement.

However, be aware that different providers are free to do their own mapping. I have seen some EF providers which do not support the full "canonical" list of functions, or add their own. Since each EF provider does the mapping themselves, it's impossible to give a definitive answer, other than the standard listed above.

Reed Copsey
That's the same link as the one I posted.
Robert Harvey
@Robert: Not the second link - the Function Mapping shows the actual methods that are ported (ie: String.Contains, etc).
Reed Copsey
Ah, I see. Wow, that's an obscure page; no wonder I couldn't find it before. Clearly I'm not ready yet to join the EF 4.0 inner sanctum. :)
Robert Harvey