Chris
Chris

Reputation: 7359

Asp.net Identity DbContext

I have the following setup:

  1. I've customized the IdentityUser and IdentityRole class by creating my own classes and inheriting from the Identity classes

  2. Also I've got my domain model based on the Entity Framework (via edmx-Designer)

Since I want to extend the IdentityUser by using classes that are in my regular domain model, I changed the TT of the data context to <#=Accessibility.ForType(container)#> partial class <#=code.Escape(container)#> : IdentityDbContext<ApplicationUser>

Outside of the generated files, I ve created a partial class from the ApplicationDataContext like so:

public partial class ApplicationDbContext
{

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

        modelBuilder.Entity<IdentityUser>().ToTable("User", "portal").Property(p => p.Id).HasColumnName("UserId");
        modelBuilder.Entity<ApplicationUser>().ToTable("User", "portal").Property(p => p.Id).HasColumnName("UserId");
        modelBuilder.Entity<IdentityUserRole>().ToTable("UserRoles", "portal");
        modelBuilder.Entity<IdentityUserLogin>().ToTable("UserLogins", "portal");
        modelBuilder.Entity<IdentityUserClaim>().ToTable("UserClaims", "portal");
        modelBuilder.Entity<UserStoreAssignment>().ToTable("UserStoreAssignment", "portal");
        modelBuilder.Entity<ApplicationRole>().ToTable("Roles", "portal");
    }

    new public DbSet<ApplicationRole> Roles { get; set; }
}

The class UserStoreAssignment points to a class Store that is located in the domain model. Everything can be build successfully. But as soon as I start accessing ApplicationUser from within my application, I get the following error message:

The entity type ApplicationUser is not part of the model for the current context.

Does anyone know, what the problem could be?

Upvotes: 0

Views: 631

Answers (1)

joelmdev
joelmdev

Reputation: 11773

It sounds like you're trying to map the ApplicationUser to a table, but you haven't actually added the ApplicationUser to the context via the Designer.

Upvotes: 0

Related Questions