-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnote.txt
34 lines (31 loc) · 1.22 KB
/
note.txt
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
33
34
1/ Set web-project is the start-up project
2/ Add class "temp create db context factory" in web project:
example:
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebBlog.Database.Data;
namespace WebBlog.Api
{
public class IdentityTempDbContextFactory : IDesignTimeDbContextFactory<ApplicationDbContext>
{
////////
public ApplicationDbContext CreateDbContext(string[] args)
{
var builder = new DbContextOptionsBuilder<ApplicationDbContext>();
IConfigurationRoot configuration = new ConfigurationBuilder()
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
.AddJsonFile("appsettings.json")
.Build();
builder.UseSqlServer(configuration.GetConnectionString("WebBlogIdentityDBConnection"));
return new ApplicationDbContext(builder.Options);
}
}
}
3/Copy appsettings.json to /bin/debug
4/ Run PowerShell command line: Add-Migration NameMigration -C DatabaseContextName
5/ Run PowerShell command line: Update-Database -C DatabaseContextName