Completely changes way of fetching context
This commit is contained in:
@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user