Unique column order in free nhibernate

I am trying to create a unique index with smooth nhibernate. But when I use the following table classes are created as:

Person Table:
Id
Name

PersonStatistic Table:
Id
Date
Count
Person_Id

Because of this structure, when I create a unique key, the column order looks like "Date - Person_Id". But I want the order of the columns in the key, like "Person_Id - Date"

Entities and classes of cards, as shown below.

Entities:

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; }
}

Card 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");
}

Is there something wrong with my classes or collation, or another trick to set the order of the columns in the key?

+3
source share
1 answer

Try placing a call Referencesbefore Map.

0
source

Source: https://habr.com/ru/post/1782525/


All Articles