使用entity framework core時報如標題錯誤。
在startup.cs文件中配置服務
public void ConfigureServices(IServiceCollection services) { services.AddControllers(); //注冊數據庫上下文 services.AddEntityFrameworkSqlServer().AddDbContext<SQLDbRWContext>(options => { options.UseSqlServer(Configuration.GetConnectionString("Main_ReadAndWrite")); }); }
解決方案
1、首先檢查項目添加了Microsoft.EntityFrameworkCore和Microsoft.EntityFrameworkCore.SqlServer引用
2、需要手動在startup.cs中添加引用,不然無法識別擴展方法。
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.SqlServer;
唉,有點坑。