问题
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);
回答1:
Your "hacky" solution looks fine to me.
来源:https://stackoverflow.com/questions/1240087/what-is-the-best-way-to-cast-each-item-in-a-linq-to-entities-query-to-an-interfa