开发者

NHibernate.QueryException ActiveRecord

开发者 https://www.devze.com 2023-01-27 01:27 出处:网络
[ActiveRecord] public class Category { private int _id; private string _name; private Category _category; [PrimaryKey(PrimaryKeyType.HiLo, \"id\", Params = \"max_lo=9\")]
   [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 QueryExce开发者_Go百科ption

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

Any idea?


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)); 
0

精彩评论

暂无评论...
验证码 换一张
取 消