Hi all,

I'm trying to use projections to only return a few properties of my
domain object from the db.  The code I'm using looks like:

var tenants = Session.QueryOver<Tenant>()
                                .Select(x => x.Id, x => x.FirstName, x => 
x.LastName)
                                .List<Tenant>();

The generated sql is spot on, but unfortunately, things are not
working when NHibernate tries to map the result to an
IEnumerable<Tenant>.  It throws an exception similar to:

The value "System.Object[]" is not of type "MyDomain.Tenant" and
cannot be used in this generic collection.
Parameter name: value
System.ThrowHelper.ThrowWrongValueTypeArgumentException(Object value,
Type targetType) +122
 
System.Collections.Generic.List`1.System.Collections.IList.Add(Object
item) +150
   NHibernate.Util.ArrayHelper.AddAll(IList to, IList from) in d:
\Builds\NHibernate\nhibernate\src\NHibernate\Util\ArrayHelper.cs:201
   NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList
results) in d:\Builds\NHibernate\nhibernate\src\NHibernate\Impl
\SessionImpl.cs:1994

I've tried to set a transformer
(using 
.UnderlyingCriteria.SetResultTransformer(Transformers.AliasToBean(typeof(Tenant)))),
but it did not seem to help.  This is using NHibernate 3.0.0.1001

Any ideas what is going on and how to fix it?

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to