This article mainly for you to introduce the VS2017 add EF MVC Controller Error Resolution method, with a certain reference value, interested in small partners can refer to
VS2017 Add EF MVC Controller error Resolution, for your reference, the specific content as follows
1. Error description:No database provider have been configured fot this DbContext.
This type of error is caused by the registration of the context. Workaround in DbContext, rewrite the onconfiguring method to inject the database connection.
In DbContext:
public static string ConnectionString {get; set;} protected override void Onconfiguring (Dbcontextoptionsbuilder optionsbuilder) {optionsbuilder.usesqlserver ( ConnectionString); Base. Onconfiguring (Optionsbuilder);}
In the Startup.cs
public void Configureservices (iservicecollection services) { //ADD framework services. var sqlserverconnection = configuration.getconnectionstring ("sqlserverconnection"); dbcontext.connectionstring = sqlserverconnection;//The configuration connection into the services in DbContext . adddbcontext<dbcontext> (options = options. Usesqlserver (sqlserverconnection)); Services. Addmvc ();}
2. Description of the error: Could not add Model type XXX to DbContext
The error description does not register the DbSet property. But actually there is public dbset<xxx> xxx{get; set;} Registered. Changing a class in dbset<xxx> to a < namespace + class name > this complete declaration resolves