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 Identity store to EF Sql数据库zoidbergi描述了一个类似于我正在经历的问题,但是这个问题并没有得到完全的回答。当试图从inbuild .mdf数据库迁移到MySQL时,我收到了上面的错误。我使用的是数据库优先的方法,并且已经成功地从底层Mysql数据库创建了实体模型。
No matter whether I recreate the asp.net identity datatables the application chokes as soon as user manager is accessed:
无论我是否重新创建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)
I have pointed the ApplicationDBContext at my DbContext model:
我在DbContext模型中指出了ApplicationDBContext:
Public Class ApplicationDbContext
Inherits IdentityDbContext(Of ApplicationUser)
Public Sub New()
MyBase.New("IMSEntities")
End Sub
End Class
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!
谷歌搜索倾向于找到那些已经放弃并编写了自己的安全服务的人——如果可能的话,我希望使用标准的安全服务。困惑!
2 个解决方案
#1
28
(INELEGANT?) SOLUTION:
(不雅的?)解决方案:
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:
我看了这个很棒的视频https://www.youtube.com/watch?由Alexander Schmidt和at 33:00的作者发现,连接字符串不应该是EF连接字符串(使用EF提供程序),但是应该是专门为安全设置的一个MYSQL/SQLServer连接字符串。
<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
This makes me nervous about accessing the security entities through the ORM - but I guess may well be by design so maybe no loss.
这让我对通过ORM访问安全实体感到紧张——但我猜很可能是设计的,所以可能没有损失。
#2
0
In my case it was the providerName
property of the connection string. I used a copy of Database First generated connection string which uses System.Data.EntityClient
while normal connection strings (to SQL Server) use System.Data.SqlClient
. So I changed this
在我的例子中,它是连接字符串的providerName属性。我使用了数据库第一生成的使用System.Data的连接字符串的副本。正常连接字符串(到SQL Server)使用System.Data.SqlClient。所以我改变了这个
<add name="DefaultConnection" connectionString="..." System.Data.EntityClient"/>
to this
这个
<add name="DefaultConnection" connectionString="..." System.Data.SqlClient"/>
#1
28
(INELEGANT?) SOLUTION:
(不雅的?)解决方案:
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:
我看了这个很棒的视频https://www.youtube.com/watch?由Alexander Schmidt和at 33:00的作者发现,连接字符串不应该是EF连接字符串(使用EF提供程序),但是应该是专门为安全设置的一个MYSQL/SQLServer连接字符串。
<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
This makes me nervous about accessing the security entities through the ORM - but I guess may well be by design so maybe no loss.
这让我对通过ORM访问安全实体感到紧张——但我猜很可能是设计的,所以可能没有损失。
#2
0
In my case it was the providerName
property of the connection string. I used a copy of Database First generated connection string which uses System.Data.EntityClient
while normal connection strings (to SQL Server) use System.Data.SqlClient
. So I changed this
在我的例子中,它是连接字符串的providerName属性。我使用了数据库第一生成的使用System.Data的连接字符串的副本。正常连接字符串(到SQL Server)使用System.Data.SqlClient。所以我改变了这个
<add name="DefaultConnection" connectionString="..." System.Data.EntityClient"/>
to this
这个
<add name="DefaultConnection" connectionString="..." System.Data.SqlClient"/>