i have to retrive some data and count of the rows based on the criteria
the bellow is my code snippet
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>()
and this snippet resulting in exception while running
here goes the exception
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"}
and the stack trace is
at System.ThrowHelper.ThrowWrongValueTypeArgumentException(Object value, Type targetType)1.VerifyValueType(Object value)
at System.Collections.Generic.List
at System.Collections.Generic.List1.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
type casting of the transformation to demographic will work to max extent but here in demo graphics i have approx 40 columns and i have declared a new class for holding the result like
public class operatorenrollment
{
public string OperatorName { get; set; }
public DateTime enrollmentdate { get; set; }
public int enrollmentcount { get; set; }
}
can i now transform this to new class like
NHibernate.Transform.Transformers.AliasToBean(typeof(operatorenrollment))
any help here is very much appriciable
thanks in adv
The error is pretty clear.
You are using
Transformers.AliasToEntityMap, which transforms your projection into anIDictionary, and trying to get back a list ofDemographic.Use
Transformers.AliasToBean<Demographic>()instead.