- Install-package Microsoft.EntityFrameworkCore
- Install-package Microsoft.EntityFrameworkCore.SqlServer
- Install-package Microsoft.EntityFrameworkCore.Design
- Install-package Microsoft.EntityFrameworkCore.Tools
- Install-package Microsoft.EntityFrameworkCore.SqlServer.Design
- protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
- {
- if (!optionsBuilder.IsConfigured)
- {
- #warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
- //optionsBuilder.UseSqlServer("Server=.;database=CommonPermission;User ID=sa;Password=123;");
- }
- }
- {
- "Logging": {
- "LogLevel": {
- "Default": "Warning"
- }
- },
- "ConnectionStrings": {
- "SQLConnection": "Server=.;database=CommonPermission;User ID=sa;Password=123;"
- },
- "AllowedHosts": "*"
- }
- // 注入上下文对象
- services.AddDbContext<CommonPermissionContext>(x => x.UseSqlServer(Configuration.GetConnectionString("SQLConnection")));
来源: http://www.bubuko.com/infodetail-3028511.html