Populating settings table in da created
This commit is contained in:
@ -1,4 +1,6 @@
|
|||||||
namespace EntityFrameworkBasics
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace EntityFrameworkBasics
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Our Settings database table representional model
|
/// Our Settings database table representional model
|
||||||
@ -8,14 +10,19 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The unique Id for this entry
|
/// The unique Id for this entry
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Key]
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The settings name
|
/// The settings name
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[MaxLength(256)]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The settings value
|
/// The settings value
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[MaxLength(2048)]
|
||||||
public string Value { get; set; }
|
public string Value { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,6 +24,26 @@ namespace EntityFrameworkBasics
|
|||||||
using(var context = new ApplicationDBContext())
|
using(var context = new ApplicationDBContext())
|
||||||
{
|
{
|
||||||
context.Database.EnsureCreated();
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
services.AddMvc();
|
services.AddMvc();
|
||||||
|
|||||||
Reference in New Issue
Block a user