Nhibernate hasmany not updating
For example, we have a Site Product that represents a Product on a Site.When we first designed the database, we setup the relationship entites with a single field surrogate key: A unique, automatically generated ID that only exists to serve the database.We wanted to eliminate those surrogate keys and use the combination of Site Id and Product Id as a composite key instead.We had similar circumstances in a couple of other relationship tables that we also wanted to improve.We ended up with this: After reworking our entities and Fluent NHibernate maps to mirror our new structure, we ran into the following rather cryptic exception when running our unit test suite against SQLLite: Notice that Product Id is one component of the composite key for Media In Pool and one component of the composite key for Site Product.As it turns out, NHibernate simply cannot deal with one field being mapped twice.
Here’s a portion of our original database structure: The changes we wanted to make fell into two categories.
The problem was it had no meaning to the business so our screens tended to know the Site Id and the Product Id but not the Site Product Id.
This forced us to constantly join or lookup the Site Product table to get the Site Product Id so we could get to the data we needed to perform work.
If we make the reference to Media In Pool read only, the Media Id does not get set and the insert fails; If we make the Site Product reference read only, the insert fails with a null Site Id.
A couple members of the team looked for solutions all afternoon.