ASP.NET/Identity Error: The entity type ApplicationUser is not part of the model for the current context

前端 未结 2 1186
南方客
南方客 2020-12-31 05:29

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

相关标签:
2条回答
  • 2020-12-31 06:14

    (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:

    <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.

    0 讨论(0)
  • 2020-12-31 06:33

    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

    <add name="DefaultConnection" connectionString="..." System.Data.EntityClient"/>
    

    to this

    <add name="DefaultConnection" connectionString="..." System.Data.SqlClient"/>
    
    0 讨论(0)
提交回复
热议问题