NHibernate Session.Query<>列列表? [英] NHibernate Session.Query<>, column list?

查看:85
本文介绍了NHibernate Session.Query<>列列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们编写了一些代码,这些代码取决于使用IQueryable实例,因此我想我们不得不使用ISession.Query<>().

We have some code written which depends on working with the IQueryable instances, so I suppose we are stuck with having to use ISession.Query<>().

在一种特殊情况下,我只想部分混合DBO,并从NHibernate将生成的SELECT语句中排除某些列. 使用Query<>可以实现这一目标吗?

In one particular case I would like to only partially hydrate the DBOs and exclude certain columns from the SELECT statement which NHibernate will generate. Is it possible to achieve that while using Query<>?

或者,是否有可能以某种方式从ICriteria转到IQueryable? (我认为对于ICriteria,可以通过使用Projections实现我所需的功能吗?)

Alternatively, is it possible to somehow go from ICriteria to IQueryable? (I think for ICriteria it is possible to achieve what I need by using Projections?)

推荐答案

IQueryable也支持投影.语法应如下所示:

Projections are supported in IQueryable as well. Syntax should be like this:

var query = session.Query<Employee>();
var list = query.Select(s => new Employee
    {
        FirstName = s.FirstName,
        LastName = s.LastName,
        ...
     })
     .ToList();

新员工甚至可能是一些DTO ...

The new Employee could be even some DTO...

有关QueryOver投影API的一些基本信息:

Some basic info about QueryOver projection API:

这篇关于NHibernate Session.Query&lt;&gt;列列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆