Hi All!
I want to create background task with database access. I'll start my thread in Startup.cs in Configure method.
with code:
// create new database instance var contextOptions = new DbContextOptionsBuilder<Data.ApplicationDbContext>().UseSqlServer(Configuration.GetConnectionString("DefaultConnection")); using (var context = new Data.ApplicationDbContext(contextOptions.Options)) { var mydata = context.Where(...); //.. work with mydata... await context.SaveChangesAsync(); }
And got NullReference Exception when call SaveChangesAsync(), whats wrong?