我有一个场景,我需要定义两个多列唯一约束,如下所示:
public class UserMap : IAutoMappingOverride<User>
{
public void Override(AutoMapping<User> mapping)
{
mapping.Map(x => x.UserName)
.UniqueKey("UQ_User_UserName_Client");
mapping.Map(x => x.LoweredEmail)
.UniqueKey("UQ_User_Email_Client");
mapping.References(x => x.Client)
.UniqueKey("UQ_User_UserName_Client")
.UniqueKey("UQ_User_Email_Client");
}
}
这样做的原因是我需要每个客户的用户名和电子邮件都是唯一的。生成的 SQL 如下所示:
create table Users (
Id UNIQUEIDENTIFIER not null,
UserName NVARCHAR(256) not null,
LoweredEmail NVARCHAR(256) not null,
Email NVARCHAR(256) not null,
ClientId UNIQUEIDENTIFIER null,
primary key (Id),
unique (UserName),
unique (LoweredEmail, ClientId)
)
这不是预期的效果。如何创建以下 SQL?
create table Users (
Id UNIQUEIDENTIFIER not null,
UserName NVARCHAR(256) not null,
LoweredEmail NVARCHAR(256) not null,
Email NVARCHAR(256) not null,
ClientId UNIQUEIDENTIFIER null,
primary key (Id),
unique (UserName, ClientId),
unique (LoweredEmail, ClientId)
)
我不确定这是否是 Fluent 或 NHibernate 的问题/限制。任何帮助,将不胜感激。