我已經在我的“服務”專案(類別庫)中安裝了 EF 6.4.4。
在我的“WebApp”專案(ASP.NET Core 6.0)中,我想在 Program.cs 中宣告 DbContext。我已經安裝Microsoft.Extensions.DependencyInjection
并添加
using Microsoft.Extensions.DependencyInjection;
到檔案頂部然后
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
builder.Services.AddDbContext<MyDbContext>(options => options.UseSqlServer(connectionString));
無法編譯專案我有以下錯誤:
“IServiceCollection”不包含“AdDbContext”的定義
uj5u.com熱心網友回復:
添加了錯誤的包。EntityFramework 6.4.4是用于 .NET Framework 應用程式的舊 EF 庫,對依賴注入中間件一無所知。
請改用Microsoft.EntityFrameworkCore包。最新的穩定版本是6.0.8
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/506993.html
標籤:C# 。网 asp.net-mvc 实体框架