I have a domain where the children don't reference the parents. I am using nh 3+ and fluent nh with automapping. An example would be like this.
public class Parent
{
public Guid Id {get;set;}
public string Name {get;set;}
public List<Child> Children {get;set;}
}
public class Child
{
public Guid Id {get;set;}
public Guid ParentId {get;set;}
public string Name {get;set;}
public string SomethingElse {get;set;}
}
When I add a child to my parent collection and save I get an error (sql) saying can't insert the value null into ParentId
. Column doesn't allow nulls
the HasMany
mapping would be like this
mapping.HasMany(x => x.Children).Cascade.AllDeleteOrphan();
There must be someway to do this. I know about inverse but you would put inverse on the reference map of the child to the parent and as my child doesn't have a reference to the parent that wont work.