我有以下設置:Asp.net身份的DbContext
我已經通過創建我自己的類,並從身份類繼承定製IdentityUser和IdentityRole類
而且我已經有基於實體框架我的域模型(通過EDMX設計器)
因爲我想通過使用在我的正常的域模型類擴展IdentityUser,I C掛的數據上下文的TT到<#=Accessibility.ForType(container)#> partial class <#=code.Escape(container)#> : IdentityDbContext<ApplicationUser>
外部記錄所產生的文件,我已經創建的局部類從ApplicationDataContext像這樣:
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; }
}
類UserStoreAssignment
指向一個類Store
,其位於領域模型。一切都可以成功建立。但只要我開始從我的應用程序中訪問ApplicationUser
,我得到了以下錯誤消息:
的實體類型ApplicationUser是不是該機型爲當前上下文的一部分。
有誰知道,問題可能是什麼?