public Startup(IConfiguration configuration) { Configuration = configuration; using (var client = new TemperDbContext()) { client.Database.EnsureCreated(); } }
private void DoWork(object state) { var temperature = TemperReader.GetTemperature(); if (temperature.Temperature.HasValue) { using (var db = new TemperDbContext()) { db.MesureValues.Add(new MesureValue() { MesuareDateTime = DateTime.Now, Temperature = temperature.Temperature.Value }); db.SaveChanges(); _logger.LogInformation("Timed Hosted Service is working. Temperature: {temperature}", temperature.StringifiedResult); } } else { _logger.LogInformation("Timed Hosted Service failed.Error: {temperature}", temperature.StringifiedResult); } }