Method 'SingleOrDefault' not supported by Linq to Entities
Posted
by user300992
on Stack Overflow
See other posts from Stack Overflow
or by user300992
Published on 2010-04-20T16:00:58Z
Indexed on
2010/04/20
16:03 UTC
Read the original article
Hit count: 860
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();
© Stack Overflow or respective owner