I have two tables in a legacy database...
tblParentTable (int id, string specialIdentifier, ...)
tblChildTable (int id, string specialIdentifier, ...)
As you can see, an auto-incrementing int id has been added, but the child table is joined using the old string primary key (in fact, specialIdentifier is the primary key of tblParentTable, and the primary and foreign key on tblChildTable).
So I have created domain objects and Fluent NHibernate maps, but because of this odd schema, NHibernate thinks that it needs to save the tblChildTable record first, before it saves tblParentTable - this results in a foreign key constraint error.
How can I hint to NHibernate that tblParentTable is the parent and needs to be saved first?
Here is are the mappings...
public ParentMap()
{
Table("tblParentTable");
Id(x => x.Id).Column("id");
Map(x => x.SpecialIdentifier);
References(x => x.Child).Column("specialIdentifier");
}
public ChildMap()
{
Table("tblChildTable");
Id(x => x.Id).Column("id");
Map(x => x.SpecialIdentifier);
References(x => x.Child).Column("specialIdentifier");
}
Please feel free to ask for more information if you think I am missing something important.
Thanks