public class Program { private static TestDBContext _tContext; private static void Main(string[] args) { Startup(); var dd = _tContext.User.Take(1).ToList(); //e(); } private static void Startup() { var services = new ServiceCollection(); var connectionString = "Data Source=192.168.3.1;User ID=sa;Password=sa;Database=dbname;Trusted_Connection=True;integrated security=false;TrustServerCertificate=True;"; services.AddDbContext<TZCArchiveContext>(options => options.UseSqlServer(connectionString)) .AddTransient<TestDBContext>() .AddOptions(); var prov = services.BuildServiceProvider(); _tContext = prov.GetService<TestDBContext>(); } }
标签:NetCore,prov,private,services,static,dbcontext,var,控制台,tContext From: https://www.cnblogs.com/xuanlanbinfen/p/17579341.html