开发者

How can one change the primary key using NHibernate

开发者 https://www.devze.com 2022-12-29 00:47 出处:网络
I want to change the primary key of an entity in database, s开发者_Python百科o that all the relevant foreign key constraints are updated as well./We are using NHibenate as our ORM.

I want to change the primary key of an entity in database, s开发者_Python百科o 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.


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...


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消