Adding EF initialization
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
using System.Data.Entity;
|
||||
using System.Linq;
|
||||
using LeafWeb.Core.Parsers;
|
||||
using LeafWeb.Core.Utility;
|
||||
|
||||
namespace LeafWeb.Core.DAL
|
||||
{
|
||||
public class LeafWebInitializer : DropCreateDatabaseIfModelChanges<LeafWebContext>
|
||||
{
|
||||
private const string ContentDirectory = @"DAL\InitialData\";
|
||||
|
||||
protected override void Seed(LeafWebContext context)
|
||||
{
|
||||
// get fluxnet sites from file
|
||||
var fileInfo = FileUtility.GetContentFile(ContentDirectory, "fluxnet_site_list_all_October2015_with_joins_corrected.csv");
|
||||
var fluxnetSiteCsvParser = new FluxnetSiteCsvParser(fileInfo);
|
||||
var fluxnetSites = fluxnetSiteCsvParser.Parse().ToList();
|
||||
|
||||
// add to context
|
||||
fluxnetSites.ForEach(s => context.FluxnetSites.Add(s));
|
||||
context.SaveChanges();
|
||||
|
||||
base.Seed(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user