Asp.net 表映射ASPNET标识时出错

Asp.net 表映射ASPNET标识时出错,asp.net,entity-framework,entity-framework-5,code-first,Asp.net,Entity Framework,Entity Framework 5,Code First,显然,我对这一点并不熟悉,但我一直在与新的身份会员提供商合作,试图将我们的旧网站转换为标准平台。到目前为止,一切似乎都按预期运行,但当我尝试登录到我们的站点时,我收到以下错误{“无效列名'ApplicationUser_Id'。”。我相信这与EF试图映射我的两个用户表之间关系的方式有关。我有第一个表AspNetUsers,然后是一个扩展的概要文件表ISF_ProfileEmployee。请参阅下面的信息。我一直在关注pranav rastogi的博客,因此如果他在附近,我将非常感谢他的帮助 这是

显然,我对这一点并不熟悉,但我一直在与新的身份会员提供商合作,试图将我们的旧网站转换为标准平台。到目前为止,一切似乎都按预期运行,但当我尝试登录到我们的站点时,我收到以下错误{“无效列名'ApplicationUser_Id'。”。我相信这与EF试图映射我的两个用户表之间关系的方式有关。我有第一个表AspNetUsers,然后是一个扩展的概要文件表ISF_ProfileEmployee。请参阅下面的信息。我一直在关注pranav rastogi的博客,因此如果他在附近,我将非常感谢他的帮助

这是我的密码

    public class ISF_ProfileEmployee
    {

        public Guid UserID { get; set; }
        public string AlternateEmployeeId { get; set; }
        public Guid DefaultDashboardId { get; set; }
        public DateTime LastUpdatedDate { get; set; }
        public string AlternateEmailAddress { get; set; }
        public DateTime EmploymentStartDate { get; set; }
        public string EmployeeStatus { get; set; }
        public bool IsSupervisor { get; set; }
        public Guid ISFLocationId { get; set; }
        public Guid ISFDepartmentId { get; set; }
        public Guid ISFSupervisorId { get; set; }
        public Guid ISFPositionId { get; set; }
        public Guid StatusId { get; set; }
        public string StatusMessage { get; set; }
        public DateTime StatusUpdateDate { get; set; }
        public bool InBoardUser { get; set; }
        public Guid? InBoardStatus { get; set; }
        [Required]
        public DateTime HireDate { get; set; }
        public string GersUserId { get; set; }
        public bool UseCustomDash { get; set; }
    }

    public class ApplicationUser : IdentityUser
    {
        [Required]
        public string FirstName { get; set; }
        [Required]
        public string LastName { get; set; }
        public string Nickname { get; set; }
        [Required]
        public string Email { get; set; }
        public bool Disabled { get; set; }
        public DateTime? BirthDay {get; set;}
        public string ImageFileName {get; set;}
        public string OfficePhone {get; set;}
        public string MobilePhone { get; set; }
        public string Extension { get; set; }
        public string FaxPhone {get; set;}
        public string PasswordQuestion {get; set;}
        public string PasswordAnswer {get; set;}
        public DateTime CreateDate {get; set;}
        public DateTime LastLockoutDate {get; set;}
        public bool IsLockedOut {get; set;}
        public int FailedPasswordAttemptCount {get; set;}
        public DateTime FailedPasswordAttemptWindowStart {get; set;}
        public int FailedPasswordAnswerAttemptCount {get; set;}
        public DateTime FailedPasswordAnswerAttemptWindowStart {get; set;}
        public DateTime LastPasswordChangedDate {get; set;}
        public string Comment {get; set;}

        public ISF_ProfileEmployee ISF_ProfileEmployee { get; set; }
    }

    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext()
            : base("DefaultConnection")
        {
        }
    protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.Entity<IdentityUser>().HasKey(k => k.Id).Property(p => p.Id).HasColumnName("UserId");
        modelBuilder.Entity<IdentityRole>().HasKey(r=>r.Id).Property(p => p.Id).HasColumnName("RoleId");
        modelBuilder.Entity<IdentityRole>().Property(p => p.Name).HasColumnName("RoleName");
        modelBuilder.Entity<ISF_ProfileEmployee>().ToTable("ISF_ProfileEmployee").HasKey(p => p.UserID);
        modelBuilder.Entity<ApplicationUser>().HasRequired(x => x.ISF_ProfileEmployee).WithRequiredPrincipal();

    }
公共类ISF\U ProfileEmployee
{
公共Guid用户标识{get;set;}
公共字符串AlternateEmployeeId{get;set;}
公共Guid DefaultDashboardId{get;set;}
公共日期时间LastUpdateDate{get;set;}
公共字符串AlternateEmailAddress{get;set;}
public DateTime EmploymentStartDate{get;set;}
公共字符串EmployeeStatus{get;set;}
公共bool发行人{get;set;}
公共Guid ISFLocationId{get;set;}
公共Guid ISFDepartmentId{get;set;}
公共Guid ISFSupervisorId{get;set;}
公共Guid ISFPositionId{get;set;}
公共Guid状态ID{get;set;}
公共字符串状态消息{get;set;}
公共日期时间状态更新日期{get;set;}
公共bool-InBoardUser{get;set;}
公共Guid?InBoardStatus{get;set;}
[必需]
公共日期时间HireDate{get;set;}
公共字符串GersUserId{get;set;}
公共bool UseCustomDash{get;set;}
}
公共类应用程序用户:IdentityUser
{
[必需]
公共字符串名{get;set;}
[必需]
公共字符串LastName{get;set;}
公共字符串昵称{get;set;}
[必需]
公共字符串电子邮件{get;set;}
公共bool已禁用{get;set;}
公共日期时间?生日{get;set;}
公共字符串ImageFileName{get;set;}
电话{get;set;}的公共字符串
公共字符串移动电话{get;set;}
公共字符串扩展名{get;set;}
公用字符串传真电话{get;set;}
公共字符串密码问题{get;set;}
公共字符串密码应答{get;set;}
公共日期时间CreateDate{get;set;}
公共日期时间LastLockoutDate{get;set;}
公共bool IsLockedOut{get;set;}
public int FailedPasswordAttemptCount{get;set;}
public DateTime FailedPasswordAttemptWindowsStart{get;set;}
public int FailedPasswordAnswerAttemptCount{get;set;}
public DateTime FailedPasswordAnswerAttemptWindowsStart{get;set;}
公共日期时间LastPasswordChangedDate{get;set;}
公共字符串注释{get;set;}
公共ISF_ProfileEmployee ISF_ProfileEmployee{get;set;}
}
公共类ApplicationDbContext:IdentityDbContext
{
公共应用程序上下文()
:base(“默认连接”)
{
}
模型创建时受保护的覆盖无效(System.Data.Entity.DbModelBuilder modelBuilder)
{
基于模型创建(modelBuilder);
modelBuilder.Entity().HasKey(k=>k.Id).Property(p=>p.Id).HasColumnName(“UserId”);
modelBuilder.Entity().HasKey(r=>r.Id).Property(p=>p.Id).HasColumnName(“RoleId”);
modelBuilder.Entity().Property(p=>p.Name).HasColumnName(“RoleName”);
modelBuilder.Entity().ToTable(“ISF_ProfileEmployee”).HasKey(p=>p.UserID);
modelBuilder.Entity().HasRequired(x=>x.ISF_ProfileEmployee).WithRequiredPrincipal();
}

我认为可能发生的情况是,由于您是从早期的成员系统迁移过来的,该系统有一个ApplicationSerid列,该列仍然存在,或者EF正在查找该列,并且无法映射该列。请尝试将ApplicationSerid列映射到UserId,看看是否有效

我永远无法获得answer来解决这个问题。身份成员显然对您使用的表中的列名非常挑剔。我最终合并了两个表,并将UserId列改回Id(这是Aspnet Identity所期望的名称)一旦我做到了这一点,我就可以很容易地向前迈进。在我看来,在定制它所使用的模式的能力方面,还需要做更多的工作。此外,缺乏文档是相当令人沮丧的,这个想法很好,但后续工作还有待改进。

我在这里的任何地方都没有看到属性应用程序用户Ide类。它是否在视图中被引用?视图可能期望模型拥有它,并且在找不到它时抛出错误。没有在任何地方引用它。据我所知,实体框架正在尝试解析两个表之间的映射,并期望一个具有该名称的列,而实际上没有。您是否执行了sol注意搜索
ApplicationUser\u Id
是,未找到匹配项。可能是其中一个表上的外键?当我尝试使用modelBuilder.Entity().Property(p=>p)时,该列在我的两个模型上都不可用。您对解决此问题有其他想法吗?