-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathProgram.cs
More file actions
49 lines (42 loc) · 1.17 KB
/
Program.cs
File metadata and controls
49 lines (42 loc) · 1.17 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
using EF;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
var composition = new Composition
{
ServiceProvider = new ServiceCollection()
.AddEntityFrameworkInMemoryDatabase()
.AddDbContext<PersonsDbContext>(options => options.UseInMemoryDatabase("Database of persons"))
.BuildServiceProvider()
};
var root = composition.Root;
await root.RunAsync();
partial class Program(
PersonsDbContext db,
Func<Person> newPerson,
Func<Contact> newContact)
{
private async Task RunAsync()
{
var nik = newPerson() with
{
Name = "Nik",
Contacts =
[
newContact() with { PhoneNumber = "+123456789" }
]
};
db.Persons.Add(nik);
var john = newPerson() with
{
Name = "John",
Contacts =
[
newContact() with { PhoneNumber = "+777333444" },
newContact() with { PhoneNumber = "+999888666" }
]
};
db.Persons.Add(john);
await db.SaveChangesAsync();
await db.Persons.ForEachAsync(Console.WriteLine);
}
}