您好,当我尝试将cmd中的迁移添加到我的网络应用中时出现错误:
“考虑使用IDbContextFactory在设计时覆盖DbContext的初始化。
要解决这个问题,我提到了这个链接:https://docs.microsoft.com/en-us/ef/core/miscellaneous/configuring-dbcontext#using-idbcontextfactorytcontext
所以我添加了一个名为TemporaryDbContextFactory
的工厂using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
namespace _3610Project.Models
{
public class TemporaryDbContextFactory : IDbContextFactory<ProjectContext>
{
public ProjectContext Create()
{
var builder = new DbContextOptionsBuilder<ProjectContext>();
builder.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=pinchdb;Trusted_Connection=True;MultipleActiveResultSets=true");
return new ProjectContext(builder.Options);
}
}
}
但是在TemporaryDBContextFactory中,我收到一条错误消息,说我需要实现接口并建议插入下面的代码而不是原始方法。
我该怎么做才能解决这个问题?