Hi all. I have a table http://img36.imageshack.us/i/beztytuuszxq.png/ and mapping:
public class CategoryMap : ClassMap<Category>
{
public CategoryMap()
{
Table(FieldNames.Category.Table);
Id(x => x.ID);
Map(x => x.Name).Not.Nullable();
Map(x => x.ShowInMenuBar).Not.Nullable();
References(x => x.Parent).Column(FieldNames.Category.ID).Nullable();
HasMany(x => x.Articles).Cascade.All().Inverse().Table(FieldNames.Article.Table);
}
}
The entity looks that:
public class Category : EntityBase
{
public virtual int ID { set; get; }
public virtual string Name { set; get; }
public virtual Category Parent { set; get; }
public virtual bool ShowInMenuBar { set; get; }
public virtual IList<Article> Articles { set; get; }
}
When I want to save an Category object to db, when Parent property is set to null, I have exception:
not-null property references a null or transient value CMS.Domain.Entities.Article.Category
I cannot change the
public virtual Category Parent { set; get; }
line to
public virtual Category? Parent { set; get; }
or
public virtual Nullable<Category> Parent { set; get; }
because I have an error during compile:
CMS.Domain.Entities.Category' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable<T>'
I don't know what to change to have possibility to save Category objects without parents.