ASP.NET/Identity错误:实体类型ApplicationUser不是当前上下文模型的一部分 [英] ASP.NET/Identity Error: The entity type ApplicationUser is not part of the model for the current context

查看:30
本文介绍了ASP.NET/Identity错误:实体类型ApplicationUser不是当前上下文模型的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将ASP.NET身份存储移动到EF Sql数据库中 zoidbergi描述了一个与我所遇到的问题类似的问题,但尚未完全解决.尝试从内置的.mdf数据库迁移到MySQL时,出现上述错误.我正在使用数据库优先方法,并已成功从基础Mysql数据库创建了实体模型.

In Move ASP.NET Identity store to EF Sql database zoidbergi described an issue similar to that which I'm experiencing, but which was not completely answered. I am receiving the error above when attempting to migrate from the inbuilt .mdf database to MySQL. I am using a Database-First methodology and have successfully created the Entity Model from the underlying Mysql database.

无论我是否重新创建asp.net身份数据表,应用程序都会在访问用户管理器后立即阻塞:

No matter whether I recreate the asp.net identity datatables the application chokes as soon as user manager is accessed:

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

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: The entity type ApplicationUser is not part of the model for the current context.

Source Error:  

Line 65:             ' Create a local login before signing in the user
Line 66:             Dim user = New ApplicationUser() With {.UserName = model.UserName}
**Line 67:             Dim result = Await UserManager.CreateAsync(User, model.Password)**
Line 68:             If result.Succeeded Then
Line 69:                 Await SignInAsync(User, isPersistent:=False)

我已经将ApplicationDBContext指向了我的DbContext模型:

I have pointed the ApplicationDBContext at my DbContext model:

Public Class ApplicationDbContext
    Inherits IdentityDbContext(Of ApplicationUser)
    Public Sub New()
        MyBase.New("IMSEntities")
    End Sub
End Class

使用Google搜索时,往往会找到放弃并编码自己的安全提供程序的人员-如果可能的话,我想使用标准的安全提供程序.莫名其妙!

Googling tends to find people who have given up and coded up their own security providers - I'd like to use the standard one if possible. Baffled!

推荐答案

(INELEGANT?)解决方案:

(INELEGANT?) SOLUTION:

我观看了这段精彩的视频, https://www.youtube.com/watch?v=elfqejow5hM 亚历山大·施密特(Alexander Schmidt)并在33:00揭示了该连接字符串不应该是EF连接字符串(使用EF提供程序),而应该是专门为安全性设置的原始MYSQL/SQLServer连接字符串,即:

I watched this excellent video https://www.youtube.com/watch?v=elfqejow5hM by Alexander Schmidt and at 33:00 the author reveals that the connection string should not be an EF connection string (using the EF provider) but should be a vanilla MYSQL/SQLServer connection string specifically set up for security, ie:

<add name="IMSSecurityEntities" connectionString="data source=localhost;database=mydb;Uid=id;Pwd=password;" providerName="mysql.data.mysqlclient"/>

并且类似地,身份模型应调整为:

and similarly the identity model should be adjusted to:

Public Class ApplicationDbContext
    Inherits IdentityDbContext(Of ApplicationUser)
    Public Sub New()
        MyBase.New("IMSSecurityEntities")
    End Sub

这使我担心通过ORM访问安全实体-但我想可能完全是设计使然,因此可能不会造成任何损失.

This makes me nervous about accessing the security entities through the ORM - but I guess may well be by design so maybe no loss.

这篇关于ASP.NET/Identity错误:实体类型ApplicationUser不是当前上下文模型的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆