For easy installation parent -> child (CK, CK) like this. I'm having trouble adding a new child and getting the parent link. Therefore, I would add an object in this way.
var parent = new Parent{
Children = new List<Child>{
new Child{
Other = otherReference
}
}
};
Or even adding it using a method Add()...
parent.Children.Add (new Child {Other = other});
Link to Parentfails. It just ends up as a null property. I get the following exception.
{"Cannot insert NULL into column" ParentId ", table" mssql_test.Children ", column does not allow zeros. INSERT does not work. \ R \ nApplication is complete." }
I can do it ...
new Child {
Parent = parentReference,
Other = otherReference
}
. , . , , . - ? .
class Parent {
int Id { get; set; }
IList<Child> Children { get; set; }
}
class Other {
int Id { get; set; }
}
class Child {
Parent Parent { get; set; }
Other Other { get; set; }
}
Mapping
ChildMap() {
CompositeId()
.KeyReference(x => x.Parent, "ParentId")
.KeyReference(x => x.Other, "OtherId");
}
ParentMap(){
HasManyToMany(x => x.Children)
.AsBag()
.ChildKeyColumns.Add(new[] { "ParentId", "OtherId" })
.Inverse()
.Cascade.All())
.Table("[Test]");
}