开发者

NHibernate: InvalidCastException when using AliasToBeanResultTransformer

What's the matter with the following code (in NHibernate 2.1.2)?

        public IEnumerable<EmployeeSummary> List()
    {
        return Session.CreateCriteria<Employee>("e")
            .SetCacheable(true)
            .SetProjection(Projections.ProjectionList()
                            .Add(Projections.Property("e.Id"), "Id")
             开发者_JS百科               .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; }
    }

I receive the following error: NHibernate.Exceptions.GenericADOException : Unable to perform find[SQL: SQL not available] ----> System.InvalidCastException : Unable to cast object of type 'EmployeeSummary' to type 'System.Object[]'.


Worked this one out - the problem is SetCacheable. You can't use it with AliasToBeanResultTransformer.

It appears to be a bug/bug-feature of NHibernate. Not sure if its resolved in later versions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜