Having a problem getting eager fetching of an association property to
work smoothly,
I have an entity called PatientIntensity with an association property
PatientStay.
A simple attempt to query in code:
var q = es.Session.CreateSQLQuery(@"
select {pi.*}, {ps.*}
from patientintensity pi
join patientstay ps on ps.patientstayid = pi.patientstayid")
.AddEntity("pi", typeof(PatientIntensity))
.AddJoin("ps", "pi.PatientStay");
Now, I would think that I can do
var list = q.List<PatientIntensity>();
but when I do that, I get an error:
System.ArgumentException : The value "System.Object[]" is not of type
"PatientIntensity" and cannot be used in this generic collection.
Parameter name: value
at System.ThrowHelper.ThrowWrongValueTypeArgumentException(Object
value, Type targetType)
at System.Collections.Generic.List`1.VerifyValueType(Object value)
at System.Collections.Generic.List`1.System.Collections.IList.Add
(Object item)
at NHibernate.Util.ArrayHelper.AddAll(IList to, IList from)
at NHibernate.Impl.SessionImpl.ListCustomQuery(ICustomQuery
customQuery, QueryParameters queryParameters, IList results)
at NHibernate.Impl.SessionImpl.List(NativeSQLQuerySpecification spec,
QueryParameters queryParameters, IList results)
at NHibernate.Impl.SessionImpl.List[T](NativeSQLQuerySpecification
spec, QueryParameters queryParameters)
at NHibernate.Impl.SqlQueryImpl.List[T]()
However, I can get it to work, including join fetching the
association, by doing the following;
var l = q.List<object[]>();
var l2 = l.Select(x => x[0] as PatientIntensity).ToList();
Basically, take the first object in the array for each row and return
it as a list.
Is this what we would expect, or am I missing some way to get NH to do
this for me? I note that all of the documentation examples I find seem
to be using the non-generic List() method rather than the generic
List<T> method, so maybe this is just how things are?
Thanks
roger
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---