Hibernate Criteria可以只查询出表中几个字段

利用投影可以解决此问题:

1 Criteria   criteria=session.createCriteria(User.class); 
2 ProjectionList proList = Projections.projectionList();//设置投影集合
3 proList.add(Projections.groupProperty( "userName "));
4 proList.add(Projections.groupProperty( "password "));
5 criteria.setProjection(proList);
6 criteria.SetProjection(proList).SetResultTransformer(new NHibernate.Transform.AliasToBeanResultTransformer(typeof(AchievementSummary))); // 要转换的类型

 

posted @ 2011-10-31 17:23  kntao  阅读(1344)  评论(0编辑  收藏  举报