Building MVC pattern project by Visual Studio 2017 ( ASP.Net Core Part )
Step 9. Create a new class library project called the infra project of .NET Core framework, which name is “Enterprise_Dot_Net_Core_WebApp.Infra.” After Visual Studio build-over the class library project, create two folders under this project, such as DBContext folders and the Repositories folder.

Note: Database context folder/file naming rules don’t set the “DbContext” because the entity framework has a tool name that is DbContext. If you set your database context file name is DbContext, the Visual Studio compiler will miss the entity framework’s Dbcontext reference. “Naming rules” are important! Important! Important!!
Step 10. Create the class file, which name is “DemoDbContext,” under the DBContext folder.

Note: This sample project is to add Microsoft.EntityFramework.Sqlserver to the reference part of the infra project. If you want to use other databases such as Mysql, SQLite, and PostgreSQL, you must install other Microsoft.EntityFramework database.
Step 11. Edit the connection database source code in the DemoDbContext file. DemoDbContext file will get the database connection string from the appsettings file of the web project. Don’t worry about it.

using Enterprise_Dot_Net_Core_WebApp.Core.Entities;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Text;
namespace Enterprise_Dot_Net_Core_WebApp.Infra.DBContext
{
public class DemoDbContext : DbContext
{
public DemoDbContext(DbContextOptions options) : base(options)
{ }
public DbSet<Enterprise_MVC_Core> Enterprise_MVC_Cores { get; set; }
}
}
Note: In this file, I only set the table by the “DbSet” method. You can select more tables or other forms in this file.
Step 12. Create the class file, which name is “Enterprise_MVC_Repository,” under the Repositories folder.

Step 13. Edit some codes in the Enterprise_MVC_Repository file. This code will accord the interface file of the core project to create the methods in this file. The infra project is based on Microsoft.EntityFrameworkCore library, so you write code that must follow the Microsoft.EntityFrameworkCore rules.

Note: If you want to see the complete source code, please go to my Github – Enterprise_MVC_WebApp. My Github link puts on my profile page. (Link)
1 Comment