NHibernate.QueryException ActiveRecord

发布于 2024-10-04 23:25:07 字数 1060 浏览 0 评论 0原文

   [ActiveRecord]   
    public class Category
   {
    private int _id;
    private string _name;
    private Category _category;

    [PrimaryKey(PrimaryKeyType.HiLo, "id", Params = "max_lo=9")]
    public long Id
    {
        get { return _id; }
        protected internal set { _id = value; }
    }
    [Property]
    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }
    [BelongsTo("ParentCategoryId")]
    public Category ParentCategory
    {
        get { return _category;}
        set { _category = value; }
    }       
}

表在数据库中正确生成,并且可以毫无问题地插入数据

但是当我运行时

        var criteria = DetachedCriteria.For<Category>
            .Add(Restrictions.Eq("ParentCategory.ParentCategoryId", testCategory.id));           
        Assert.That(m_repository.FindAll(criteria).Length, Is.EqualTo(1));

我收到 QueryException

`NHibernate.QueryException:无法 解析属性: ParentCategory.ParentCategoryId'

有什么想法吗?

   [ActiveRecord]   
    public class Category
   {
    private int _id;
    private string _name;
    private Category _category;

    [PrimaryKey(PrimaryKeyType.HiLo, "id", Params = "max_lo=9")]
    public long Id
    {
        get { return _id; }
        protected internal set { _id = value; }
    }
    [Property]
    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }
    [BelongsTo("ParentCategoryId")]
    public Category ParentCategory
    {
        get { return _category;}
        set { _category = value; }
    }       
}

Table is correctly generated in the database and data can be insterted without any problems

But when I'm running

        var criteria = DetachedCriteria.For<Category>
            .Add(Restrictions.Eq("ParentCategory.ParentCategoryId", testCategory.id));           
        Assert.That(m_repository.FindAll(criteria).Length, Is.EqualTo(1));

I'm reciving QueryException

`NHibernate.QueryException : could not
resolve property:
ParentCategory.ParentCategoryId'

Any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

女皇必胜 2024-10-11 23:25:07

您正在获取类别的 ParentCategory 属性,该属性本身就是一个类别。您的 DetachedCriteria 应该是:

   var criteria = DetachedCriteria.For<Category>()
                                  .Add(Restrictions.Eq("ParentCategory.Id",
                                                       testCategory.id)); 

You are fetching the ParentCategory property of a Category, which is itself a Category. Your DetachedCriteria should be:

   var criteria = DetachedCriteria.For<Category>()
                                  .Add(Restrictions.Eq("ParentCategory.Id",
                                                       testCategory.id)); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文