public class SqlConfig:DbContext
{
public DbSet<AdminSQLModel> AdminTb { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(@"Server=.;Data Source=(local);uid=sa;pwd=sasa;DataBase=SpecialDB");
}
}
1.DbContext 必须继承;
2.public DbSet AdminTb { get; set; } AdminTb 名称是SQL中表名称;
3.DbSet<T> 返回的类型是IQueryable<T> 类型
4.查询SQL表实际效果是转换为EF操作数据库相关表数据
IQueryable<AdminSQLModel> str =sqldb.AdminTb.Where(s=>s.Id==ID);