DbContextScope
DbContextScope copied to clipboard
DbContextCollection.cs not found
Locating source for 'C:\Users\Adam\Documents\GitHub\apawsey\DbContextScope\EntityFramework.DbContextScope\DbContextCollection.cs'. Checksum: SHA1 {c3 15 50 d6 95 b b7 e7 26 b6 a8 46 7c d8 79 57 2c 55 17 70}
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
I'll have a look at this.