I have a method that ‘has no translation to SQL’ that I want to perform on an IQueryable, is there a way to force the IQueryable to execute without having to store it in some intermediate class?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Is the problem that you want your method to execute locally rather than in the database? If so,
AsEnumerableis your friend. It’s a very simple method, something like:The important thing is that it makes the compile-time type of the result
IEnumerable<T>rather thanIQueryable<T>, which means any LINQ query operators you call after that will be the LINQ to Objects ones instead of LINQ to SQL.For example:
You could call
ToListas suggested elsewhere, but if you’re doing filtering and don’t really need the full list in memory, callingAsEnumerableand filtering that result will be more efficient than loading everything first.