0

Consider the following class hierarchy:

public abstract class Animal {}

public class Dog : Animal
{
    public int DogTagNumber { get; set; }
}

public class Cat : Animal
{
    public int CatTagNumber { get; set; }
}

Note: DogTagNumber and CatTagNumber is purposely placed in the subclasses instead of as TagNumber in Animal class to demonstrate property explicit to each subclass.

The question: Using Fluent NHibernate, is it possible to map unique constrain on class discriminator together with subclasses's explicit properties, like below:

Unique("DOG", DogTagNumber) and also Unique("CAT", CatTagNumber)

The purpose is to ensure the uniqueness of each Dog and Cat with regard to the discriminator in the table on database level.

Thanks in advance.

  • Solved, see [SO Q1](http://stackoverflow.com/questions/4041365/multiple-unique-keys-in-nhibernate), [SO Q2](http://stackoverflow.com/questions/834565/how-to-create-a-multi-column-index-or-unique-constraint-with-nhibernate) – 1156140 Jan 19 '12 at 06:42

1 Answers1

0

try this one:

   Map(x => x.Something).UniqueKey("KeyName");
   DiscriminateSubClassesOnColumn("discr_column").UniqueKey("KeyName");
mynkow
  • 4,408
  • 4
  • 38
  • 65
  • I have actually came across that before and that produces Unique("discr_column", DogTagNumber, CatTagNumber) instead of the desired Unique("discr_column", DogTagNumber) and Unique("discr_column", CatTagNumber). – 1156140 Jan 19 '12 at 00:59