Creating the DbContext Class

The instance of the DbContext class represents the session to the database and this DbContext class does most of the heavy lifting of your data access for your application. Create a new class named EmployeeDbContext with the following content:


Go to https://goo.gl/hbju3w to access the code.
using Microsoft.EntityFrameworkCore;
namespace ConsoleEF
{
public class EmployeeDbContext : DbContext
{
public DbSet<Employee> Employees { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(@"Data Source=
(localdb)\MSSQLLocalDB;Initial Catalog=
EFConsole;Integrated Security=True;Connect
Timeout=30;
Encrypt=False;TrustServerCertificate=True;
ApplicationIntent=ReadWrite;
MultiSubnetFailover=False");
}
}

There are a few things to be noted in the preceding code snippet: