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();
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With