Get this error when try to query data from dbContext.
public class ApplicationDbContext : DbContext, IDbContext
{
private readonly string connectionString;
public ApplicationDbContext()
: base()
{
this.connectionString =
"Server=(localdb)\\mssqllocaldb;Database=DbContextScopeDemo;Trusted_Connection=True;MultipleActiveResultSets=true";
}
public DbSet<Style> Styles { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(this.connectionString);
}
}
public class GenericRepository<T> : IGenericRepository<T>
where T : BaseEntity
{
private readonly IAmbientDbContextLocator ambientDbContextLocator;
public GenericRepository(IAmbientDbContextLocator ambientDbContextLocator)
{
this.ambientDbContextLocator = ambientDbContextLocator
?? throw new ArgumentNullException(nameof(ambientDbContextLocator));
}
private ApplicationDbContext DbContext
{
get
{
var dbContext = this.ambientDbContextLocator.Get<ApplicationDbContext>();
if (dbContext == null)
throw new InvalidOperationException(
$"No ambient DbContext of type {nameof(ApplicationDbContext)} found.");
dbContext.Database.EnsureCreated();
return dbContext;
}
}
public IQueryable<T> GetAll()
{
return this.DbContext.Set<T>();
}
}
I'm using .net core and ef core.
Problem only with package. Code seems like works fine
Get this error when try to query data from dbContext.
I'm using .net core and ef core.
Problem only with package. Code seems like works fine