The exception is selected by the purpose of the call - when creating the controller

I am new to ASP.NET MVC 5 and I was building a small application. While I was adding the controller, a message appeared: "An error occurred with the code generator running: the exception was caused by the purpose of the call." Before adding the controller, I added the connection string to the Web.Config file. Please tell me how to solve this error.

0
source share
2 answers

There may be a mismatch between your model and the connection string. Have you created a model? If so, then your DbContext class name must match the name provided on your connection string. It is also case sensitive. See the example below.

--- Model Class ---

Public Class Model
    Public Property ...
End Class

Public Class ModelDbContext
    Inherits DbContext

    Public Property Models As DbSet(Of Model)
End Class

Imports System.Data.Entity

:

<add name="ModelDbContext"
     connectionString="Data Source=LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\Models.mdf;Integrated Security=True"
     providerName="System.Data.SqlClient" />
+2

, throwIfV1Schema false DbContext,

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext() : base("DefaultConnection", throwIfV1Schema: false) { }

    public static ApplicationDbContext Create()
    {
        return new ApplicationDbContext();
    }
}
0

Source: https://habr.com/ru/post/1629506/


All Articles