The context cannot be used while the model is being created

前端 未结 14 1390
渐次进展
渐次进展 2020-12-03 13:27

In my application I receive the following error:

The context cannot be used while the model is being created.

I\'m not sure what

14条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-03 14:00

    Solved by the following:

    I had the same issue in my application and resolved by using the below.

    1. Verify your Model names and the table names and it should be matched.

    2. Datatype and Column names used in the model and the database table column name/ Datatype should be matched.

    3. use the below code in your Context class

      Public class MVCRepositoryContext : DbContext 
      {
          static MVCRepositoryContext()
          {
              Database.SetInitializer < mvcrepositorycontext > (null);
          }
      
          public MVCRepositoryContext():base("MVCRepositoryContext"){ }
      
          public virtual DbSet Customers { get; set; }
      
          public virtual DbSet Books { get; set; }
      
          public virtual DbSet Authors { get; set; }
      }
      

提交回复
热议问题