I try to create a tree in single table using Fluent Nhibernate. Table must look like this:
Model class:
public class Category
{
public virtual int CategoryId { get; set; }
public virtual string CategoryName { get; set; }
public virtual Category ParentCategory { get; set; }
public virtual IList<Category> ChildCategory { get; } = new List<Category>();
}
Mapping class:
public class CategoryMap : ClassMap<Category>
{
public CategoryMap()
{
Id(x => x.CategoryId).GeneratedBy.Increment();
Map(x => x.CategoryName).Not.Nullable();
References(x => x.ParentCategory).Column("ParentCategoryId").Access.CamelCaseField();
HasMany(x => x.ChildCategory)
.Cascade.AllDeleteOrphan()
.AsSet()
.KeyColumn("CategoryId")
.Access.CamelCaseField();
}
}
ORM return following exception:
NHibernate.PropertyNotFoundException: Could not find property nor field 'childCategory' in class 'MyProj.Models.Category'
I'm only studying NH. What I'm doing wrong?