在Move ASP.NET Identity store to EF Sql database中,zoidbergi描述了一个类似于我正在经历的问题,但并没有完全得到回答。当我试图从内置的.mdf数据库迁移到MySQL时,我收到了上面的错误。我使用的是Database-First方法,并且已经成功地从底层Mysql数据库创建了实体模型。
无论我是否重新创建asp.net身份数据表,只要访问用户管理器,应用程序就会阻塞:
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模型:
Public Class ApplicationDbContext
Inherits IdentityDbContext(Of ApplicationUser)
Public Sub New()
MyBase.New("IMSEntities")
End Sub
End Class谷歌倾向于找到那些放弃并编写自己的安全提供商的人-如果可能的话,我想使用标准的安全提供商。莫名其妙!
发布于 2014-03-24 16:20:01
(不优雅?)解决方案:
我观看了Alexander Schmidt的这个不错的视频https://www.youtube.com/watch?v=elfqejow5hM,在33:00,作者透露,连接字符串不应该是EF连接字符串(使用EF提供者),而应该是专门为安全设置的普通MYSQL/SQLServer连接字符串,即:
<add name="IMSSecurityEntities" connectionString="data source=localhost;database=mydb;Uid=id;Pwd=password;" providerName="mysql.data.mysqlclient"/>同样,身份模型也应该调整为:
Public Class ApplicationDbContext
Inherits IdentityDbContext(Of ApplicationUser)
Public Sub New()
MyBase.New("IMSSecurityEntities")
End Sub这让我对通过ORM访问安全实体感到紧张--但我猜很可能是故意的,所以可能没有损失。
发布于 2017-03-22 14:18:16
在我的例子中,它是连接字符串的providerName属性。我使用Database First生成的连接字符串的副本,它使用System.Data.EntityClient,而普通连接字符串(到SQL Server)使用System.Data.SqlClient。所以我改变了这个
<add name="DefaultConnection" connectionString="..." System.Data.EntityClient"/>到这个
<add name="DefaultConnection" connectionString="..." System.Data.SqlClient"/>https://stackoverflow.com/questions/22592770
复制相似问题