Clarifying "AsEnumerable: not only to use unsupported methods"

As you have probably seen with Roger comment and his blog post about this, my post “AsEnumerable: not only to use unsupported methods” wasn’t very clear. So I will try to clarify it.

In my old post Entity Framework Include with Func”, Niraj posted an interesting comment. In fact, he wants to do an Include with condition which doesn’t return an anonymous type and Daniel Simmons proposed me a great solution but it is good only for Include with condition for an EntityCollection<T> (so children relationship end) and not for parent relationship end.

So I try to do the same for the parent relationship end.

In my request, I “want to get Northwind orders if date is greater or equal than 1998 with their property Customer only if country is France with a LINQ to Entities request”. So my method will return an IEnumerable<Order>.

I agree with Roger that in most cases, it isn’t a good idea to use AsEnumerable, particularly if you don’t want all of the sql query results (if you use a where (except if you call a LINQ To Entities unsupported method) or a restrictive select for example) but in my sample, I think you can use AsEnumerable extension method.

This entry was posted in 7671, 7674. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *