Create the model & context
Create the model Student
Studentnamespace EFGetStarted
{
public class Student
{
public int Id { get; set; }
public string Name { get; set; }
public bool IsEnrolled { get; set; }
}
}Create the context MyContext
using Microsoft.EntityFrameworkCore;
namespace EFGetStarted
{
public class MyContext: DbContext
{
public DbSet<Student> Students { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
var server = "(localdb)";
var instance = "mssqllocaldb";
var database = "CollegeDB";
var authentication = "Integrated Security = true";
var conString = $"Data Source={server}\\{instance}; Initial Catalog={database};{authentication}";
options.UseSqlServer(conString);
}
}
}What is a DbContext ?
Last updated