Is there a way to force a constant to be generated for a generated query in LINQ to SQL?

LINQ to SQL always converts values ​​to query parameters in the output. For example:

someTable.Where(n => n.Field == 5); 

gives:

 WHERE Field = @p0 

This causes problems in certain query optimization scenarios. Is there a way to force the values ​​to be embedded in the generated SQL so that it becomes:

 WHERE Field = 5 

? Will LINQ to Entities provide a way or will it behave the same?

+7
linq-to-sql linq-to-entities
source share
1 answer

Like Diego Vega from the Entity Framework team mentioned on Twitter :

constants were actually translated as built-in constants in EF forever.

therefore it seems that EF is the way, with one catch:

We believe that EF7 should parameterize more, so we need to hear when it is bad for you.

at least EF6 is much better than LINQ to SQL so that we can use EF instead.

+1
source share

All Articles