how do I save to a database record with the primary key value = 0?
I have a client's database that I am accessing with nHibernate. In one table, they have a primary key which auto-increments starting at 0. I cannot have the client's database changed to a 1 based auto-increment.
When I attempt to save a child record in a table with a foreign key back to this table I receive the following error: "not-null property references a null or transient value". The problem is only found when I save the child of the record that has the 0 primary key value, al开发者_运维百科l other records work fine.
This is the generator for the parent table
and the foreign key relationship map:
Question: how do I save to a database record with the primary key value = 0?
i cant see your mappings but i would try
public ParentMap()
{
Id(x => x.Id).GeneratedBy.Increment().UnsavedValue(-1);
}
and
public Parent()
{
Id = -1;
}
精彩评论