Skip to content
This repository has been archived by the owner on May 1, 2019. It is now read-only.

Commit

Permalink
Updated the user index to incorporate the TenantId
Browse files Browse the repository at this point in the history
  • Loading branch information
JSkimming committed Feb 24, 2014
1 parent 7cbde73 commit 0c31e22
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -86,6 +88,15 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)

modelBuilder.Entity<TUserLogin>()
.HasKey(e => new { e.TenantId, e.LoginProvider, e.ProviderKey, e.UserId });

modelBuilder.Entity<TUser>()
.Property(u => u.UserName)
.HasColumnAnnotation(
"Index",
new IndexAnnotation(new IndexAttribute("UserNameIndex", order: 1)
{
IsUnique = true
}));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -48,7 +50,13 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)
modelBuilder.Entity<TUser>()
.Property(e => e.TenantId)
.HasMaxLength(128)
.IsRequired();
.IsRequired()
.HasColumnAnnotation(
"Index",
new IndexAnnotation(new IndexAttribute("UserNameIndex", order: 0)
{
IsUnique = true
}));
}
}
}
17 changes: 17 additions & 0 deletions src/Examples/IntegerPkImplementation/Models/IdentityModels.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -41,5 +43,20 @@ public ApplicationDbContext()
: base("DefaultConnection")
{
}

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

modelBuilder.Entity<ApplicationUser>()
.Property(e => e.TenantId)
.IsRequired()
.HasColumnAnnotation(
"Index",
new IndexAnnotation(new IndexAttribute("UserNameIndex", order: 0)
{
IsUnique = true
}));
}
}
}

0 comments on commit 0c31e22

Please sign in to comment.