Castle ActiveRecord无法在某些查询中检测到DAO字段

时间:2010-05-13 17:24:30

标签: asp.net-mvc nhibernate castle-activerecord

此查询正常工作:

DetachedCriteria filter = DetachedCriteria
                          .For(typeof(NotificationRecord), "nr")
                          .Add(Expression.Eq("nr.Submission.Id", 5));

return ActiveRecordMediator<NotificationRecord>.FindAll(filter);

此查询失败,并显示异常消息:could not resolve property: Submission.IsScheduledForNotification of: NotificationRecord

DetachedCriteria filter = DetachedCriteria
                          .For(typeof(NotificationRecord), "nr")
                          .Add(Expression.Eq("nr.Submission.IsScheduledForNotification", true));

return ActiveRecordMediator<NotificationRecord>.FindAll(filter);

为确保ActiveRecord能够识别IsScheduledForNotification,我使用Submission作为过滤器对实际的IsScheduledForNotification对象进行简单查询,并且可以正常使用

ActiveRecordMediator<Submission>.Exists(Expression.Eq("IsScheduledForNotification", true));

有人可以说为什么会这样吗?

1 个答案:

答案 0 :(得分:1)

使用CreateAlias()表示已加入的实体,例如:

DetachedCriteria
.For(typeof(NotificationRecord), "nr")
.CreateAlias("nr.Submission", "s")
.Add(Expression.Eq("s.IsScheduledForNotification", true));

nr.Submission.Id查询不需要这个,因为那里没有连接。