4

I try to create unique index with fluent nhibernate. But when i use the following classes tables are created like :

Person Table:
Id
Name

PersonStatistic Table:
Id
Date
Count
Person_Id

Because of this structure when i create the unique key, column order look like "Date - Person_Id". But i want to column order in key like "Person_Id - Date"

Entity and map classes like below.

Entity classes :

public class Person()
{
    public virtual Guid Id { get; set; }
    public virtual string Name { get; set; }
}

public class PersonStatistic()
{
    public virtual Guid Id { get; set; }
    public virtual DateTime Date { get; set; }
    public virtual long? Count { get; set; }
    public virtual Person Person { get; set; }
}

Map classes :

public PersonMap()
{
    Id(x => x.Id).GeneratedBy.GuidComb();
    Map(x => x.Name).Not.Nullable().Length(50);
}

public PersonStatisticMap()
{        
    Id(x => x.Id).GeneratedBy.GuidComb();
    Map(x => x.Date).Not.Nullable().UniqueKey("UK_Person_Date");
    Map(x => x.Count).Nullable();

    References(x => x.Person)
        .Not.Nullable()
        .UniqueKey("UK_Person_Date");
}

Something is wrong in my classes or mapping or another trick to set column order in key?

Murat Aras
  • 403
  • 2
  • 10

1 Answers1

0

Try putting the References call before the Map one.

Diego Mijelshon
  • 52,548
  • 16
  • 116
  • 154