本文介绍了从实体获取单个列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您如何从一个查询,而不是一个整体对象获取单个列回来?
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>();
我接到的。
这篇关于从实体获取单个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!