-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreate-Test-Project.ps1
More file actions
80 lines (62 loc) · 1.85 KB
/
Create-Test-Project.ps1
File metadata and controls
80 lines (62 loc) · 1.85 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
dotnet new console -o Sample.Ef | Out-Null
Set-Location .\Sample.Ef
dotnet add package Microsoft.EntityFrameworkCore.Sqlite
dotnet add package Microsoft.EntityFrameworkCore.Design
$personClass = @"
namespace Sample.Ef.Models
{
public class Person
{
public int Id { get; set; }
}
}
"@
New-Item -Path . -Name "Models" -ItemType "directory"
New-Item -Path "Models" -ItemType "file" -Name "Person.cs" -Value $personClass
$dbContexClass = @"
using Microsoft.EntityFrameworkCore;
namespace Sample.Ef.Models
{
public class PeopleContext : DbContext
{
public DbSet<Person> Persons { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Data Source=people.db");
}
}
}
"@
New-Item -Path "Models" -ItemType "file" -Name "PeopleContext.cs" -Value $dbContexClass
dotnet ef migrations add InitialCreate | Out-Null
dotnet ef database update | Out-Null
$contactClass = @"
namespace Sample.Ef.Models
{
public class Contact
{
public int Id { get; set; }
public int PersonId { get; set; }
public Person Person { get; set; }
}
}
"@
New-Item -Path "Models" -ItemType "file" -Name "Contact.cs" -Value $contactClass
$dbContexClass = @"
using Microsoft.EntityFrameworkCore;
namespace Sample.Ef.Models
{
public class PeopleContext : DbContext
{
public DbSet<Person> Persons { get; set; }
public DbSet<Contact> Contacts { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Data Source=people.db");
}
}
}
"@
New-Item -Force -Path "Models" -ItemType "file" -Name "PeopleContext.cs" -Value $dbContexClass
dotnet ef migrations add AddContactEntity | Out-Null
dotnet ef database update | Out-Null