Skip to content

Commit 402ac0d

Browse files
Ticket #10 : Create keyspace
1 parent da4cfd5 commit 402ac0d

11 files changed

Lines changed: 192 additions & 11 deletions

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<VersionPrefix>2.0.2</VersionPrefix>
3+
<VersionPrefix>2.0.3</VersionPrefix>
44
<Authors>SimpleIdServer</Authors>
55
<Owners>SimpleIdServer</Owners>
66
</PropertyGroup>

EFCore.Cassandra.sln

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.27130.0
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30406.217
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "01. Core Layer", "01. Core Layer", "{4920F8DE-E217-452A-865A-E47DAC924B5F}"
77
EndProject
@@ -20,6 +20,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.Cassandra.Tests", "t
2020
EndProject
2121
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.Cassandra.Samples", "samples\EFCore.Cassandra.Samples\EFCore.Cassandra.Samples.csproj", "{84CB9B7A-BDCF-4AF6-8C02-80405EB54C93}"
2222
EndProject
23+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "04. Benchmarks", "04. Benchmarks", "{46930201-AD6E-448E-B8D7-95B26ABD9BB6}"
24+
EndProject
25+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.Cassandra.Benchmarks", "src\EFCore.Cassandra.Benchmarks\EFCore.Cassandra.Benchmarks.csproj", "{BBB1B39C-42FF-43AD-AF77-33B0018FD0E6}"
26+
EndProject
2327
Global
2428
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2529
Debug|Any CPU = Debug|Any CPU
@@ -38,6 +42,10 @@ Global
3842
{84CB9B7A-BDCF-4AF6-8C02-80405EB54C93}.Debug|Any CPU.Build.0 = Debug|Any CPU
3943
{84CB9B7A-BDCF-4AF6-8C02-80405EB54C93}.Release|Any CPU.ActiveCfg = Release|Any CPU
4044
{84CB9B7A-BDCF-4AF6-8C02-80405EB54C93}.Release|Any CPU.Build.0 = Release|Any CPU
45+
{BBB1B39C-42FF-43AD-AF77-33B0018FD0E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
46+
{BBB1B39C-42FF-43AD-AF77-33B0018FD0E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
47+
{BBB1B39C-42FF-43AD-AF77-33B0018FD0E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
48+
{BBB1B39C-42FF-43AD-AF77-33B0018FD0E6}.Release|Any CPU.Build.0 = Release|Any CPU
4149
EndGlobalSection
4250
GlobalSection(SolutionProperties) = preSolution
4351
HideSolutionNode = FALSE
@@ -46,6 +54,7 @@ Global
4654
{2D74D363-66B9-424B-BB34-468BEF0A2F07} = {4920F8DE-E217-452A-865A-E47DAC924B5F}
4755
{BE0A2541-1253-4917-A070-4BB8F71F4704} = {BCAC9560-F9EC-4C11-A0E2-D3CAC0759519}
4856
{84CB9B7A-BDCF-4AF6-8C02-80405EB54C93} = {D43C01D1-8661-4A06-B3D8-5CD1A9AC1DB3}
57+
{BBB1B39C-42FF-43AD-AF77-33B0018FD0E6} = {46930201-AD6E-448E-B8D7-95B26ABD9BB6}
4958
EndGlobalSection
5059
GlobalSection(ExtensibilityGlobals) = postSolution
5160
SolutionGuid = {13BDB38B-AFCC-4B2C-B0F9-404FB6249216}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<OutputType>Exe</OutputType>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\EFCore.Cassandra\EFCore.Cassandra.csproj" />
13+
</ItemGroup>
14+
</Project>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) SimpleIdServer. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
using EFCore.Cassandra.Benchmarks.Models;
4+
using Microsoft.EntityFrameworkCore;
5+
using Microsoft.EntityFrameworkCore.Cassandra.Storage;
6+
using Microsoft.EntityFrameworkCore.Migrations;
7+
8+
namespace EFCore.Cassandra.Benchmarks
9+
{
10+
public class FakeDbContext : DbContext
11+
{
12+
public DbSet<Applicant> Applicants { get; set; }
13+
14+
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
15+
{
16+
optionsBuilder.UseCassandra("Contact Points=127.0.0.1;", opt =>
17+
{
18+
opt.MigrationsHistoryTable(HistoryRepository.DefaultTableName, "cv");
19+
});
20+
}
21+
22+
protected override void OnModelCreating(ModelBuilder modelBuilder)
23+
{
24+
var timeUuidConverter = new TimeUuidToGuidConverter();
25+
modelBuilder.ForCassandraAddKeyspace("cv", new KeyspaceReplicationSimpleStrategyClass(2));
26+
modelBuilder.Entity<Applicant>()
27+
.ToTable("applicants", "cv")
28+
.HasKey(p => new { p.Id, p.Order });
29+
modelBuilder.Entity<Applicant>()
30+
.ForCassandraSetClusterColumns(_ => _.Order)
31+
.ForCassandraSetClusteringOrderBy(new[] { new CassandraClusteringOrderByOption("Order", CassandraClusteringOrderByOptions.ASC) });
32+
modelBuilder.Entity<Applicant>()
33+
.Property(p => p.TimeUuid)
34+
.HasConversion(new TimeUuidToGuidConverter());
35+
modelBuilder.Entity<Applicant>()
36+
.Property(p => p.Id)
37+
.HasColumnName("id");
38+
modelBuilder.Entity<ApplicantAddress>()
39+
.ToUserDefinedType("applicant_addr", "cv")
40+
.HasNoKey();
41+
}
42+
}
43+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright (c) SimpleIdServer. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
using BenchmarkDotNet.Attributes;
4+
using EFCore.Cassandra.Benchmarks.Models;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
9+
namespace EFCore.Cassandra.Benchmarks
10+
{
11+
public class InsertData : IDisposable
12+
{
13+
private readonly FakeDbContext _dbContext;
14+
private readonly Applicant[] _applicants;
15+
16+
public InsertData()
17+
{
18+
_dbContext = new FakeDbContext();
19+
_applicants = Enumerable.Range(1, 5).Select(_ => BuildApplicant()).ToArray();
20+
}
21+
22+
public void Dispose()
23+
{
24+
_dbContext.Dispose();
25+
}
26+
27+
[Benchmark]
28+
public void Add100Applicants()
29+
{
30+
foreach (var applicant in _applicants)
31+
{
32+
_dbContext.Applicants.Add(applicant);
33+
}
34+
35+
_dbContext.SaveChanges();
36+
}
37+
38+
[Benchmark]
39+
public void AddRange100Applicants()
40+
{
41+
_dbContext.Applicants.AddRange(_applicants);
42+
_dbContext.SaveChanges();
43+
}
44+
45+
private static Applicant BuildApplicant()
46+
{
47+
return new Applicant
48+
{
49+
Id = Guid.NewGuid(),
50+
Order = 0,
51+
Dic = new Dictionary<string, string>(),
52+
Lst = new List<string>(),
53+
LstInt = new List<int>()
54+
};
55+
}
56+
}
57+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) SimpleIdServer. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
using Cassandra;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Net;
7+
using System.Numerics;
8+
9+
namespace EFCore.Cassandra.Benchmarks.Models
10+
{
11+
public class Applicant
12+
{
13+
public Guid Id { get; set; }
14+
public int Order { get; set; }
15+
public Guid ApplicantId { get; set; }
16+
public string LastName { get; set; }
17+
public long Long { get; set; }
18+
public bool Bool { get; set; }
19+
public decimal Decimal { get; set; }
20+
public double Double { get; set; }
21+
public float Float { get; set; }
22+
public int Integer { get; set; }
23+
public short SmallInt { get; set; }
24+
public DateTimeOffset DateTimeOffset { get; set; }
25+
public TimeUuid TimeUuid { get; set; }
26+
public sbyte Sbyte { get; set; }
27+
public BigInteger BigInteger { get; set; }
28+
public byte[] Blob { get; set; }
29+
public LocalDate LocalDate { get; set; }
30+
public IPAddress Ip { get; set; }
31+
public LocalTime LocalTime { get; set; }
32+
public IList<string> Lst { get; set; }
33+
public IList<int> LstInt { get; set; }
34+
public IDictionary<string, string> Dic { get; set; }
35+
public ApplicantAddress Address { get; set; }
36+
}
37+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+

2+
namespace EFCore.Cassandra.Benchmarks.Models
3+
{
4+
public class ApplicantAddress
5+
{
6+
public int StreetNumber { get; set; }
7+
public string City { get; set; }
8+
}
9+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) SimpleIdServer. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
using BenchmarkDotNet.Running;
4+
using System.Threading.Tasks;
5+
6+
namespace EFCore.Cassandra.Benchmarks
7+
{
8+
internal class Program
9+
{
10+
private static async Task Main(string[] args)
11+
{
12+
BenchmarkRunner.Run<InsertData>();
13+
}
14+
}
15+
}

src/EFCore.Cassandra/Migrations/CassandraHistoryRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Newtonsoft.Json;
1212
using System;
1313
using System.Collections.Generic;
14+
using System.Diagnostics;
1415
using System.Linq;
1516
using System.Text;
1617
using System.Threading;

src/EFCore.Cassandra/Migrations/CassandraMigrationsSqlGenerator.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,17 +285,12 @@ private class MigrationOpComparer : IComparer<MigrationOperation>
285285
{
286286
public int Compare(MigrationOperation x, MigrationOperation y)
287287
{
288-
if (x is CreateUserDefinedTypeOperation)
288+
if (y is CreateUserDefinedTypeOperation || y is EnsureSchemaOperation)
289289
{
290-
return -1;
290+
return 1;
291291
}
292292

293-
if (y is CreateUserDefinedTypeOperation)
294-
{
295-
return -1;
296-
}
297-
298-
return 1;
293+
return -1;
299294
}
300295
}
301296
}

0 commit comments

Comments
 (0)