Suppose the following table is MyObjects :
Id (PK, int) DecimalField (decimal) TextField (nvarchar)
I added an extra index on DecimalField .
Consider a LINQ to Entities query to retrieve an object:
db.MyObjects.FirstOrDefault(r => r.DecimalField == localValue1 && r.TextField == localValue2)
Due to the index, it is important that the generated EF query DecimalField order of the properties in the WHERE clause the same (i.e. DecimalField first and TextField second), otherwise the table will be scanned and the index will be useless. How can I make EF stick to a certain order in a WHERE clause? Is there a difference between special and compiled queries?
source share