mirror of
https://github.com/fergalmoran/EFCore.NamingConventions.git
synced 2026-01-04 16:04:01 +00:00
Support efcore 6.0 preview 3 (#80)
This commit is contained in:
committed by
GitHub
parent
872404a96c
commit
748054bf6e
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -13,7 +13,7 @@ jobs:
|
|||||||
- name: Setup .NET Core SDK
|
- name: Setup .NET Core SDK
|
||||||
uses: actions/setup-dotnet@v1
|
uses: actions/setup-dotnet@v1
|
||||||
with:
|
with:
|
||||||
dotnet-version: '5.0.x'
|
dotnet-version: '6.0.100-preview.3.21202.5'
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: dotnet test
|
run: dotnet test
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<EFCoreVersion>5.0.5</EFCoreVersion>
|
<EFCoreVersion>6.0.0-preview.3.21201.2</EFCoreVersion>
|
||||||
<MicrosoftExtensionsVersion>5.0.0</MicrosoftExtensionsVersion>
|
<MicrosoftExtensionsVersion>6.0.0-preview.3.21201.4</MicrosoftExtensionsVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.1</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<VersionPrefix>5.0.2</VersionPrefix>
|
<VersionPrefix>6.0.0-preview.3</VersionPrefix>
|
||||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||||
<SignAssembly>true</SignAssembly>
|
<SignAssembly>true</SignAssembly>
|
||||||
<AssemblyOriginatorKeyFile>../EFCore.NamingConventions.snk</AssemblyOriginatorKeyFile>
|
<AssemblyOriginatorKeyFile>../EFCore.NamingConventions.snk</AssemblyOriginatorKeyFile>
|
||||||
|
|||||||
@@ -4,24 +4,31 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
using Microsoft.EntityFrameworkCore.Metadata;
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
using Microsoft.EntityFrameworkCore.Metadata.Conventions;
|
using Microsoft.EntityFrameworkCore.Metadata.Conventions;
|
||||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
|
||||||
|
|
||||||
namespace EFCore.NamingConventions.Internal
|
namespace EFCore.NamingConventions.Internal
|
||||||
{
|
{
|
||||||
public class NameRewritingConvention :
|
public class NameRewritingConvention :
|
||||||
IEntityTypeAddedConvention, IEntityTypeAnnotationChangedConvention, IPropertyAddedConvention,
|
IEntityTypeAddedConvention,
|
||||||
IForeignKeyOwnershipChangedConvention, IKeyAddedConvention, IForeignKeyAddedConvention,
|
IEntityTypeAnnotationChangedConvention,
|
||||||
IIndexAddedConvention, IEntityTypeBaseTypeChangedConvention, IModelFinalizingConvention
|
IPropertyAddedConvention,
|
||||||
|
IForeignKeyOwnershipChangedConvention,
|
||||||
|
IKeyAddedConvention,
|
||||||
|
IForeignKeyAddedConvention,
|
||||||
|
IIndexAddedConvention,
|
||||||
|
IEntityTypeBaseTypeChangedConvention,
|
||||||
|
IModelFinalizingConvention
|
||||||
{
|
{
|
||||||
private static readonly StoreObjectType[] _storeObjectTypes
|
private static readonly StoreObjectType[] _storeObjectTypes
|
||||||
= { StoreObjectType.Table, StoreObjectType.View, StoreObjectType.Function, StoreObjectType.SqlQuery };
|
= { StoreObjectType.Table, StoreObjectType.View, StoreObjectType.Function, StoreObjectType.SqlQuery };
|
||||||
|
|
||||||
private readonly INameRewriter _namingNameRewriter;
|
private readonly INameRewriter _namingNameRewriter;
|
||||||
|
|
||||||
public NameRewritingConvention(INameRewriter nameRewriter) => _namingNameRewriter = nameRewriter;
|
public NameRewritingConvention(INameRewriter nameRewriter)
|
||||||
|
=> _namingNameRewriter = nameRewriter;
|
||||||
|
|
||||||
public virtual void ProcessEntityTypeAdded(
|
public virtual void ProcessEntityTypeAdded(
|
||||||
IConventionEntityTypeBuilder entityTypeBuilder, IConventionContext<IConventionEntityTypeBuilder> context)
|
IConventionEntityTypeBuilder entityTypeBuilder,
|
||||||
|
IConventionContext<IConventionEntityTypeBuilder> context)
|
||||||
{
|
{
|
||||||
var entityType = entityTypeBuilder.Metadata;
|
var entityType = entityTypeBuilder.Metadata;
|
||||||
|
|
||||||
@@ -72,8 +79,7 @@ namespace EFCore.NamingConventions.Internal
|
|||||||
var foreignKey = relationshipBuilder.Metadata;
|
var foreignKey = relationshipBuilder.Metadata;
|
||||||
var ownedEntityType = foreignKey.DeclaringEntityType;
|
var ownedEntityType = foreignKey.DeclaringEntityType;
|
||||||
|
|
||||||
if (foreignKey.IsOwnership &&
|
if (foreignKey.IsOwnership && ownedEntityType.GetTableNameConfigurationSource() != ConfigurationSource.Explicit)
|
||||||
ownedEntityType.GetTableNameConfigurationSource() != ConfigurationSource.Explicit)
|
|
||||||
{
|
{
|
||||||
// An entity type is becoming owned - this is complicated.
|
// An entity type is becoming owned - this is complicated.
|
||||||
|
|
||||||
@@ -94,8 +100,12 @@ namespace EFCore.NamingConventions.Internal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ProcessEntityTypeAnnotationChanged(IConventionEntityTypeBuilder entityTypeBuilder, string name,
|
public void ProcessEntityTypeAnnotationChanged(
|
||||||
IConventionAnnotation annotation, IConventionAnnotation oldAnnotation, IConventionContext<IConventionAnnotation> context)
|
IConventionEntityTypeBuilder entityTypeBuilder,
|
||||||
|
string name,
|
||||||
|
IConventionAnnotation annotation,
|
||||||
|
IConventionAnnotation oldAnnotation,
|
||||||
|
IConventionContext<IConventionAnnotation> context)
|
||||||
{
|
{
|
||||||
var entityType = entityTypeBuilder.Metadata;
|
var entityType = entityTypeBuilder.Metadata;
|
||||||
|
|
||||||
@@ -134,9 +144,9 @@ namespace EFCore.NamingConventions.Internal
|
|||||||
index.Builder.HasDatabaseName(_namingNameRewriter.RewriteName(index.GetDefaultDatabaseName()));
|
index.Builder.HasDatabaseName(_namingNameRewriter.RewriteName(index.GetDefaultDatabaseName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (annotation?.Value is not null &&
|
if (annotation?.Value is not null
|
||||||
entityType.FindOwnership() is IConventionForeignKey ownership &&
|
&& entityType.FindOwnership() is IConventionForeignKey ownership
|
||||||
(string)annotation.Value != ownership.PrincipalEntityType.GetTableName())
|
&& (string)annotation.Value != ownership.PrincipalEntityType.GetTableName())
|
||||||
{
|
{
|
||||||
// An owned entity's table is being set explicitly - this is the trigger to undo table splitting (which is the default).
|
// An owned entity's table is being set explicitly - this is the trigger to undo table splitting (which is the default).
|
||||||
|
|
||||||
@@ -157,7 +167,9 @@ namespace EFCore.NamingConventions.Internal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ProcessForeignKeyAdded(IConventionForeignKeyBuilder relationshipBuilder, IConventionContext<IConventionForeignKeyBuilder> context)
|
public void ProcessForeignKeyAdded(
|
||||||
|
IConventionForeignKeyBuilder relationshipBuilder,
|
||||||
|
IConventionContext<IConventionForeignKeyBuilder> context)
|
||||||
=> relationshipBuilder.HasConstraintName(_namingNameRewriter.RewriteName(relationshipBuilder.Metadata.GetDefaultName()));
|
=> relationshipBuilder.HasConstraintName(_namingNameRewriter.RewriteName(relationshipBuilder.Metadata.GetDefaultName()));
|
||||||
|
|
||||||
public void ProcessKeyAdded(IConventionKeyBuilder keyBuilder, IConventionContext<IConventionKeyBuilder> context)
|
public void ProcessKeyAdded(IConventionKeyBuilder keyBuilder, IConventionContext<IConventionKeyBuilder> context)
|
||||||
@@ -189,8 +201,7 @@ namespace EFCore.NamingConventions.Internal
|
|||||||
if (columnName.StartsWith(entityType.ShortName() + '_', StringComparison.Ordinal))
|
if (columnName.StartsWith(entityType.ShortName() + '_', StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
property.Builder.HasColumnName(
|
property.Builder.HasColumnName(
|
||||||
_namingNameRewriter.RewriteName(entityType.ShortName()) +
|
_namingNameRewriter.RewriteName(entityType.ShortName()) + columnName.Substring(entityType.ShortName().Length));
|
||||||
columnName.Substring(entityType.ShortName().Length));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var storeObjectType in _storeObjectTypes)
|
foreach (var storeObjectType in _storeObjectTypes)
|
||||||
@@ -205,8 +216,8 @@ namespace EFCore.NamingConventions.Internal
|
|||||||
if (columnName.StartsWith(entityType.ShortName() + '_', StringComparison.Ordinal))
|
if (columnName.StartsWith(entityType.ShortName() + '_', StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
property.Builder.HasColumnName(
|
property.Builder.HasColumnName(
|
||||||
_namingNameRewriter.RewriteName(entityType.ShortName()) +
|
_namingNameRewriter.RewriteName(entityType.ShortName())
|
||||||
columnName.Substring(entityType.ShortName().Length));
|
+ columnName.Substring(entityType.ShortName().Length));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -224,9 +235,10 @@ namespace EFCore.NamingConventions.Internal
|
|||||||
|
|
||||||
// TODO: The following is a temporary hack. We should probably just always set the relational override below,
|
// TODO: The following is a temporary hack. We should probably just always set the relational override below,
|
||||||
// but https://github.com/dotnet/efcore/pull/23834
|
// but https://github.com/dotnet/efcore/pull/23834
|
||||||
#pragma warning disable 618
|
var baseColumnName = StoreObjectIdentifier.Create(property.DeclaringEntityType, StoreObjectType.Table) is { } tableIdentifier
|
||||||
propertyBuilder.HasColumnName(_namingNameRewriter.RewriteName(property.GetColumnName()));
|
? property.GetDefaultColumnName(tableIdentifier)
|
||||||
#pragma warning restore 618
|
: property.GetDefaultColumnBaseName();
|
||||||
|
propertyBuilder.HasColumnName(_namingNameRewriter.RewriteName(baseColumnName));
|
||||||
|
|
||||||
foreach (var storeObjectType in _storeObjectTypes)
|
foreach (var storeObjectType in _storeObjectTypes)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user