Just to be clear - this question is not about Fluent NHibernate.
I have a Parent
and Child
classes, with a one-to-many relationship between them.
The code is shortened for readability.
public class Child
{
int Id;
string Name;
}
public class Parent
{
int Id;
string Name;
Iesi.Collections.Generic.ISet<Child> Children;
}
public ChildMapping()
{
Table("Children");
Id(p => p.Id, m => {
m.Column("Id");
m.Generator(Generators.Identity);
});
Property(p => p.Name, m => {
m.Column("Name");
m.NotNullable(true);
});
}
public ParentMapping()
{
Table("Parents");
Id(p => p.Id, m => {
m.Column("Id");
m.Generator(Generators.Identity);
});
Property(p => p.Name, m => {
m.Column("Name");
m.NotNullable(true);
});
Set(p => p.Children, m => {
m.Cascade(Cascade.All | Cascade.DeleteOrphans);
m.Key(k => {
k.Column("ParentId");
k.NotNullable(true);
});
}, a => a.OneToMany());
}
The Child
class needs a Parent
property on it.
The Parent
needs to control the relationship (I can't set the Inverse
to true
on the Parent
's end).
How should the Parent
and Child
mapping look like?