- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
Latest commit
44 lines (34 loc) · 1.39 KB
/
Copy pathProgram.cs
File metadata and controls
44 lines (34 loc) · 1.39 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
// See https://aka.ms/new-console-template for more information
usingMicrosoft.Extensions.DependencyInjection;
usingmyNOC.EntityFramework.Query.Extensions;
usingQuerySample.Data;
usingQuerySample.Entities;
usingQuerySample.Queries;
awaitSeedSampleData();
IServiceCollectionservices=newServiceCollection();
services.AddQueryPattern();
varprovider=services.BuildServiceProvider();
varqueryRepo=provider.GetRequiredService<IAddressBookContextRepository>();
varresult=awaitqueryRepo.Query(newContactGetAll());
DisplayResults("Return All Contacts",result);
Console.WriteLine();
result=awaitqueryRepo.Query(newContactNameContains("a"));
DisplayResults("Contacts Where Name Contain 'a'",result);
Console.WriteLine();
varid=awaitqueryRepo.Query(newContactGetIdByName("Bob"));
Console.WriteLine($"Bob's Id is: {id}");
staticasyncTaskSeedSampleData()
{
varaddressBook=newAddressBookDbContext();
addressBook.Add(newContactEntity{Id=1,Name="Abby"});
addressBook.Add(newContactEntity{Id=2,Name="Bob"});
addressBook.Add(newContactEntity{Id=3,Name="Charlie"});
addressBook.Add(newContactEntity{Id=4,Name="David"});
awaitaddressBook.SaveChangesAsync();
}
staticvoidDisplayResults(stringtitle,IEnumerable<QuerySample.Models.ContactModel>result)
{
Console.WriteLine(title);
foreach(variteminresult)
Console.WriteLine(item.DisplayName);
}