从实体获取单个列 [英] Getting single column from an entity

查看:104
本文介绍了从实体获取单个列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您如何从一个查询,而不是一个整体对象获取单个列回来?

How can you get a single column back from a query instead of a whole object?

我可以做这样的事情来获得整个对象,但我要的是名称:

I could do something like this to get the whole object, but all I want is the names:

IList<Tribble> tribbles = session.CreateCriteria(typeof(Tribble)).List<Tribble>();
IList<string> names = new List<string>();
foreach (Tribble t in tribbles) {
    names.Add(t.Name);
}



我想可以指定其他条件,所以有可能?刚刚从检索排除某些列

I would like to be able to specify additional criteria, so is it possible to just exclude certain columns from being retrieved?

推荐答案

下面是我最终结束了使用的解决方案:

Here is the solution I eventually ended up using:

ICriteria c = session.CreateCriteria(typeof(Tribble));
c.SetProjection(Projections.ProjectionList().Add(Projections.Property("Name")));
IList<string> names = c.List<string>();



我接到的这个古老的计算器问题

这篇关于从实体获取单个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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