tags:

views:

25

answers:

2

Dear ladies and sirs.

I want to change the primary key of an entity in database, so that all the relevant foreign key constraints are updated as well./We are using NHibenate as our ORM.

Is it possible to do it?

Thanks.

P.S.

I know the practice of changing the primary key is highly discouraged. My problem is that my primary key is backed by a natural Id of the entity, which may sometimes change. We could, theoretically, utilize a unique primary key, unrelated to the natural key of the entity, but this complicates things too much in other places, so this is not an option.

A: 

I'm not clear on your question.... nHibernate is just a mapping of your database. It seems that to do what you are suggesting you just need to change your database to whatever you need it to be, redo your mapping files, then modify any queries you have to match the new schema...

Max Schilling
A: 

No, it is not possible. NHibernate will complain if you try to do it.

The only way to do it "from" NHibernate is using CreateSQLQuery.

Diego Mijelshon