需要安裝以下套件
Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.Tools
Microsoft.EntityFrameworkCore.Design
指令
Scaffold-DbContext "Server=伺服器位置;Database=資料表;Trusted_Connection=True;User ID=帳號;Password=密碼" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Force
appsettings.json
{
"ConnectionStrings": {
"TodoDatabase": "Server=伺服器位置;Database=資料表;Trusted_Connection=True;UserID=帳號;Password=密碼"
},
}
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<TodoContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("TodoDatabase")));
}
參考文章:
作者已經移除這則留言。
回覆刪除你好 安装数据库得过程中出现了登录不上去服务器得错误 Error Number:18452,State:1,Class:14
回覆刪除登录失败。该登录名来自不受信任的域,不能与 Windows 身份验证一起使用。
麻烦您下 之前有遇到过这种情况吗?