EF Core ASP.NET Application
Registering the Context with Dependency Injection
To enable dependency injection for ADPContext, you must register it with the service container.
In newer ASP.NET Core projects (using the minimal hosting model), this is done in Program.cs.
In older projects, the code may go in Startup.cs.
using MySolutionName.Models;
using Microsoft.EntityFrameworkCore;
var connection = @"InitiateOAuth=GETANDREFRESH;OAuthClientId=YourClientId;OAuthClientSecret=YourClientSecret;SSLClientCert='c:\\cert.pfx';SSLClientCertPassword='admin@123'";
builder.Services.AddDbContext<ADPContext>(options =>
options.UseADP(connection));
Creating a Controller and Views
To create a controller and views for your web app, follow these steps:
- Right-click the Controllers folder in the Solution Explorer and select Add -> Controller...
- Choose MVC Controller with views, using Entity Framework, and then click Add.
- Set the Model Class to the class corresponding to your table or view and set the Data context class to ADPContext.
- Click Add. Take note of the controller name.
Running Your Application
Once the controller and views are set up, you can run your application by selecting Debug -> Start Without Debugging. Your browser will open automatically. To view your data, navigate to: Now that the controllers and views have been setup, you can launch your app using Debug -> Start Without Debugging. The app will then launch in your browser. You can find your data by navigating to <base URL>/<controller name without the "Controller" suffix>