Say I want to unit test Entity Framework's query logic, one way would be to convert the DbSet<T>
to IQueryable<T>
before building the expression trees for easy mocking. Is this "safe" and is there anything to be aware about?
AsEnumerable preserves deferred execution and does not build an often useless intermediate list. On the other hand, when forced execution of a LINQ query is desired, ToList can be a way to do that. AsQueryable can be used to make an enumerable collection accept expressions in LINQ statements.
ToListAsync(IQueryable)Creates a List<T> from an IQueryable by enumerating it asynchronously.
It is not only safe, it is legal and fully standard. This is what OO is all about. You just downcast. A DbSet
HAS to be a IQUeryable
, per the contract defined by the designers.
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