Skip to content

Commit 54f2d7e

Browse files
author
Henk Kin
committed
Refactored to version 1.0.1
1 parent 8c4b4d8 commit 54f2d7e

10 files changed

+39
-24
lines changed

.bettercodehub.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
component_depth: 2
2+
languages:
3+
- csharp

Identifiers.EntityFrameworkCore.SqlServer.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ VisualStudioVersion = 16.0.29324.140
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Identifiers.EntityFrameworkCore.SqlServer", "Identifiers.EntityFrameworkCore.SqlServer\Identifiers.EntityFrameworkCore.SqlServer.csproj", "{90E30D11-B814-47C4-BA3B-EB1E963A43EA}"
77
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3750EA4C-3861-4ED4-B0AD-F872D2AA550B}"
9+
ProjectSection(SolutionItems) = preProject
10+
.bettercodehub.yml = .bettercodehub.yml
11+
appveyor.yml = appveyor.yml
12+
README.md = README.md
13+
EndProjectSection
14+
EndProject
815
Global
916
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1017
Debug|Any CPU = Debug|Any CPU

Identifiers.EntityFrameworkCore.SqlServer/IdentifierMigrationsAnnotationProvider.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Identifiers.EntityFrameworkCore.SqlServer
88
{
9-
public class IdentifierMigrationsAnnotationProvider : MigrationsAnnotationProvider
9+
internal class IdentifierMigrationsAnnotationProvider : MigrationsAnnotationProvider
1010
{
1111
public IdentifierMigrationsAnnotationProvider(MigrationsAnnotationProviderDependencies dependencies)
1212
: base(dependencies)
@@ -20,7 +20,7 @@ public override IEnumerable<IAnnotation> For(IProperty property)
2020
var annotation = property.FindAnnotation("Identifier");
2121
return annotation == null
2222
? baseAnnotations
23-
: baseAnnotations.Concat(new[] { new Annotation("SqlServer:ValueGenerationStrategy", annotation.Value) });
23+
: baseAnnotations.Concat(new[] { new Annotation("SqlServer:ValueGenerationStrategy", annotation.Value) });
2424
}
2525
}
26-
}
26+
}

Identifiers.EntityFrameworkCore.SqlServer/IdentifierPropertyBuilderExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
namespace Identifiers.EntityFrameworkCore.SqlServer
66
{
77
public static class IdentifierPropertyBuilderExtensions
8-
{
8+
{
99
public static PropertyBuilder<Identifier> IdentifierValueGeneratedOnAdd(this PropertyBuilder<Identifier> propertyBuilder)
1010
{
1111
propertyBuilder = propertyBuilder
1212
.ValueGeneratedOnAdd()
1313
.HasAnnotation("Identifier", SqlServerValueGenerationStrategy.IdentityColumn);
1414

1515
propertyBuilder.Metadata.SetBeforeSaveBehavior(PropertySaveBehavior.Ignore);
16+
1617
return propertyBuilder;
1718
}
1819
}
19-
}
20+
}

Identifiers.EntityFrameworkCore.SqlServer/IdentifierSqlServerDbContextOptionsExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ namespace Identifiers.EntityFrameworkCore.SqlServer
77
{
88
public static class IdentifierSqlServerDbContextOptionsExtensions
99
{
10-
public static DbContextOptionsBuilder UseIdentifiers<TDatabaseClrType>(this DbContextOptionsBuilder optionsBuilder) where TDatabaseClrType : IConvertible
10+
public static DbContextOptionsBuilder UseIdentifiers<TDatabaseClrType>(this DbContextOptionsBuilder optionsBuilder)
1111
{
1212
optionsBuilder.ReplaceService<IMigrationsAnnotationProvider, IdentifierMigrationsAnnotationProvider>();
1313
optionsBuilder.ReplaceService<IValueConverterSelector, IdentifierValueConverterSelector<TDatabaseClrType>>();
1414

1515
return optionsBuilder;
1616
}
1717
}
18-
}
18+
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
using System;
2-
using Identifiers.TypeConverters;
32
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
43

54
namespace Identifiers.EntityFrameworkCore.SqlServer
65
{
7-
public class IdentifierValueConverter<TDatabaseClrType> : ValueConverter<Identifier, TDatabaseClrType> where TDatabaseClrType : IConvertible
6+
internal class IdentifierValueConverter<TDatabaseClrType> : ValueConverter<Identifier, TDatabaseClrType>
87
{
98
public IdentifierValueConverter(ConverterMappingHints mappingHints = null)
109
: base(
11-
id => IdentifierTypeConverter.FromIdentifier<TDatabaseClrType>(id),
12-
value => IdentifierTypeConverter.ToIdentifier<TDatabaseClrType>(value),
13-
new ConverterMappingHints(valueGeneratorFactory: (p, t) => new IdentifierValueGenerator<TDatabaseClrType>())
10+
id => (TDatabaseClrType)Convert.ChangeType(id.GetValue(), typeof(TDatabaseClrType)),
11+
value => new Identifier(value),
12+
new ConverterMappingHints(valueGeneratorFactory: (p, t) => new IdentifierValueGenerator<TDatabaseClrType>())
1413
)
1514
{ }
1615
}
17-
}
16+
}

Identifiers.EntityFrameworkCore.SqlServer/IdentifierValueConverterSelector.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55

66
namespace Identifiers.EntityFrameworkCore.SqlServer
77
{
8-
/// <summary>
9-
/// Thanks to https://andrewlock.net/strongly-typed-ids-in-ef-core-using-strongly-typed-entity-ids-to-avoid-primitive-obsession-part-4/
10-
/// </summary>
11-
/// <typeparam name="TDatabaseClrType"></typeparam>
12-
public class IdentifierValueConverterSelector<TDatabaseClrType> : ValueConverterSelector where TDatabaseClrType : IConvertible
8+
internal class IdentifierValueConverterSelector<TDatabaseClrType> : ValueConverterSelector
139
{
1410
// The dictionary in the base type is private, so we need our own one here.
1511
private readonly ConcurrentDictionary<(Type ModelClrType, Type ProviderClrType), ValueConverterInfo> _converters

Identifiers.EntityFrameworkCore.SqlServer/IdentifierValueGenerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
namespace Identifiers.EntityFrameworkCore.SqlServer
77
{
88
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "EF1001:Internal EF Core API usage.", Justification = "<Pending>")]
9-
public class IdentifierValueGenerator<TDatabaseClrType> : ValueGenerator<Identifier> where TDatabaseClrType : IConvertible
9+
internal class IdentifierValueGenerator<TDatabaseClrType> : ValueGenerator<Identifier>
1010
{
1111
private readonly ValueGenerator _valueGenerator;
1212

13-
public IdentifierValueGenerator()
13+
public IdentifierValueGenerator()
1414
{
1515
if (typeof(TDatabaseClrType) == typeof(short))
1616
{
@@ -43,4 +43,4 @@ public override Identifier Next(EntityEntry entry)
4343
public override bool GeneratesTemporaryValues
4444
=> true;
4545
}
46-
}
46+
}

Identifiers.EntityFrameworkCore.SqlServer/Identifiers.EntityFrameworkCore.SqlServer.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
<RepositoryUrl>https://github.com/HenkKin/Identifiers.EntityFrameworkCore.SqlServer.git</RepositoryUrl>
1111
<RepositoryType>GitHub</RepositoryType>
1212
<PackageTags>Identifiers id int guid di DependencyInjection Core EntityFramework EF SqlServer</PackageTags>
13-
<AssemblyVersion>1.0.0.0</AssemblyVersion>
14-
<FileVersion>1.0.0.0</FileVersion>
15-
<Version>1.0.0</Version>
13+
<AssemblyVersion>1.0.1.0</AssemblyVersion>
14+
<FileVersion>1.0.1.0</FileVersion>
15+
<Version>1.0.1</Version>
16+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1617
</PropertyGroup>
1718

1819

appveyor.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 1.0.{build}
2+
image:
3+
- Visual Studio 2019
4+
5+
build_script:
6+
- cmd: dotnet build
7+
test_script:
8+
- cmd: dotnet test

0 commit comments

Comments
 (0)