Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method 'SingleOrDefault' not supported by Linq to Entities

I read other posts on similar problem on using SingleOfDefault on Linq-To-Entity, some suggested using "First()" and some others suggested using "Extension" method to implement the Single().

This code throws exception:

Movie movie  = (from a in movies
                where a.MovieID == '12345'
                  select a).SingleOrDefault();

If I convert the object query to a List using .ToList(), "SingleOrDefault()" actually works perfectly without throwing any error.

My question is: Is it not good to convert to List? Is it going to be performance issue for more complicated queries? What does it get translated in SQL?

Movie  movie  = (from a in movies.ToList()
                where a.MovieID == '12345'
                  select a).SingleOrDefault();
like image 702
userb00 Avatar asked Nov 23 '25 14:11

userb00


1 Answers

It's not supported on provider level as far as the the linq 2 entity team is concerned but there are ways todo it check here.

But as far as I know its now supported in .NET 4.

like image 116
ntziolis Avatar answered Nov 28 '25 17:11

ntziolis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!