I am new to NHibernate and it is difficult for me to match the following relationships in this class.
public class Category : IAuditable { public virtual int Id { get; set; } public virtual string Name{ get; set; } public virtual Category ParentCategory { get; set; } public virtual IList<Category> SubCategories { get; set; } public Category() { this.Name = string.Empty; this.SubCategories = new List<Category>(); } }
Class maps (although this is almost a hunch)
public class CategoryMap : ClassMap<Category> { public CategoryMap() { Id(x => x.Id); Map(x => x.Name); References(x => x.ParentCategory) .Nullable() .Not.LazyLoad(); HasMany(x => x.SubCategories) .Cascade.All(); } }
Each category can have a parent category, some categories have many subcategories, etc. etc. I can correctly save the category to save (the correct subcategories and the parent category fk exist in the database), but when loaded, it returns itself as the parent category.
I use Fluent to map classes, but if someone can point me in the right direction just for simple NHibernate, which will also work.
source share