Omar
Omar

Reputation: 40162

Why can't I use LINQ's First/FirstOrDefault method in OData?

I can do the following:

container.Users.Where(u => u.Name == "Omar").FirstOrDefault()

but

container.Users.FirstOrDefault(u => u.Name == "Omar")

returns a NotSupportedException (The method 'FirstOrDefault' is not supported.).

Since these are essentially the same, why is it no supported?

Upvotes: 11

Views: 4478

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564323

The LINQ Translation engine used by the OData provider doesn't handle every scenario.

While these are logically the same, the expression for each must be generated to build the query string. The engine doesn't support the second form.

Upvotes: 14

Related Questions