简体   繁体   English

仅选择Nhibernate IQueryable中的特定列

[英]Select only specific columns in Nhibernate IQueryable

I have an entity that is mapped (using Fluent Nhibernate) to a view in the database. 我有一个实体(使用Fluent Nhibernate)映射到数据库中的视图。
The view has many columns, but the user can choose the columns that he wants to see in a report. 该视图有许多列,但是用户可以选择他想在报表中查看的列。 I would like the resulting database query to only contain those columns, for performance reasons. 出于性能原因,我希望结果数据库查询仅包含这些列。
I think this can be done using QueryOver<>, as explianed here: How to select only a few columns in my NHibernate query? 我认为可以使用QueryOver <>完成此操作,如下所述: 如何在NHibernate查询中仅选择几列?
The problem is that I need to obtain an Iqueryable for paging and sorting, so I am using the Linq Session.Query<> extension method. 问题是我需要获得一个Iqueryable来进行分页和排序,所以我使用的是Linq Session.Query <>扩展方法。
I either need a way to convert the QueryOver to an IQueryable or to apply the projection directly to the IQueryable. 我或者需要一种将QueryOver转换为IQueryable或将投影直接应用于IQueryable的方法。 As the columns to select are dynamic, I cannot create a new entity class or a new mapping. 由于选择的列是动态的,因此我无法创建新的实体类或新的映射。
Thanks 谢谢

Do you really need to use LINQ? 您真的需要使用LINQ吗? If so, check out System.Linq.Dynamic NuGet package, which is based on Microsoft code. 如果是这样,请签出基于Microsoft代码的System.Linq.Dynamic NuGet程序包。 I wrote some posts on that which may help you, see for example: Dynamic Linq Extension Method . 我写了一些可能对您有所帮助的文章,例如: Dynamic Linq Extension Method You could do better with Criteria or HQL, though. 不过,使用Criteria或HQL可以做得更好。

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

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