I have very simple unidirectional mappings. see below:
public ContactMap() { Id(x => x.Id).GeneratedBy.Assigned(); Map(x => x.Name); References(x => x.Device); HasMany(x => x.Numbers) .Not.Inverse() .Not.KeyNullable() .Cascade.AllDeleteOrphan() .Not.LazyLoad() .Fetch.Subselect(); Table("Contacts"); } public PhoneNumberMap() { Id(x => x.Id).GeneratedBy.Native(); Map(x => x.Number); Table("ContactNumbers"); }
According to this message, after nhibernate 3 and above, the installation key as invalid should fix the problem with updating the insert (the problem is when NHibernate issues an insert with a foreign key set to null and then updating to update the foreign key to fix the value), but for this is not me. When I set the key as invalid, NHibernate issues the correct insert statement
INSERT INTO ContactNumbers (Number, ContactId) VALUES ('(212) 121-212' , 10 );
As you can see, it inserts the ContactId field, but after that it still issues the update instruction
UPDATE ContactNumbers SET ContactId = 10 WHERE Id = 34
So, to clarify the problem. NHibernate inserts a contact string with the foreign key assigned correctly, and after that it issues an update instruction to update the foreign key (ContactId), which is redundant.
How can I get rid of this redundant update statement? Thanks.
By the way, I am using the latest version of NHibernate and Fluent NHibernate. SQLite Database
mapping nhibernate fluent-nhibernate
Davita
source share