【发布时间】:2016-05-11 17:16:56
【问题描述】:
我是第一次尝试 MVC 6、Entity Framework 7 和 ASP.NET Identity。 我刚刚生成了一个默认项目,我正在根据以下教程更改登录过程以支持租户帐户。
https://www.scottbrady91.com/ASPNET-Identity/Quick-and-Easy-ASPNET-Identity-Multitenancy
问题是,当我尝试更改初始迁移以支持 AspNetUsers 表上的复合键 (Id,TenentId) 时,它只是失败并显示一般消息。 迁移代码如下。
migrationBuilder.CreateTable(
name: "AspNetUsers",
columns: table => new
{
Id = table.Column<string>(nullable: false),
TenantId = table.Column<string>(nullable: false),
AccessFailedCount = table.Column<int>(nullable: false),
ConcurrencyStamp = table.Column<string>(nullable: true),
Email = table.Column<string>(nullable: true),
EmailConfirmed = table.Column<bool>(nullable: false),
LockoutEnabled = table.Column<bool>(nullable: false),
LockoutEnd = table.Column<DateTimeOffset>(nullable: true),
NormalizedEmail = table.Column<string>(nullable: true),
NormalizedUserName = table.Column<string>(nullable: true),
PasswordHash = table.Column<string>(nullable: true),
PhoneNumber = table.Column<string>(nullable: true),
PhoneNumberConfirmed = table.Column<bool>(nullable: false),
SecurityStamp = table.Column<string>(nullable: true),
TwoFactorEnabled = table.Column<bool>(nullable: false),
UserName = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ApplicationUser", x => new { x.Id, x.TenantId });
});
我也尝试了以下代码,但它也不起作用。
constraints: table =>
{
table.PrimaryKey("PK_ApplicationUser", x => x.Id);
table.PrimaryKey("PK_ApplicationUser", x => x.TenantId);
});
如果我将其保留为非复合键,则迁移将成功执行。
constraints: table =>
{
table.PrimaryKey("PK_ApplicationUser", x => x.Id);
});
我尝试在两列上定义唯一约束,但我无法找到方法。
有人对此有什么想法吗?
【问题讨论】:
-
你把代码放在哪里了?在 ApplicationUserDbContext 类的 OnModelCreating() 覆盖中?
-
在初始迁移文件中。
标签: c# asp.net entity-framework asp.net-identity