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; }
    }       
}

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?

1 Answer 1

1

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)); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.