I'm trying MVC 6, Entity Framework 7 and ASP.NET Identity for the first time. I just generated a default project and I'm changing the login process to support accounts by tenant, based on the following tutorial.
https://www.scottbrady91.com/ASPNET-Identity/Quick-and-Easy-ASPNET-Identity-Multitenancy
The thing is, when I try to change the initial migration to support a composite key (Id,TenentId) on the AspNetUsers table it simply fails with a generic message. The migration code is the following.
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 }); }); I also tried the following code but it also doesn't work.
constraints: table => { table.PrimaryKey("PK_ApplicationUser", x => x.Id); table.PrimaryKey("PK_ApplicationUser", x => x.TenantId); }); If I leave it as a non composite key the migration executes successfully.
constraints: table => { table.PrimaryKey("PK_ApplicationUser", x => x.Id); }); I tried to define a unique constraint over both columns but I wasn't able to find a way to do it.
Does anyone have any thoughts on this?