VS2017 adding EF to the MVC controller error resolution method

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.