Created
September 8, 2018 23:03
-
-
Save mehmetalierol/1c7f4680e9bc77481c077a9e234e0cff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.EntityFrameworkCore; | |
using Microsoft.EntityFrameworkCore.Design; | |
using Microsoft.Extensions.Configuration; | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Text; | |
namespace Company.Application.Data.Context | |
{ | |
class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<ApplicationDbContext> | |
{ | |
public ApplicationDbContext CreateDbContext(string[] args) | |
{ | |
IConfigurationRoot configuration = new ConfigurationBuilder() | |
.SetBasePath(Directory.GetCurrentDirectory()) | |
.AddJsonFile("appsettings.json") | |
.Build(); | |
var builder = new DbContextOptionsBuilder<ApplicationDbContext>(); | |
var connectionString = configuration.GetConnectionString("DefaultConnection"); | |
builder.UseSqlServer(connectionString); | |
return new ApplicationDbContext(builder.Options); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment