1. public class AppDbContext : DbContext
    2. {
    3. public AppDbContext(DbContextOptions options) : base(options)
    4. {
    5. }
    6. public DbSet<Student> Students { get; set; }
    7. }
    • 在 DbContext 类中我们要对使用到的每个实体,都添加 DbSet 属性
    • 我们将使用此 DbSet 属性,Students 来查询和保存类文件 Student 的实例
    • 当对 DbSet 采用 LINQ 查询时,它会自动转换为 SQL 语句来对基础数据库做查询操作