简体   繁体   English

将LINQ to Entities查询中的每个项目转换为接口的最佳方法是什么?

[英]What is the best way to cast each item in a LINQ to Entities query to an interface?

I have an entity object 'User' which implements 'IUser': 我有一个实体对象'User'来实现'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);

你的“hacky”解决方案对我来说很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM