Completely changes way of fetching context

This commit is contained in:
2020-01-22 22:09:07 +01:00
parent f28ea09235
commit cc8eb0302e
5 changed files with 69 additions and 35 deletions

View File

@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using System;
using System.Linq;
namespace EntityFrameworkBasics.Controllers
{
@ -7,6 +8,28 @@ namespace EntityFrameworkBasics.Controllers
{
public IActionResult Index()
{
// No using statement because of the DI and IoC
var context = IoC.ApplicationDbContext;
context.Database.EnsureCreated();
if (!context.Settings.Any())
{
context.Settings.Add(new SettingsDataModel
{
Name = "BackgroundColor",
Value = "Red"
});
var SettingsLocally = context.Settings.Local.Count();
var SettingsDatabase = context.Settings.Count();
var firstLocal = context.Settings.Local.FirstOrDefault();
var firstDatabase = context.Settings.FirstOrDefault();
context.SaveChanges();
}
return View();
}