2011-10-21 50 views
0

我必须以检索一些数据,并基于该标准 行数波纹管是我的代码片段错误功能NHibernate COUNT(*)函数

criteria.SetProjection(Projections.ProjectionList().Add(Projections.Property("LastUpdatedUserName"),"OperatorName") 
      .Add(Projections.Property("Created"),"enrollmentdate") 
      .Add(Projections.Count("NIK"), "enrollmentcount") 
      .Add(Projections.GroupProperty("LastUpdatedUserName")) 
      .Add(Projections.GroupProperty("Created"))) 
      .SetResultTransformer(NHibernate.Transform.Transformers.AliasToEntityMap); 
     var result = criteria.List<Demographic>() 

,当运行

这个片段中产生异常

这里去除了

ex.message = Unable to perform find[SQL: SQL not available] ex.innerexception = {"The value \"System.Collections.Hashtable\" is not of type \"Indo.Id.Data.Infrastructure.Entities.Demographic\" and cannot be used in this generic collection.\r\nParameter name: value"}

和堆栈跟踪是

at System.ThrowHelper.ThrowWrongValueTypeArgumentException(Object value, Type targetType) at System.Collections.Generic.List 1.VerifyValueType(对象的值) 在System.Collections.Generic.List 1.System.Collections.IList.Add(Object item) at NHibernate.Util.ArrayHelper.AddAll(IList to, IList from) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Util\ArrayHelper.cs:line 233 at NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 1948

改造人口统计将致力于最大程度,但在这里演示图形的类型转换我有大约40列,我宣布一个新的类持有类似

结果我现在可以改造这个新的类象

NHibernate.Transform.Transformers.AliasToBean(typeof(operatorenrollment))

这里任何帮助是非常appriciable

感谢进阶

回答

0

错误是相当清楚的。

您正在使用Transformers.AliasToEntityMap,它将您的投影转换为IDictionary,并试图找回Demographic的列表。

改为使用Transformers.AliasToBean<Demographic>()

+0

嗨,现在问题变成了新的,当我试图像你指导的方式转换为人口obj 无法找到类'Indo.Id.Data.Infrastructure.Entities.Demographic'属性'enrollmentcount'的setter ' 我知道财产不可用在人口统计现在我可以将结果投到另一个对象,我只有这三个领域,但不是其余的领域像 NHibernate.Transform.Transformers.AliasToBean(typeof(OperatorEn)) 其中操作员类定义如下 公共课程作业 –

+0

{ public string OperatorName {get;组; } public DateTime enrollmentdate {get;组; } public int enrollmentcount {get;组; } } –