I have a class that has a Primary Key as well as 2 foreign keys. Foreign combinations must be unique. I do not see a way to do this (at least since SetA开发者_运维问答ttribute was deprecated).
James touched on this with SetAttribute: How to create a Multi-Column Index or Unique Constraint with NHibernate
This might be useful to someone else, FNH mapping of unique constraint is accomplished like this:
mapping.References<FirstClass>(x => x.FirstClass).UniqueKey("unique123");
mapping.References<SecondClass>(x => x.SecondClass).UniqueKey("unique123");
Further, it is explained that this only builds the constraint in the db, but that the developer is responsible to intercept duplicate insert attempts, otherwise an SqlException
will be thrown saying an UNIQUE KEY constraint was violated.
from the FNH group
精彩评论