NHibernate.QueryException 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'
有什么想法吗?
[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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在获取类别的 ParentCategory 属性,该属性本身就是一个类别。您的 DetachedCriteria 应该是:
You are fetching the ParentCategory property of a Category, which is itself a Category. Your DetachedCriteria should be: