hask
June 29, 2022, 12:26am
1
νμ κ°λ° νκ²½μ .NetFramework4.8 κΉμ§ μμ
μ ν΄μ€κ³ μμμ΅λλ€.
μ
λ°μ΄νΈκ° λκΈ΄κ²λ κ·Έλ κ³ λ¨Έλ¬Όλ¬ μκΈ° λͺ¨νΈν λ§μμ
.Net6.0μΌλ‘ νκ²½ λ³κ²½νμ¬ μ²μ μ ν΄λ³΄κ³ μλλ°μ,
Code-Firstμμ£Όλ‘ μμ
νμμ΅λλ€.
DB Seedν λ
.NetFramework4.8 μμλ App.config νμΌμ΄ μ루μ
μμ±μ μλμΌλ‘ μμ± λμμμ΅λλ€.
νλ° .Net6.0μλ μλλΌκ΅¬μβ¦?
μ΄λ¬ν ConnectionString μ²λ¦¬λ₯Ό(?) Seedμ²λ¦¬λ₯Ό νκΈ° μν΄μλβ¦?
.Net6.0μμλ μ΄λ»κ² μ²λ¦¬νλκ±ΈκΉμ??
dimohy
June 29, 2022, 1:13am
2
μ°μ EF Coreμ Data Seeding λ¬Έμλ₯Ό μ΄ν΄λ³΄μκΈ° λ°λλλ€.
App.configλ .NET 6μμλ λμΌνκ² μ¬μ© κ°λ₯ν©λλ€.
μλμ λ§ν¬λ₯Ό μ°Έκ³ νμΈμ.
2 Likes
nyjin
June 29, 2022, 1:34am
3
νΉμ app.configμ κ°μ μ€μ νμΌμ .net core νκ²½μμλ μ΄λ»κ² μ¬μ©νλμ§λ₯Ό μ¬μ€ 보μλκ±°λΌλ©΄
μλ λ§ν¬λ₯Ό μ°Έμ‘°ν΄ λ³΄μλ κ²λ μ’μ κ² κ°μμ.
νμΌ μΆκ°
appsettings.json νμΌ μΆκ° + Copy to Output Directory μμ±μ Copy if newerλ‘ λ³κ²½
ν¨ν€μ§ μΆκ°
dotnet add package Microsoft.Extensions.Configuration
dotnet add package Microsoft.Extensions.Configuration.Json
μμ
class Program
{
static void Main(string[] args)
{
var builder = new ConfigurationBuilder()
.AddJsonFile($"appsettings.json", true, true);
var config = builder.Build();
var connectionString = config["ConnectionString"];
var emailHost = config["Smtp:Host"];
Console.WriteLine($"Connection String is: {connectionString}");
Console.WriteLine($"Email Host is: {emailHost}");
Console.ReadLine();
}
}
μμ λ μΈλ±μ€λ‘ μ κ·Όνλλ°μ.
GetConnectionString μμ±μ΄ μμκΊΌμμ.
http://www.techtutorhub.com/article/how-to-read-appsettings-json-configuration-file-in-dot-net-core-console-application/83
2 Likes