cs0815
cs0815

Reputation: 17408

Linq get all objects that implement interface

Is it possible to get something like this:

return Session.Query<A>().Where(x => x is B).ToList();

where B derives from A working for an interface (i.e. get all objects that implement certain interface)? Thanks.

Upvotes: 2

Views: 3515

Answers (1)

mipe34
mipe34

Reputation: 5666

You can't directly convert this statement to SQL. First you will have to evaluate the query or use AsEnumerable().

return Session.Query<A>().AsEnumerable().Where(x => x is B).ToList();

Or:

return Session.Query<A>().AsEnumerable().OfType<B>().ToList();

The part after the AsEnumerable will be executed in memory.

Upvotes: 1

Related Questions