流畅的 nhibernate 中唯一的键列顺序
我尝试使用流畅的 nhibernate 创建唯一索引。但是当我使用以下课程时 表的创建方式如下:
Person Table:
Id
Name
PersonStatistic Table:
Id
Date
Count
Person_Id
由于当我创建唯一键时的这种结构,列顺序看起来像“日期 - Person_Id”。但我想按“Person_Id - Date”
实体等键的列顺序并映射类,如下所示。
实体类:
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; }
}
映射类:
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");
}
我的类或映射或设置键中列顺序的其他技巧出了问题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将
References
调用放在Map
调用之前。Try putting the
References
call before theMap
one.