开发者

Nhibernate 3.0: problems with Future<> and Restrictions on a join table

I can't figure out what the problem with nHibernate. My domain is quite simple. Since most of my data is show in a paginated grid (jqGrid) I need to use Future<> to get the total number of rows. If I run this chunk of code here it works properly:

ICriteria FiltersCriteriaCount = session.CreateCriteria<Domain.Reminder>();
ICriteria FiltersCriteria = session.CreateCriteria<Domain.Reminder>();

var TotalRecords = FiltersCriteriaCount
    .SetProjection(Projections.RowCount())
    .FutureValue<Int开发者_StackOverflow32>();

var sResult = FiltersCriteria
    .CreateAlias("Company", "Company")
    .CreateAlias("PlanType", "PlanType")
    .CreateAlias("OperationsManager", "OperationsManager")
    .CreateAlias("Schedules", "Schedules", NHibernate.SqlCommand.JoinType.LeftOuterJoin)
    .SetFirstResult(0)
    .SetMaxResults(100)
    .Future<Domain.Reminder>()
    .ToList<Domain.Reminder>();

but if I add a restriction I get an exception could not resolve property: Schedules.Notes of: BpReminders.Domain.Reminder:

ICriteria FiltersCriteriaCount = session.CreateCriteria<Domain.Reminder>();
ICriteria FiltersCriteria = session.CreateCriteria<Domain.Reminder>();

FiltersCriteriaCount.Add(Restrictions.Eq("Schedules.Notes", ""));
FiltersCriteria.Add(Restrictions.Eq("Schedules.Notes", ""));

var TotalRecords = FiltersCriteriaCount
    .SetProjection(Projections.RowCount())
    .FutureValue<Int32>();

var sResult = FiltersCriteria
    .CreateAlias("Company", "Company")
    .CreateAlias("PlanType", "PlanType")
    .CreateAlias("OperationsManager", "OperationsManager")
    .CreateAlias("Schedules", "Schedules", NHibernate.SqlCommand.JoinType.LeftOuterJoin)
    .SetFirstResult(0)
    .SetMaxResults(100)
    .Future<Domain.Reminder>()
    .ToList<Domain.Reminder>();

If I get rid of Future<> and trasform my code like this everything works fine:

ICriteria FiltersCriteria = session.CreateCriteria<Domain.Reminder>();
FiltersCriteria.Add(Restrictions.Eq("Schedules.Notes", ""));

var sResult = FiltersCriteria
    .CreateAlias("Company", "Company")
    .CreateAlias("PlanType", "PlanType")
    .CreateAlias("OperationsManager", "OperationsManager")
    .CreateAlias("Schedules", "Schedules", NHibernate.SqlCommand.JoinType.LeftOuterJoin)
    .SetFirstResult(0)
    .SetMaxResults(100)
    .List<Domain.Reminder>();

I can't find the reason for that. Any help would be really really appreciated.


I'd say, try this:

var TotalRecords = FiltersCriteriaCount
    .CreateAlias("Schedules", "Schedules", NHibernate.SqlCommand.JoinType.LeftOuterJoin)
    .SetProjection(Projections.RowCount())
    .FutureValue<Int32>();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜