Skip to content

Commit b13fdb3

Browse files
authored
Merge pull request #22 from TAGC/update-net-6
Upgrade to target .NET 6
2 parents ddd7d27 + 68633e5 commit b13fdb3

File tree

5 files changed

+83
-14
lines changed

5 files changed

+83
-14
lines changed

samples/SpatialFocus.EntityFrameworkCore.Extensions.SQLiteDemo/SpatialFocus.EntityFrameworkCore.Extensions.SQLiteDemo.csproj

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

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp3.0</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.0" />
9+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.0" />
1010
</ItemGroup>
1111

1212
<ItemGroup>

src/SpatialFocus.EntityFrameworkCore.Extensions/NamingExtension.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ public static void ConfigureNames(this ModelBuilder modelBuilder, NamingOptions
3131
// Properties
3232
entity.GetProperties()
3333
.ToList()
34+
#if NET5_0_OR_GREATER
35+
.ForEach(x => x.SetColumnName(namingOptions.ColumnNamingFunction(x.GetColumnBaseName())));
36+
#else
3437
.ForEach(x => x.SetColumnName(namingOptions.ColumnNamingFunction(x.GetColumnName())));
38+
#endif
3539

3640
// Primary and Alternative keys
3741
entity.GetKeys().ToList().ForEach(x => x.SetName(namingOptions.ConstraintNamingFunction(x.GetName())));
@@ -44,7 +48,11 @@ public static void ConfigureNames(this ModelBuilder modelBuilder, NamingOptions
4448
// Indices
4549
entity.GetIndexes()
4650
.ToList()
51+
#if NET5_0_OR_GREATER
52+
.ForEach(x => x.SetDatabaseName(namingOptions.ConstraintNamingFunction(x.GetDatabaseName())));
53+
#else
4754
.ForEach(x => x.SetName(namingOptions.ConstraintNamingFunction(x.GetName())));
55+
#endif
4856
}
4957
}
5058
}

src/SpatialFocus.EntityFrameworkCore.Extensions/SpatialFocus.EntityFrameworkCore.Extensions.csproj

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.1</TargetFramework>
4+
<TargetFrameworks>netstandard2.1;net5.0;net6.0</TargetFrameworks>
55
</PropertyGroup>
66

77
<PropertyGroup>
@@ -33,10 +33,26 @@
3333
<ItemGroup>
3434
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
3535
<PackageReference Include="Humanizer.Core" Version="2.8.26" />
36+
</ItemGroup>
37+
38+
<!-- Conditionally obtain references for the netstandard2.1 target -->
39+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.1' ">
3640
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.0" />
3741
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.0" />
3842
</ItemGroup>
3943

44+
<!-- Conditionally obtain references for the net5.0 target -->
45+
<ItemGroup Condition=" '$(TargetFramework)' == 'net5.0' ">
46+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.12" />
47+
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.12" />
48+
</ItemGroup>
49+
50+
<!-- Conditionally obtain references for the net6.0 target -->
51+
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
52+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
53+
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.0" />
54+
</ItemGroup>
55+
4056
<ItemGroup>
4157
<None Include="..\..\docs\nuget-icon.png" Pack="true" PackagePath="\" />
4258
</ItemGroup>

test/SpatialFocus.EntityFrameworkCore.Extensions.Test/NamingOptionsTest.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ public void OverrideColumnNaming()
3434
ProductContext context = GetContext(namingOptions: new NamingOptions().OverrideColumnNaming(NamingScheme.SnakeCase));
3535

3636
IEntityType findEntityType = context.Model.FindEntityType(typeof(ProductTag));
37+
#if NET5_0_OR_GREATER
38+
Assert.Equal("product_tag_id", findEntityType.FindProperty(nameof(ProductTag.ProductTagId)).GetColumnBaseName());
39+
#else
3740
Assert.Equal("product_tag_id", findEntityType.FindProperty(nameof(ProductTag.ProductTagId)).GetColumnName());
41+
#endif
3842
}
3943

4044
[Fact]
@@ -44,10 +48,21 @@ public void OverrideConstraintNaming()
4448

4549
IEntityType findEntityType = context.Model.FindEntityType(typeof(ProductTag));
4650
Assert.Equal("ProductTag", findEntityType.GetTableName());
51+
52+
#if NET5_0_OR_GREATER
53+
Assert.Equal("ProductTagId", findEntityType.FindProperty(nameof(ProductTag.ProductTagId)).GetColumnBaseName());
54+
#else
4755
Assert.Equal("ProductTagId", findEntityType.FindProperty(nameof(ProductTag.ProductTagId)).GetColumnName());
56+
#endif
57+
4858
Assert.True(findEntityType.GetKeys().All(x => x.GetName() == NamingScheme.SnakeCase(x.GetDefaultName())));
4959
Assert.True(findEntityType.GetForeignKeys().All(x => x.GetConstraintName() == NamingScheme.SnakeCase(x.GetDefaultName())));
60+
61+
#if NET5_0_OR_GREATER
62+
Assert.True(findEntityType.GetIndexes().All(x => x.GetDatabaseName() == NamingScheme.SnakeCase(x.GetDefaultDatabaseName())));
63+
#else
5064
Assert.True(findEntityType.GetIndexes().All(x => x.GetName() == NamingScheme.SnakeCase(x.GetDefaultName())));
65+
#endif
5166
}
5267

5368
[Fact]
@@ -77,6 +92,20 @@ public void PluralizeAndOverrideTableNaming()
7792
Assert.Equal("product_tags", findEntityType.GetTableName());
7893
}
7994

95+
#if NET5_0_OR_GREATER
96+
[Fact]
97+
public void SetNamingScheme()
98+
{
99+
ProductContext context = GetContext(namingOptions: new NamingOptions().SetNamingScheme(NamingScheme.SnakeCase));
100+
101+
IEntityType findEntityType = context.Model.FindEntityType(typeof(ProductTag));
102+
Assert.Equal("product_tag", findEntityType.GetTableName());
103+
Assert.Equal("product_tag_id", findEntityType.FindProperty(nameof(ProductTag.ProductTagId)).GetColumnBaseName());
104+
Assert.True(findEntityType.GetKeys().All(x => x.GetName() == NamingScheme.SnakeCase(x.GetDefaultName())));
105+
Assert.True(findEntityType.GetForeignKeys().All(x => x.GetConstraintName() == NamingScheme.SnakeCase(x.GetDefaultName())));
106+
Assert.True(findEntityType.GetIndexes().All(x => x.GetDatabaseName() == NamingScheme.SnakeCase(x.GetDefaultDatabaseName())));
107+
}
108+
#else
80109
[Fact]
81110
public void SetNamingScheme()
82111
{
@@ -89,6 +118,7 @@ public void SetNamingScheme()
89118
Assert.True(findEntityType.GetForeignKeys().All(x => x.GetConstraintName() == NamingScheme.SnakeCase(x.GetDefaultName())));
90119
Assert.True(findEntityType.GetIndexes().All(x => x.GetName() == NamingScheme.SnakeCase(x.GetDefaultName())));
91120
}
121+
#endif
92122

93123
[Fact]
94124
public void MultipleProviders()
Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
5-
6-
<IsPackable>false</IsPackable>
7-
</PropertyGroup>
3+
<PropertyGroup>
4+
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
5+
<IsPackable>false</IsPackable>
6+
</PropertyGroup>
87

98
<ItemGroup>
10-
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.0" />
11-
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.0" />
129
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
1310
<PackageReference Include="xunit" Version="2.4.0" />
1411
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
1512
<PackageReference Include="coverlet.collector" Version="1.0.1" />
1613
</ItemGroup>
1714

18-
<ItemGroup>
19-
<ProjectReference Include="..\..\src\SpatialFocus.EntityFrameworkCore.Extensions\SpatialFocus.EntityFrameworkCore.Extensions.csproj" />
20-
</ItemGroup>
15+
<!-- Conditionally obtain references for the netcoreapp3.1 target -->
16+
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
17+
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.0" />
18+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.0" />
19+
</ItemGroup>
20+
21+
<!-- Conditionally obtain references for the net5.0 target -->
22+
<ItemGroup Condition=" '$(TargetFramework)' == 'net5.0' ">
23+
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.12" />
24+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.12" />
25+
</ItemGroup>
26+
27+
<!-- Conditionally obtain references for the net6.0 target -->
28+
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
29+
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.0" />
30+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.0" />
31+
</ItemGroup>
32+
33+
<ItemGroup>
34+
<ProjectReference Include="..\..\src\SpatialFocus.EntityFrameworkCore.Extensions\SpatialFocus.EntityFrameworkCore.Extensions.csproj" />
35+
</ItemGroup>
2136

2237
</Project>

0 commit comments

Comments
 (0)