Reputation: 839
How do I get NHibernate to save or update using column other than the <id>
? I've implemented an identity key column in a table but this is not what makes a row unique. I know that "composite-id" exists but I heard that that should only be used on legacy databases, where there is not much freedom to change it. Is there any other way to implement unique keys without using an artifical key? Should I make my own key based on a hash of the columns that make a row unique? If I do that, won't NHibernate complain when it tries to insert an object with a manually assigned key?
Upvotes: 1
Views: 808
Reputation: 14097
Uniqueness of db rows is completely different then identifying which row you want to update.
Why not use unique constraints to ensure your records are unique and follow the standard practice of using Ids.
Upvotes: 1
Reputation: 99720
NHibernate has lots of options for primary keys. You can use any of the available built-in generators, or an application-assigned PK (the "assigned" generator option).
If none of these options suit you, you can always implement your own IIdentifierGenerator
, but think really hard before doing so: the built-in generators and PK handling encapsulate years of RDBMS experience from many experts.
Composite PKs are generally not worth the complexity they add.
Upvotes: 4