Professional Documents
Culture Documents
WEB: chỉnh cổng chạy yêu cầu trong properties => launchSettings
3.On Developer PowerShell dialog , execute the following commands to generate model:
-appsettings.json
{
"ConnectionStrings": {
"PE_Fall21B5DB":
"Server=(local);uid=sa;pwd=123;database=PE_Fall21B5;Trusted_Connection=True;TrustServerCertificate=True"
}
}
-Dbcontext.cs
Trường hợp bạn khai thác dữ liệu từ database bằng EF (Entity Framework)
Microsoft.entityframeworkcore.design(6.0.1)
Microsoft.entityframeworkcore.sqlserver(6.0.1)
Microsoft.extensions.configuration.json(6.0.0)
System.data.sqlclient(4.8.3)
Với ASP.NET Core Web App ( Nó có sẵn thư viện json rồi ) :
Trường hợp bạn khai thác dữ liệu từ database bằng EF (Entity Framework)
Microsoft.entityframeworkcore.design(6.0.1)
Microsoft.entityframeworkcore.sqlserver(6.0.1)
Đoạn code đọc file json trong hàm onconfig: ( với Entity Framework nhớ thay vào
hàm đc dạy trong class có đuôi Context.cs )
{
"ConnectionStrings": {
"MyCnn": "server=localhost;database=MyDB2;uid=sa;pwd=123"
}
}
{
"ConnectionStrings": {
"MyCnn":"server=(local);database=MySaleDB;uid=sa;pwd=123;TrustServerCertificate=true"
}
}