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

按id查找nhibernate标准

  •  1
  • user315648  · 技术社区  · 14 年前

    我有两个实体:

    public class Authority : Entity
    {
        [NotNull, NotEmpty]
        public virtual string Name { get; set; }
    
        [NotNull]
        public virtual AuthorityType Type { get; set; }
    
    }
    
    public class AuthorityType : Entity
    {
        [NotNull, NotEmpty]
        public virtual string Name { get; set; }
    
        public virtual string Description { get; set; }
    }
    

    现在我希望按类型从存储库中查找所有权限。我试着这样做:

        public IList<Authority> GetAuthoritiesByType(int id)
        {
            ICriteria criteria = Session.CreateCriteria(typeof (Authority));
            criteria.Add(Restrictions.Eq("Type.Id", id));
            IList<Authority> authorities = criteria.List<Authority>();
            return authorities;            
        }
    

    但是,我得到一个错误,即sql有问题(“无法执行查询”)。InnerException如下:{“列名'typefk'无效。\r\n列名'typefk'无效。”}

    有什么建议吗?还有别的办法吗?

    最美好的祝福, 安得烈

    1 回复  |  直到 14 年前
        1
  •  3
  •   Chris    14 年前

    看起来您的authority实体的映射文件正在将 Type 属性添加到名为 TypeFk 在授权实体映射到的任何表中。出于某种原因,该列不在那里。

    也可以查看映射文件。