Skip to content

Commit

Permalink
Merge branch 'main' into ignore-migration-table
Browse files Browse the repository at this point in the history
  • Loading branch information
EraYaN authored Aug 3, 2021
2 parents c3cf584 + 4544bc5 commit 7e62d57
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 69 deletions.
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2
updates:
- package-ecosystem: "nuget"
directory: "/"
open-pull-requests-limit: 100
schedule:
interval: "daily"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v2.3.4

- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v1.8.1
with:
dotnet-version: '5.0.x'
dotnet-version: '6.0.100-preview.3.21202.5'

- name: Test
run: dotnet test
Expand All @@ -28,7 +28,7 @@ jobs:

- name: Upload artifacts
if: github.event_name == 'push' && startsWith(github.repository, 'efcore/')
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v2.2.4
with:
name: EFCore.NamingConventions
path: nupkgs
6 changes: 2 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<Project>
<PropertyGroup>
<AnalysisLevel>latest</AnalysisLevel>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<LangVersion>9.0</LangVersion>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
</Project>
18 changes: 0 additions & 18 deletions Directory.Build.targets

This file was deleted.

24 changes: 24 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project>
<PropertyGroup>
<EFCoreVersion>6.0.0-preview.3.21201.2</EFCoreVersion>
<MicrosoftExtensionsVersion>6.0.0-preview.3.21201.4</MicrosoftExtensionsVersion>
</PropertyGroup>

<ItemGroup>
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(MicrosoftExtensionsVersion)" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="$(EFCoreVersion)" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="$(EFCoreVersion)" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.0.0" />

<!-- Test -->
<PackageVersion Include="xunit" Version="2.4.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.3" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="$(EFCoreVersion)" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="$(EFCoreVersion)" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Specification.Tests" Version="$(EFCoreVersion)" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="$(MicrosoftExtensionsVersion)" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="$(MicrosoftExtensionsVersion)" />
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="$(MicrosoftExtensionsVersion)" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
106 changes: 104 additions & 2 deletions EFCore.NamingConventions.Test/NameRewritingConventionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Globalization;
using System.Linq;
using EFCore.NamingConventions.Internal;
Expand Down Expand Up @@ -245,7 +246,7 @@ public void TPT_with_owned()
}

[Fact]
public void Table_splitting()
public void Table_splitting1()
{
var model = BuildModel(b =>
{
Expand All @@ -256,7 +257,42 @@ public void Table_splitting()
e.HasOne(s1 => s1.S2).WithOne(s2 => s2.S1).HasForeignKey<Split2>(s2 => s2.Id);
});
b.Entity<Split2>(e => e.ToTable("split_table"));
b.Entity<Split2>().ToTable("split_table");
});

var split1EntityType = model.FindEntityType(typeof(Split1));
var split2EntityType = model.FindEntityType(typeof(Split2));

var table = StoreObjectIdentifier.Create(split1EntityType, StoreObjectType.Table)!.Value;
Assert.Equal(table, StoreObjectIdentifier.Create(split2EntityType, StoreObjectType.Table));

Assert.Equal("split_table", split1EntityType.GetTableName());
Assert.Equal("one_prop", split1EntityType.FindProperty(nameof(Split1.OneProp)).GetColumnName(table));

Assert.Equal("split_table", split2EntityType.GetTableName());
Assert.Equal("two_prop", split2EntityType.FindProperty(nameof(Split2.TwoProp)).GetColumnName(table));

Assert.Equal("common", split1EntityType.FindProperty(nameof(Split1.Common)).GetColumnName(table));
Assert.Equal("split2_common", split2EntityType.FindProperty(nameof(Split2.Common)).GetColumnName(table));

var foreignKey = split2EntityType.GetForeignKeys().Single();
Assert.Same(split1EntityType.FindPrimaryKey(), foreignKey.PrincipalKey);
Assert.Same(split2EntityType.FindPrimaryKey().Properties.Single(), foreignKey.Properties.Single());
Assert.Equal(split1EntityType.FindPrimaryKey().GetName(), split2EntityType.FindPrimaryKey().GetName());
Assert.Equal(
foreignKey.PrincipalKey.Properties.Single().GetColumnName(table),
foreignKey.Properties.Single().GetColumnName(table));
Assert.Empty(split1EntityType.GetForeignKeys());
}

[Fact]
public void Table_splitting_and_explicit_owner_table()
{
var model = BuildModel(b =>
{
b.Entity<Split1>().HasOne(s1 => s1.S2).WithOne(s2 => s2.S1).HasForeignKey<Split2>(s2 => s2.Id);
b.Entity<Split2>().ToTable("split_table");
b.Entity<Split1>().ToTable("split_table");
});

var split1EntityType = model.FindEntityType(typeof(Split1));
Expand Down Expand Up @@ -306,6 +342,70 @@ public void Owned_entity_with_table_splitting()
Assert.Equal("id", ownedKey.Properties.Single().GetColumnName(table));
}

[Fact]
public void Owned_entity_with_table_splitting_and_explicit_owner_table()
{
var model = BuildModel(
b => b.Entity<Owner>(
e =>
{
e.OwnsOne(o => o.Owned);
e.ToTable("destination_table");
}));

var ownerEntityType = model.FindEntityType(typeof(Owner));
var ownedEntityType = model.FindEntityType(typeof(Owned));

Assert.Equal("destination_table", ownerEntityType.GetTableName());
Assert.Equal("destination_table", ownedEntityType.GetTableName());
var table = StoreObjectIdentifier.Create(ownerEntityType, StoreObjectType.Table)!.Value;
Assert.Equal(table, StoreObjectIdentifier.Create(ownedEntityType, StoreObjectType.Table)!.Value);

Assert.Equal("owned_owned_property", ownedEntityType.FindProperty(nameof(Owned.OwnedProperty)).GetColumnName(table));

var (ownerKey, ownedKey) = (ownerEntityType.FindPrimaryKey(), ownedEntityType.FindPrimaryKey());
Assert.Equal("pk_destination_table", ownerKey.GetName());
Assert.Equal("pk_destination_table", ownedKey.GetName());
Assert.Equal("id", ownerKey.Properties.Single().GetColumnName(table));
Assert.Equal("id", ownedKey.Properties.Single().GetColumnName(table));
}

[Fact]
public void Owned_entity_twice_with_table_splitting_and_explicit_owner_table()
{
var model = BuildModel(
b => b.Entity<Owner>(
e =>
{
e.OwnsOne("owned1", o => o.Owned);
e.OwnsOne("owned2", o => o.Owned2);
e.ToTable("destination_table");
}));

var ownerEntityType = model.FindEntityType(typeof(Owner));
var owned1EntityType = model.FindEntityType("owned1");
var owned2EntityType = model.FindEntityType("owned2");

Assert.Equal("destination_table", ownerEntityType.GetTableName());
Assert.Equal("destination_table", owned1EntityType.GetTableName());
Assert.Equal("destination_table", owned2EntityType.GetTableName());
var table = StoreObjectIdentifier.Create(ownerEntityType, StoreObjectType.Table)!.Value;
Assert.Equal(table, StoreObjectIdentifier.Create(owned1EntityType, StoreObjectType.Table)!.Value);
Assert.Equal(table, StoreObjectIdentifier.Create(owned2EntityType, StoreObjectType.Table)!.Value);

Assert.Equal("owned_owned_property", owned1EntityType.FindProperty(nameof(Owned.OwnedProperty)).GetColumnName(table));
Assert.Equal("owned2_owned_property", owned2EntityType.FindProperty(nameof(Owned.OwnedProperty)).GetColumnName(table));

var (ownerKey, owned1Key, owned2Key) =
(ownerEntityType.FindPrimaryKey(), owned1EntityType.FindPrimaryKey(), owned1EntityType.FindPrimaryKey());
Assert.Equal("pk_destination_table", ownerKey.GetName());
Assert.Equal("pk_destination_table", owned1Key.GetName());
Assert.Equal("pk_destination_table", owned2Key.GetName());
Assert.Equal("id", ownerKey.Properties.Single().GetColumnName(table));
Assert.Equal("id", owned1Key.Properties.Single().GetColumnName(table));
Assert.Equal("id", owned2Key.Properties.Single().GetColumnName(table));
}

[Fact]
public void Owned_entity_without_table_splitting()
{
Expand Down Expand Up @@ -397,6 +497,8 @@ public class Owner
public int Id { get; set; }
public int OwnerProperty { get; set; }
public Owned Owned { get; set; }
[NotMapped]
public Owned Owned2 { get; set; }
}

public class Owned
Expand Down
2 changes: 1 addition & 1 deletion EFCore.NamingConventions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F6BE1E4F-B395-456A-9856-0C9AE4F626C0}"
ProjectSection(SolutionItems) = preProject
Directory.Build.props = Directory.Build.props
Directory.Build.targets = Directory.Build.targets
.github\workflows\build.yml = .github\workflows\build.yml
Directory.Packages.props = Directory.Packages.props
EndProjectSection
EndProject
Global
Expand Down
5 changes: 3 additions & 2 deletions EFCore.NamingConventions/EFCore.NamingConventions.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<VersionPrefix>5.0.2</VersionPrefix>
<TargetFramework>net6.0</TargetFramework>
<VersionPrefix>6.0.0-preview.3</VersionPrefix>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>../EFCore.NamingConventions.snk</AssemblyOriginatorKeyFile>
Expand All @@ -22,6 +22,7 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
<PackageReference Include="Microsoft.EntityFrameworkCore" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
</ItemGroup>

</Project>
Loading

0 comments on commit 7e62d57

Please sign in to comment.