我正在尝试使用 Blazor 的 CRUD 函数并按照一些文章来执行此操作。在文章中,有一部分我应该将我的连接放在上下文文件中,但它没有说明如何设置连接字符串。
我将此代码行放在 launchSettings.json 中:
{
"ConnectionStrings": {
"UserDatabase": "Server=DESKTOP-2K2A6GN;Database=Assignment4;Trusted_Connection=True;"
},
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:56244/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Assignment4.Server": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:56248/"
}
}
}
我尝试将连接字符串添加到上下文文件中,但没有成功。
public class UserContext : DbContext
{
public virtual DbSet<User> tblUser { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer(@"UserDatabase");
}
}
}
弑天下
aluckdog
相关分类