Identity 2.0 User's UserRole always Null
<p>So i'm having issues with Identity and UserRoles. I have inherited from the base classes, and then added some custom fields. The user object now has a person, which two other classes inherit from  (Applicant and Reviewer).</p>

<p>I have tried so much to get this working in terms of re-ordering the mappings of the tables in the model builder, removing my custom inherited classes, forcing lazy loading.</p>

<p>Any suggestions or help on this would be greatly appreciated.</p>

<p>This is the applicant context.    </p>

<pre><code> public class ApplicantContext : IdentityDbContext&lt;User&gt;
        {
            public ApplicantContext()
                : base("ApplicantDbConnection")
            {
                this.Configuration.LazyLoadingEnabled = true;
            }


            public DbSet&lt;Person&gt; People { get; set; }
            public DbSet&lt;Applicant&gt; Graduates { get; set; }
            public DbSet&lt;Reviewer&gt; Reviewers { get; set; }



            //stop pluralising generated tables
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                base.OnModelCreating(modelBuilder);

                modelBuilder.Entity&lt;User&gt;().ToTable("Users");
                modelBuilder.Entity&lt;Role&gt;().HasKey&lt;string&gt;(r =&gt; r.Id).ToTable("Roles");
                modelBuilder.Entity&lt;User&gt;().HasRequired(i =&gt; i.Person).WithMany().HasForeignKey&lt;int&gt;(i =&gt; i.PersonID);
                modelBuilder.Entity&lt;User&gt;().HasMany&lt;UserRole&gt;((User u) =&gt; u.UserRoles);
                modelBuilder.Entity&lt;UserRole&gt;().HasKey(r =&gt; new { UserId = r.UserId, RoleId = r.RoleId }).ToTable("UserRoles");

                modelBuilder.Entity&lt;IdentityUser&gt;()
                   .ToTable("Users");

                modelBuilder.Entity&lt;IdentityRole&gt;()
                    .ToTable("Roles");

                modelBuilder.Entity&lt;IdentityUserRole&gt;()
                    .ToTable("UserRoles");

                modelBuilder.Entity&lt;IdentityUserClaim&gt;()
                    .ToTable("UserClaims");

                modelBuilder.Entity&lt;IdentityUserLogin&gt;()
                    .ToTable("UserLogins");



            }
        }
</code></pre>

<blockquote>
  <p>Db Initialiser. The database side of things seems all fine, but when
  i log into the system, the login is successful, however when it
  redirects to Home controller Index, the Index page uses
  [Authorize(Roles="Reviewer")] and this is where it fails. It says the
  user is not in that role, however in the database the UserId is paired
  with the RoleID in the UserRoles table. Therefore the User's role is
  null.</p>
</blockquote>

<pre><code>public class DataInitialiser : CreateDatabaseIfNotExists&lt;ApplicantContext&gt;
    {

        protected override void Seed(ApplicantContext context)
        {

            var manager = new RoleManager&lt;IdentityRole&gt;(new RoleStore&lt;IdentityRole&gt;(context));
            manager.Create(new IdentityRole("Reviewer"));
            manager.Create(new IdentityRole("Applicant"));

            ApplicationUserManager userManager = new ApplicationUserManager(new UserStore&lt;User&gt;(context));
            User user = new User
            {
                Person = new Reviewer
                {

                    FirstName = "Grant",
                    MiddleNames = "Mark",
                    Surname = "Weatherston",
                    OfficeID = 1,
                },
                Email = "test@test.com",
                UserName = "test@test.com",
                PhoneNumber = "0123456789",
            };

            userManager.Create(user, "Password123");
            userManager.AddToRole(user.Id, "Reviewer");

            context.SaveChanges();

            base.Seed(context);
        }

    }
</code></pre>

<p>Custom Role class inheriting from IdentityRole.</p>

<pre><code> public class Role : IdentityRole
    {
        public Role() { }
        public Role(string name) :base(name)
        {
        }

    }
</code></pre>

<p>Custom User class inherits from identity user with adding property Person.</p>

<pre><code> public class User : IdentityUser
    {
        public User() { }

        public int PersonID { get; set; }

        [ForeignKey("PersonID")]
        public virtual Person Person { get; set; }

        public virtual ICollection&lt;UserRole&gt; UserRoles {get;set;}

        public async Task&lt;ClaimsIdentity&gt; GenerateUserIdentityAsync(UserManager&lt;User&gt; manager)
        {
            // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
            // Add custom user claims here
            return userIdentity;
        }
    }
</code></pre>

<p>Custom User Role Class.</p>

<pre><code>    public class UserRole : IdentityUserRole
        {

        }
</code></pre>

<p>Custom Role Manager.</p>

<pre><code>public class ApplicationRoleManager : RoleManager&lt;IdentityRole&gt;
    {

        public ApplicationRoleManager(RoleStore&lt;IdentityRole&gt; roleStore)
            : base(roleStore)
        {

        }

    }
</code></pre>

<p>Custom UserManager</p>

<pre><code>public class ApplicationUserManager : UserManager&lt;User&gt;
    {
        public ApplicationUserManager(IUserStore&lt;User&gt; store)
            : base(store)
        {
        }

   }
</code></pre>