C# – the best way to cast each item in a LINQ to Entities query to an interface

ciqueryablelinqlinq-to-entities

I have an entity object 'User' which implements 'IUser':

IQueryable<User> users = Db.User;
return users;

But what I actually want to return is:

IQueryable<IUser>

So what is the best way to convert

IQueryable<User>

to

IQueryable<IUser>

without actually running the query? Right now I am doing this but it seems like a hack:

IQueryable<IUser> users = Db.User.Select<User, IUser>(u => u);

Best Answer

Your "hacky" solution looks fine to me.