lexeme
lexeme

Reputation: 2973

NHibernate. Records uniqueness

I have a class

abstract class Entity<T> where T : Entity<T>
{
    public virtual Guid ID { get; private set; }
}

all my entities are inherited from it. In the case of employee entity that's impossible to have two employees with same passport-sn, and other identity-specific documents.

Howcome I disallow to put two employees with different surrogate keys and the same passport number to a database?

Is there any constraint in mapping?

Thanks!

Upvotes: 0

Views: 44

Answers (1)

Massimiliano Peluso
Massimiliano Peluso

Reputation: 26737

you can add the Unique constrain for passport

if you are using Fluent:

mapping.Id( employee => employee.Id);
mapping.Map(employee  => employee.passport ).Unique(); 

In your domain if all the entities inherits from Entity all of them will use a surrogate keys so you have to handle any other constrains

Upvotes: 1

Related Questions