SteveBering
SteveBering

Reputation: 957

NHibernate many-to-one mappings updating unchanged table

I have a situation where I have two entities that share a primary key (Transaction and TransactionDetail). I have them mapped using many-to-one relationship from Transaction to TransactionDetail and from TransactionDetail to Transaction. Transaction detail holds one record for each transaction.

However, when I create a new transaction detail object and add it to the transaction, NHibernate tries to update the Transaction table with a query like 'update transaction set id = ? where id = ?' with the same value for each parameter.

Since the mapping is on the primary key column, I don't want the transaction to be updated. In fact, since the primary key is an identity column, I get an error when it tries to update the value. How can I prevent NHibernate from updating the Transaction table when a new TransactionDetail record is created?

Upvotes: 1

Views: 1192

Answers (1)

yfeldblum
yfeldblum

Reputation: 65435

You may want to look into the one-to-one or join-table types of mappings. many-to-one means something specific, and it looks like your case might better fit the profile of one of the other two types of mappings.

Upvotes: 2

Related Questions