A LINQ node expression of type 'ArrayIndex' is not supported in LINQ to Entities. but linq-to-sql is supported

The project just switched from linq-to-sql to linq-to-entity, and now I get an error

The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities.

for this line:

var a = db.Table.Single(d => d.Date == dates[0]);

(Fixing this in this particular case is easy, as in

var firstDate = dates[0];
var a = db.Table.Single(d => d.Date == firstDate);

)

But why does this work in linq-to-sql, but not in linq-to-entity? Did linq-to-entity do worse than linq-to-sql? What am I missing?

+5
source share
1 answer

This is because L2E is simply trying to translate your request to the sql command. Thus, any additional things (methods such as .ToString () and other things that cannot be translated into SQL) result in this exception.

L2S, linq , IEnumerable. , : L2E linq sql, L2O IEnumerable L2S .

, L2S EF ( L2E), DbContext IEnumerable:

var a = db.Table.AsEnumerable().Single(d => d.Date == dates[0]); 
// or any other methods...
+2

All Articles