I have ASP.Net Core 2.1
application & using EF Core 2.1
as DAL
This is my how DAL service method looks.
public async Task<bool> UpdateChannels(IEnumerable<Channels> subscriptions)
{
try
{
//here Context(MyReosiptory =DbContext) no issue
var zoneChannels = await Context.Channnels.Where(x => x.isActive == true).ToListAsync();
await Context.Channels.AddRangeAsync(subscriptions);
//but at this line it throws the error.
await Context.SaveChangesAsync();
return true;
}
catch (Exception ex)
{
throw new Exception(ex.Message ?? ex.InnerException.Message);
}
}
However, if I move the other Db Operation (add) in separate method, it runs.
But I have one more Db operation in the same method, & cannot move each Db related operation to separate method.
services.AddScoped<IMyRepository, MyRepository>();
Injecting the Dependency via Constructor.
Checked the below link.
Cannot access a disposed object in ASP.NET Core when injecting DbContext
But neither the Seed() is coming up nor do I understand why I should have Seed() & how it is related to disposed object.