-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDesignTimeDbContextFactory.cs
More file actions
32 lines (27 loc) · 1.19 KB
/
Copy pathDesignTimeDbContextFactory.cs
File metadata and controls
32 lines (27 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// DesignTimeDbContextFactory.cs
using System.IO;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using MVCTicariOtomasyonWeb.Models.sınıflar;
namespace MVCTicariOtomasyonWeb
{
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<Context>
{
public Context CreateDbContext(string[] args)
{
var basePath = Directory.GetCurrentDirectory();
var config = new ConfigurationBuilder()
.SetBasePath(basePath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: false)
.AddJsonFile("appsettings.Development.json", optional: true)
.AddEnvironmentVariables()
.Build();
var conn = config.GetConnectionString("DefaultConnection")
?? "Server=localhost,1433;Database=MvcTicariOtomasyon;User Id=sa;Password=Ahsennur#2025;Encrypt=False;TrustServerCertificate=True;";
var optionsBuilder = new DbContextOptionsBuilder<Context>();
optionsBuilder.UseSqlServer(conn);
return new Context(optionsBuilder.Options);
}
}
}