The entity type ApplicationUser is not part of the model for the current context. Used two different databases at beginning of project

后端 未结 2 613
无人及你
无人及你 2021-01-14 16:03

I\'ve created an MVC 4 application using entity framework to read and write data to a database I am hosting on an Azure database. The Azure database was supposed to keep th

2条回答
  •  一整个雨季
    2021-01-14 16:50

    I have tried to reproduce your issue according with below steps:

    1) create Asp.net MVC template, then register a new user.

    Result: We could find user info on local database.

    2) Add controller with views using Entity Framework. And use Azure SQL database as its resource.

    Result: we will find two connection in our web.config

    3) Delete default connection string

    4) Change Application DB Context connection string

       
    
     public class ApplicationDbContext : IdentityDbContext
        {
            public ApplicationDbContext()
                : base("jambdbEntities", throwIfV1Schema: false)
            {
            }
    
            public static ApplicationDbContext Create()
            {
                return new ApplicationDbContext();
            }
        }
    

    After above steps, My application give me below error:

    Solution:

    1) Edit 'DefaultConnection' connection string

      
        
        
      
    

    2) Modify the code:

     public class ApplicationDbContext : IdentityDbContext
        {
            public ApplicationDbContext()
                : base("jambdbEntitiesapplication", throwIfV1Schema: false)
            {
            }
    
            public static ApplicationDbContext Create()
            {
                return new ApplicationDbContext();
            }
        }
    

    3) Modify AutomaticMigrationsEnabled = true; in Configuration class under Migrations folder.

    Here is the result:

提交回复
热议问题