代码之家  ›  专栏  ›  技术社区  ›  Roman

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

  •  0
  • Roman  · 技术社区  · 14 年前

    此查询工作正常:

    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 对象使用 已安排通知 像这样过滤,它就工作了

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

    有人能说为什么会这样吗?

    1 回复  |  直到 14 年前
        1
  •  1
  •   Mauricio Scheffer    14 年前

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

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

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