-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
97 lines (69 loc) · 2.02 KB
/
Copy pathProgram.cs
File metadata and controls
97 lines (69 loc) · 2.02 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ServiceModels.Entities;
using ServiceStack.OrmLite;
using ServiceStack.Text;
using UnitTests;
namespace ConsoleUtils
{
class Program
{
static void Main(string[] args)
{
new Setup().Db();
"Db created".Print();
}
}
class Setup
{
IDbConnection _db;
public void Db()
{
var connectionString = ConfigurationManager.ConnectionStrings["DiffStack"].ConnectionString;
var dbFactory = new OrmLiteConnectionFactory(
connectionString,
SqlServerDialect.Provider
);
using (_db = dbFactory.OpenDbConnection())
{
setupTables();
seed();
print();
}
}
private void setupTables()
{
"drop/create tables...".Print();
_db.DropTables(typeof(Product), typeof(Brand));
_db.CreateTable<Brand>();
_db.CreateTable<Product>();
}
private void seed()
{
"seeding...".Print();
3.Times(i => _db.Insert<Brand>(new Brand { Name = "Brand " + (i + 1) }));
30.Times(i => _db.Insert<Product>(
new Product
{
Name = "Product " + (i + 1),
InternalInfo = "secret biz stuff for product " + (i + 1),
BrandId = (i % 3)+1
}
));
}
void print()
{
//_db.First<Brand>(p => p.Id == 1).PrintDump();
//var product1 = _db.First<Product>(p => p.Id == 1);
//product1.PrintDump();
//product1.Brand.PrintDump();
_db.Select<Brand>().PrintDump();
_db.Select<Product>().PrintDump();
}
}
}