-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataInitializer.cs
45 lines (39 loc) · 1.46 KB
/
DataInitializer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFramework_ST
{
public class DataInitializer : DropCreateDatabaseIfModelChanges<UrunContext>
{
protected override void Seed(UrunContext context)
{
List<Product> urunler = new List<Product>()
{
new Product() {ProductName = "Samsung S5",Fiyat = 1200, StokAdeti = 23},
new Product() {ProductName = "Samsung S7",Fiyat=1430,StokAdeti = 41},
new Product() {ProductName = "Iphone X", Fiyat = 8000,StokAdeti=43},
new Product() {ProductName = "Samsung S20",Fiyat=9230,StokAdeti = 41},
new Product() {ProductName = "Iphone 8", Fiyat = 6000,StokAdeti=43}
};
List<Category> categories = new List<Category>()
{
new Category() {CategoryName = "Elektronik"},
new Category() {CategoryName = "Ev aleti"},
new Category() {CategoryName = "Mobilya"}
};
foreach (var urun in urunler)
{
context.Urunler.Add(urun);
}
foreach (var kategori in categories)
{
context.Kategoriler.Add(kategori);
}
context.SaveChanges();
base.Seed(context);
}
}
}