-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathProgram.cs
126 lines (115 loc) · 4.77 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright (c) SimpleIdServer. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
using Cassandra;
using EFCore.Cassandra.Samples.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using System.Net;
using System.Threading.Tasks;
namespace EFCore.Cassandra.Samples
{
class Program
{
private static Guid ApplicantPartitionId = Guid.Parse("be2106c5-791f-45d2-890a-50fc221f96e8");
private static Guid ApplicantId = Guid.Parse("09e0f68e-8818-452a-9a47-3c8ca2c941c8");
static async Task Main(string[] args)
{
using (var dbContext = new FakeDbContext())
{
dbContext.Database.Migrate();
Console.WriteLine("Bulk insert");
var applicants = Enumerable.Repeat(1, 1).Select(_ => BuildApplicant()).ToList();
dbContext.BulkInsert(applicants);
Console.WriteLine("Add applicant");
var timeUuid = TimeUuid.NewId();
var app = BuildApplicant();
dbContext.Applicants.Add(app);
dbContext.SaveChanges();
Console.WriteLine("Applicant is added");
var appls = dbContext.Applicants.ToList();
Console.WriteLine($"Number of applicants '{dbContext.Applicants.LongCount()}'");
Console.WriteLine("Get applicants by partition key");
var filteredApplicants = dbContext.Applicants.Where(_ => _.Id == ApplicantPartitionId, false).ToList();
Console.WriteLine($"Number of applicants '{filteredApplicants.Count}'");
Console.WriteLine("Get applicants (ALLOW FILTERING)");
var allowedFilteredApplicants = dbContext.Applicants.Where(_ => _.LastName == "lastname", true).ToList();
Console.WriteLine($"Number of applicants {allowedFilteredApplicants.Count}");
Console.WriteLine("Order applicants by 'order'");
var orderedApplicants = dbContext.Applicants.Where(_ => _.Id == ApplicantPartitionId)
.OrderBy(_ => _.Order).ToList();
Console.WriteLine($"Number of applicants {orderedApplicants.Count}");
Console.WriteLine("Update the applicant");
var applicant = dbContext.Applicants.First();
applicant = dbContext.Applicants.First();
applicant.Decimal = 10;
applicant.Dic = new Dictionary<string, string>
{
{ "toto", "toto" }
};
dbContext.SaveChanges();
Console.WriteLine("Applicant is updated");
Console.WriteLine("Remove the applicant");
applicant = dbContext.Applicants.First();
dbContext.Applicants.Remove(applicant);
dbContext.SaveChanges();
Console.WriteLine("Applicant is removed");
Console.WriteLine($"Number of applicants '{dbContext.Applicants.LongCount()}'");
Console.ReadLine();
}
}
private static Applicant BuildApplicant()
{
var timeUuid = TimeUuid.NewId();
return new Applicant
{
Id = ApplicantPartitionId,
ApplicantId = ApplicantId,
Order = 0,
Lst = new List<string>
{
"1",
"2"
},
LstInt = new List<int>
{
1, 2, 3
},
Dic = new Dictionary<string, string>
{
{ "coucou", "coucou" }
},
LastName = "lastname",
BigInteger = 10,
Bool = false,
Decimal = 1,
Double = 2,
Integer = 3,
Float = 4,
Sbyte = 0,
TimeUuid = timeUuid,
DateTimeOffset = DateTimeOffset.Now,
Long = 22,
SmallInt = 11,
Blob = new byte[] { 1, 2 },
LocalDate = new LocalDate(2019, 10, 2),
Ip = IPAddress.Loopback,
LocalTime = new LocalTime(2, 3, 4, 5),
Address = new ApplicantAddress
{
City = "Brussels",
StreetNumber = 100
},
Phones = new ApplicantPhone[]
{
new ApplicantPhone
{
IsMobile = true,
PhoneNumber = "phone"
}
}
};
}
}
}