我是靠谱客的博主 心灵美路人,这篇文章主要介绍Unable to create an object of type 'DbContext'.For the different patterns supported at design time..,现在分享给大家,希望可以做个参考。
如果在做EFCore migration时碰到类似错误:Unable to create an object of type 'DbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
可尝试以下步骤进行处理:
- 检查是否未实现
EFContext默认构造函数 - 尝试清理解决方案,清除目录下的bin和obj
- 如果还不行,尝试在
DbContext同级目录下添加类DesignTimeDbContextFactory
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<EFContext>
{
public EFContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<EFContext>();
optionsBuilder.UseSqlite($"tmp.db");
return new EFContext(optionsBuilder.Options);
}
}
最后
以上就是心灵美路人最近收集整理的关于Unable to create an object of type 'DbContext'.For the different patterns supported at design time..的全部内容,更多相关Unable内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复