我不确定我在这里做错了什么,我想使用来自appsettings.json的连接字符串,并使用DI设置我的DbContext以供使用。有一个DbSet,它接受将DbContextOptions传递给base进行初始化。这就是我认为我错了的地方,但是DI应该将选项传递给这个类吗?public class PostContext : DbContext public PostContext(D
通常,我会把大量的参数看作是一个警钟,在某个地方可能会出现设计问题。我正在为ASP.NET应用程序使用一个通用存储库,并拥有一个具有越来越多参数的Controller。public class GenericRepository<T> : IRepository<T> where T : class protected DbContext Context//methods excluded to keep the question readable
我使
问题是,在启动服务时,我似乎无法将我的过滤器注册到DI,因为它找不到数据库连接。可以通过重写DbContext.OnConfiguring方法或在应用程序服务提供程序上使用AddDbContext来配置提供程序。如果使用AddDbContext,那么还要确保DbContext类型在构造函数中接受DbContextOptions对象,并将其传递给DbContext的基本构造函数。; }我的背景
public class Produc
我刚刚开始了一个使用ASP.net 5、MVC6和EntityFramework7的实验项目。我的ASP.Net身份很好,但后来尝试将自己的一些数据添加到DbContext中,并遇到了这个问题。在设置服务时,通过重写OnConfiguring类中的DbContext类或AddDbContext方法来配置数据库提供程序。Products = new ProductRepository(dbContext);
public void Dispose() { dbContext.D
该组件使用内存中的数据存储。但我记不起来了。我不明白如何遵守错误信息中的说明。我遗漏了什么?这是一个错误:
No database provider has been configured for this DbContext.A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContextIf AddDbContext is used, then also ensure that your D