Skip to content

Add settings to the Repository

Patrick edited this page Oct 28, 2016 · 4 revisions

The repository can be populated via a script, database tooling or even the EntityFrameworkCore ConfigurationContext.

To Add Settings Programatically using the ConfigurationContext

Simple AppSetting

using (var context = new ConfigurationContext())
{
    var section = new SectionEntity() { ApplicationName = "Sample", SectionName = "appSettings", Aspect = "settings" };
    context.Sections.Add(section);
    context.SaveChanges();

    var setting = new SettingEntity() { SectionId = section.Id, Key = "TestSetting", Json = @"""Test Value""" };
    context.Settings.Add(setting);
    context.SaveChanges();
}

ComplexType

using (var context = new ConfigurationContext())
{
    var complex = new ComplexType()
    {
        Id = Guid.NewGuid(),
        Name = "ComplexTypeName"
    };

    var section = new SectionEntity() { ApplicationName = "SampleApplication", SectionName = "SampleComplexTypeSection" };
    context.Sections.Add(section);
    context.SaveChanges();

    var setting = new SettingEntity() { SectionId = section.Id, Key = "SampleComplexType" };
    setting.SetValue(complex);

    context.Settings.Add(setting);
    context.SaveChanges();
}
Clone this wiki locally