From 0c31e225409b39294b9c50312ef2a82b18ef12ed Mon Sep 17 00:00:00 2001 From: James Skimming Date: Mon, 24 Feb 2014 14:19:37 +0000 Subject: [PATCH] Updated the user index to incorporate the TenantId --- .../MultitenantIdentityDbContext.Generic.cs | 11 +++++++++++ .../MultitenantIdentityDbContext.cs | 10 +++++++++- .../Models/IdentityModels.cs | 17 +++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/AspNet.Identity.EntityFramework.Multitenant/MultitenantIdentityDbContext.Generic.cs b/src/AspNet.Identity.EntityFramework.Multitenant/MultitenantIdentityDbContext.Generic.cs index 926da61..ff16b9a 100644 --- a/src/AspNet.Identity.EntityFramework.Multitenant/MultitenantIdentityDbContext.Generic.cs +++ b/src/AspNet.Identity.EntityFramework.Multitenant/MultitenantIdentityDbContext.Generic.cs @@ -8,8 +8,10 @@ namespace AspNet.Identity.EntityFramework.Multitenant { using System; using System.Collections.Generic; + using System.ComponentModel.DataAnnotations.Schema; using System.Data.Entity; using System.Data.Entity.Infrastructure; + using System.Data.Entity.Infrastructure.Annotations; using System.Data.Entity.Validation; using System.Linq; using Microsoft.AspNet.Identity; @@ -86,6 +88,15 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder) modelBuilder.Entity() .HasKey(e => new { e.TenantId, e.LoginProvider, e.ProviderKey, e.UserId }); + + modelBuilder.Entity() + .Property(u => u.UserName) + .HasColumnAnnotation( + "Index", + new IndexAnnotation(new IndexAttribute("UserNameIndex", order: 1) + { + IsUnique = true + })); } } } diff --git a/src/AspNet.Identity.EntityFramework.Multitenant/MultitenantIdentityDbContext.cs b/src/AspNet.Identity.EntityFramework.Multitenant/MultitenantIdentityDbContext.cs index 7282102..a97621b 100644 --- a/src/AspNet.Identity.EntityFramework.Multitenant/MultitenantIdentityDbContext.cs +++ b/src/AspNet.Identity.EntityFramework.Multitenant/MultitenantIdentityDbContext.cs @@ -8,7 +8,9 @@ namespace AspNet.Identity.EntityFramework.Multitenant { using System; using System.Collections.Generic; + using System.ComponentModel.DataAnnotations.Schema; using System.Data.Entity; + using System.Data.Entity.Infrastructure.Annotations; using System.Linq; using Microsoft.AspNet.Identity.EntityFramework; @@ -48,7 +50,13 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder) modelBuilder.Entity() .Property(e => e.TenantId) .HasMaxLength(128) - .IsRequired(); + .IsRequired() + .HasColumnAnnotation( + "Index", + new IndexAnnotation(new IndexAttribute("UserNameIndex", order: 0) + { + IsUnique = true + })); } } } diff --git a/src/Examples/IntegerPkImplementation/Models/IdentityModels.cs b/src/Examples/IntegerPkImplementation/Models/IdentityModels.cs index f4825ab..c6b6530 100644 --- a/src/Examples/IntegerPkImplementation/Models/IdentityModels.cs +++ b/src/Examples/IntegerPkImplementation/Models/IdentityModels.cs @@ -1,5 +1,7 @@ using Microsoft.AspNet.Identity.EntityFramework; +using System.ComponentModel.DataAnnotations.Schema; using System.Data.Entity; +using System.Data.Entity.Infrastructure.Annotations; using AspNet.Identity.EntityFramework.Multitenant; namespace IntegerPkImplementation.Models @@ -41,5 +43,20 @@ public ApplicationDbContext() : base("DefaultConnection") { } + + protected override void OnModelCreating(DbModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + + modelBuilder.Entity() + .Property(e => e.TenantId) + .IsRequired() + .HasColumnAnnotation( + "Index", + new IndexAnnotation(new IndexAttribute("UserNameIndex", order: 0) + { + IsUnique = true + })); + } } } \ No newline at end of file