Add DAL
This commit is contained in:
43
DAL/Helpers/DbInitializer.cs
Normal file
43
DAL/Helpers/DbInitializer.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Data.Entity;
|
||||
using DAL.Domain;
|
||||
|
||||
|
||||
namespace DAL.Helpers
|
||||
{
|
||||
public class DbInitializer : DropCreateDatabaseAlways<FoorumDbContext>
|
||||
{
|
||||
protected override void Seed(FoorumDbContext ctx)
|
||||
{
|
||||
|
||||
var foorum = new Foorum()
|
||||
{
|
||||
Title = "Test Foorum",
|
||||
Author = "Kala",
|
||||
Description = "Lühi kirjeldus",
|
||||
Body = "Siia kirjutame pika teksti",
|
||||
CreationTime = DateTime.Now,
|
||||
Visible = true
|
||||
|
||||
};
|
||||
ctx.Foorums.Add(foorum);
|
||||
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
var post = new Post()
|
||||
{
|
||||
Title = $"Post {i}",
|
||||
Author = "Karu",
|
||||
Body = $"Pikk sisu {i}",
|
||||
CreationTime = DateTime.Now
|
||||
};
|
||||
ctx.Posts.Add(post);
|
||||
foorum.Posts.Add(post);
|
||||
}
|
||||
|
||||
|
||||
ctx.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user