此查询正常工作:
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));
有人可以说为什么会这样吗?
答案 0 :(得分:1)
使用CreateAlias()
表示已加入的实体,例如:
DetachedCriteria
.For(typeof(NotificationRecord), "nr")
.CreateAlias("nr.Submission", "s")
.Add(Expression.Eq("s.IsScheduledForNotification", true));
nr.Submission.Id
查询不需要这个,因为那里没有连接。