NHibernate.QueryException ActiveRecord

时间:2010-11-28 01:21:31

标签: c# nhibernate castle-activerecord

   [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'

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

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

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