EF EntityFrameworkCore 各版本连接数据库字符串

发布于:2024-12-22 ⋅ 阅读:(12) ⋅ 点赞:(0)

.net core 3.0

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" />

# appsettings.json 文件
"ConnectionStrings": {
    "DefaultConnection": "Server=.;Database=Test;User ID=sa;Password=000000;"
},

.NET 5.0

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.15" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.15" />

# appsettings.json 文件
"ConnectionStrings": {
  "WriteConnection": "Server=.;Database=dbTest;User ID=sa;Password=000000;",
  "ReadConnectionList": [
    "Server=.;Database=dbTestCopy1;User ID=sa;password=000000;",
    "Server=.;Database=dbTestCopy2;User ID=sa;password=000000;",
    "Server=.;Database=dbTestCopy3;User ID=sa;password=000000;"
  ],
  "EFCoreTestToWrite": "Server=.;Database=dbTest;User ID=sa;Password=000000;",
  "EFCoreTestToRead": "Server=.;Database=dbTestCopy1;User ID=sa;Password=000000;,Server=.;Database=dbTestCopy2;User ID=sa;Password=000000;"
}

.NET 6.0

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0" />

# appsettings.json 文件
"ConnectionStrings": {
    "DefaultConnection": "data source=.;initial catalog=Test;user id=sa;password=000000;Encrypt=True;TrustServerCertificate=True;"
    "DefaultConnection": "data source=.;initial catalog=Test;user id=sa;password=000000;TrustServerCertificate=true;"
}

.NET 8.0

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />

"ConnectionStrings": {
    "DefaultConnection": "data source=.;initial catalog=Test;user id=sa;password=000000;TrustServerCertificate=true;"
}

MySQL

# appsettings.json 文件
"ConnectionStrings": {
  "MySqlConnection": "Data Source=localhost;port=3306;Initial Catalog=dbTest;user id=root;password=123456;CharSet=utf8;"
}

*
*
*


网站公告

今日签到

点亮在社区的每一天
去签到