NHibernate:使用别名BeanResultTransformer时出现InvalidCastException
以下代码(在NHibernate2.1.2中)有什么问题NHibernate:使用别名BeanResultTransformer时出现InvalidCastException,nhibernate,Nhibernate,以下代码(在NHibernate2.1.2中)有什么问题 public IEnumerable List() { 返回会话.CreateCriteria(“e”) .SetCacheable(真) .SetProjection(Projections.ProjectionList()项目) .添加(投影.属性(“e.Id”),“Id”) .Add(Projections.Property(“e.CurrentOffice.Id”),“CurrentOfficeId”) .SetResultTra
public IEnumerable List()
{
返回会话.CreateCriteria(“e”)
.SetCacheable(真)
.SetProjection(Projections.ProjectionList()项目)
.添加(投影.属性(“e.Id”),“Id”)
.Add(Projections.Property(“e.CurrentOffice.Id”),“CurrentOfficeId”)
.SetResultTransformer(新别名为BeanResultTransformer(typeof(EmployeeSummary)))
.List();
}
公共类雇员摘要
{
公共Guid Id{get;private set;}
公共Guid CurrentOfficeId{get;private set;}
}
我收到以下错误:
NHibernate.Exceptions.GenericADOException:无法执行查找[SQL:SQL不可用]
---->System.InvalidCastException:无法将类型为“EmployeeSummary”的对象强制转换为类型为“System.object[]”。解决了此问题-问题可设置为可缓存。您不能将其与别名BeanResultTransformer一起使用 这似乎是NHibernate的一个bug/bug特性。不确定它是否在以后的版本中得到解决
public IEnumerable<EmployeeSummary> List()
{
return Session.CreateCriteria<Employee>("e")
.SetCacheable(true)
.SetProjection(Projections.ProjectionList()
.Add(Projections.Property("e.Id"), "Id")
.Add(Projections.Property("e.CurrentOffice.Id"), "CurrentOfficeId")
.SetResultTransformer(new AliasToBeanResultTransformer(typeof(EmployeeSummary)))
.List<EmployeeSummary>();
}
public class EmployeeSummary
{
public Guid Id { get; private set; }
public Guid CurrentOfficeId { get; private set; }
}