mirror of
https://github.com/fergalmoran/EFCore.NamingConventions.git
synced 2026-01-03 07:26:28 +00:00
@@ -404,6 +404,18 @@ namespace EFCore.NamingConventions.Test
|
|||||||
.GetColumnName(StoreObjectIdentifier.Create(ownedEntityType, StoreObjectType.Table)!.Value));
|
.GetColumnName(StoreObjectIdentifier.Create(ownedEntityType, StoreObjectType.Table)!.Value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Owned_entity_withs_OwnsMany()
|
||||||
|
{
|
||||||
|
var model = BuildModel(b => b.Entity<Blog>().OwnsMany(b => b.Posts));
|
||||||
|
var ownedEntityType = model.FindEntityType(typeof(Post));
|
||||||
|
|
||||||
|
Assert.Equal("post", ownedEntityType.GetTableName());
|
||||||
|
Assert.Equal("pk_post", ownedEntityType.FindPrimaryKey().GetName());
|
||||||
|
Assert.Equal("post_title", ownedEntityType.FindProperty("PostTitle")
|
||||||
|
.GetColumnName(StoreObjectIdentifier.Create(ownedEntityType, StoreObjectType.Table)!.Value));
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Not_mapped_to_table()
|
public void Not_mapped_to_table()
|
||||||
{
|
{
|
||||||
@@ -451,6 +463,7 @@ namespace EFCore.NamingConventions.Test
|
|||||||
public int PostId { get; set; }
|
public int PostId { get; set; }
|
||||||
public Blog Blog { get; set; }
|
public Blog Blog { get; set; }
|
||||||
public int BlogId { get; set; }
|
public int BlogId { get; set; }
|
||||||
|
public string PostTitle { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Parent
|
public class Parent
|
||||||
|
|||||||
@@ -79,11 +79,14 @@ namespace EFCore.NamingConventions.Internal
|
|||||||
var foreignKey = relationshipBuilder.Metadata;
|
var foreignKey = relationshipBuilder.Metadata;
|
||||||
var ownedEntityType = foreignKey.DeclaringEntityType;
|
var ownedEntityType = foreignKey.DeclaringEntityType;
|
||||||
|
|
||||||
if (foreignKey.IsOwnership && ownedEntityType.GetTableNameConfigurationSource() != ConfigurationSource.Explicit)
|
// An entity type is becoming owned - this is a bit complicated.
|
||||||
|
// Unless it's a collection navigation, or the owned entity table name was explicitly set by the user, this triggers table
|
||||||
|
// splitting, which means we need to undo rewriting which we've done previously.
|
||||||
|
if (foreignKey.IsOwnership
|
||||||
|
&& !foreignKey.GetNavigation(false).IsCollection
|
||||||
|
&& ownedEntityType.GetTableNameConfigurationSource() != ConfigurationSource.Explicit)
|
||||||
{
|
{
|
||||||
// An entity type is becoming owned - this is complicated.
|
// Reset the table name which we've set when the entity type was added.
|
||||||
|
|
||||||
// Reset the table name which we've set when the entity type was added
|
|
||||||
// If table splitting was configured by explicitly setting the table name, the following
|
// If table splitting was configured by explicitly setting the table name, the following
|
||||||
// does nothing.
|
// does nothing.
|
||||||
ownedEntityType.Builder.HasNoAnnotation(RelationalAnnotationNames.TableName);
|
ownedEntityType.Builder.HasNoAnnotation(RelationalAnnotationNames.TableName);
|
||||||
@@ -183,14 +186,7 @@ namespace EFCore.NamingConventions.Internal
|
|||||||
=> 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)
|
||||||
{
|
=> keyBuilder.HasName(_namingNameRewriter.RewriteName(keyBuilder.Metadata.GetName()));
|
||||||
var entityType = keyBuilder.Metadata.DeclaringEntityType;
|
|
||||||
|
|
||||||
if (entityType.FindOwnership() is null)
|
|
||||||
{
|
|
||||||
keyBuilder.HasName(_namingNameRewriter.RewriteName(keyBuilder.Metadata.GetDefaultName()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ProcessIndexAdded(
|
public void ProcessIndexAdded(
|
||||||
IConventionIndexBuilder indexBuilder,
|
IConventionIndexBuilder indexBuilder,
|
||||||
@@ -218,17 +214,21 @@ namespace EFCore.NamingConventions.Internal
|
|||||||
{
|
{
|
||||||
var identifier = StoreObjectIdentifier.Create(entityType, storeObjectType);
|
var identifier = StoreObjectIdentifier.Create(entityType, storeObjectType);
|
||||||
if (identifier is null)
|
if (identifier is null)
|
||||||
continue;
|
|
||||||
|
|
||||||
if (property.GetColumnNameConfigurationSource(identifier.Value) == ConfigurationSource.Convention)
|
|
||||||
{
|
{
|
||||||
columnName = property.GetColumnName(identifier.Value);
|
continue;
|
||||||
if (columnName.StartsWith(entityType.ShortName() + '_', StringComparison.Ordinal))
|
}
|
||||||
{
|
|
||||||
property.Builder.HasColumnName(
|
if (property.GetColumnNameConfigurationSource(identifier.Value) != ConfigurationSource.Convention)
|
||||||
_namingNameRewriter.RewriteName(entityType.ShortName())
|
{
|
||||||
+ columnName.Substring(entityType.ShortName().Length));
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
columnName = property.GetColumnName(identifier.Value);
|
||||||
|
if (columnName.StartsWith(entityType.ShortName() + '_', StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
property.Builder.HasColumnName(
|
||||||
|
_namingNameRewriter.RewriteName(entityType.ShortName())
|
||||||
|
+ columnName.Substring(entityType.ShortName().Length));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -254,7 +254,9 @@ namespace EFCore.NamingConventions.Internal
|
|||||||
{
|
{
|
||||||
var identifier = StoreObjectIdentifier.Create(entityType, storeObjectType);
|
var identifier = StoreObjectIdentifier.Create(entityType, storeObjectType);
|
||||||
if (identifier is null)
|
if (identifier is null)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (property.GetColumnNameConfigurationSource(identifier.Value) == ConfigurationSource.Convention)
|
if (property.GetColumnNameConfigurationSource(identifier.Value) == ConfigurationSource.Convention)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user