-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprogram.cs
54 lines (53 loc) · 1.2 KB
/
program.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
46
47
48
49
50
51
52
53
54
using System;
using System.IO;
using System.Linq;
using Databases.Models;
namespace Databases
{
class Program
{
static void Main(string[] args)
{
string dbName = "TestDatabase.db";
if (File.Exists(dbName))
{
File.Delete(dbName);
}
using (var dbContext = new MyDbContext())
{
// Ensure database is created
dbContext.Database.EnsureCreated();
if (!dbContext.Products.Any())
{
// Create a products array and add to it via a for loop
dbContext.Products.AddRange(new Product[] {
new Product
{
id = 1,
title = "Product 1",
sub_title = "Product 2 subtitle"
},
new Product
{
id = 2,
title = "Product 2",
sub_title = "Product 2 subtitle"
},
new Product
{
id = 3,
title = "Product 3",
sub_title = "Product 2 subtitle"
}
});
dbContext.SaveChanges();
}
foreach (var product in dbContext.Products)
{
System.Console.WriteLine($"Product ID = {product.id}\tTitle={product.title}\t{product.sub_title}\tDate added={product.created_at}");
}
}
Console.ReadLine();
}
}
}