2010-05-13 53 views
0

此查询工作正常DAO领域:城堡的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,我做使用IsScheduledForNotification作为过滤器的实际Submission对象的简单查询就像这样,它的工作原理

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

有人可以说为什么会发生这种情况吗?

回答

1

使用CreateAlias()指示加盟实体,例如:

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

因为没有参加在那里,你不需要这个了​​查询。