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

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

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

你可能感兴趣的:(Hibernate)