一,nuget 添加
二,创建DbContext
U1为数据库表对象
public class Entities : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { //注入Sql链接字符串 optionsBuilder.UseSqlServer(@"Server=.;Database=TestUserData;uid=sa;pwd=sasa;"); } public DbSet<U1> U1 { get; set; } }
三,调用
static void Main(string[] args) { var q = db.U1.ToList(); Console.ReadLine(); }