我使用的是 asp net core 2.1 和 EF 6,使用的是 DB第一.我在App.Config.中的连接字符串。
我有这样的错误:在处理请求时发生了一个未处理的异常.InvalidOperationException: 在应用程序配置文件中找不到名为'DataContext'的连接字符串.System.Data.Entity.Internal.LazyInternalConnection.get_ConnectionHasModel()
任何帮助将被感激。
根据内容 APWebDataContext
你提供的,错误的原因是这样的。
public APWebDataContext() : base("name=APWebDataContext") { }
你不需要添加 name
在这里,修改你的APWebDataContext。
修改你的APWebDataContext如下。
public partial class APWebDataContext : DbContext
{
public APWebDataContext() : base("APWebDataContext") { }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet<xxxxxx> x{ get; set;}
}