What is the best way to cast each item in a LINQ t

2019-04-07 12:56发布

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条回答
我欲成王,谁敢阻挡
2楼-- · 2019-04-07 13:31

Your "hacky" solution looks fine to me.

查看更多
登录 后发表回答