2010-05-13 52 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)); 

因爲沒有參加在那裏,你不需要這個了​​查詢。