mirror of
https://github.com/fergalmoran/EFCore.NamingConventions.git
synced 2025-12-22 09:38:21 +00:00
@@ -404,6 +404,18 @@ namespace EFCore.NamingConventions.Test
|
||||
.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]
|
||||
public void Not_mapped_to_table()
|
||||
{
|
||||
@@ -451,6 +463,7 @@ namespace EFCore.NamingConventions.Test
|
||||
public int PostId { get; set; }
|
||||
public Blog Blog { get; set; }
|
||||
public int BlogId { get; set; }
|
||||
public string PostTitle { get; set; }
|
||||
}
|
||||
|
||||
public class Parent
|
||||
|
||||
@@ -79,11 +79,14 @@ namespace EFCore.NamingConventions.Internal
|
||||
var foreignKey = relationshipBuilder.Metadata;
|
||||
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
|
||||
// does nothing.
|
||||
ownedEntityType.Builder.HasNoAnnotation(RelationalAnnotationNames.TableName);
|
||||
@@ -183,14 +186,7 @@ namespace EFCore.NamingConventions.Internal
|
||||
=> relationshipBuilder.HasConstraintName(_namingNameRewriter.RewriteName(relationshipBuilder.Metadata.GetDefaultName()));
|
||||
|
||||
public void ProcessKeyAdded(IConventionKeyBuilder keyBuilder, IConventionContext<IConventionKeyBuilder> context)
|
||||
{
|
||||
var entityType = keyBuilder.Metadata.DeclaringEntityType;
|
||||
|
||||
if (entityType.FindOwnership() is null)
|
||||
{
|
||||
keyBuilder.HasName(_namingNameRewriter.RewriteName(keyBuilder.Metadata.GetDefaultName()));
|
||||
}
|
||||
}
|
||||
=> keyBuilder.HasName(_namingNameRewriter.RewriteName(keyBuilder.Metadata.GetName()));
|
||||
|
||||
public void ProcessIndexAdded(
|
||||
IConventionIndexBuilder indexBuilder,
|
||||
@@ -218,10 +214,15 @@ namespace EFCore.NamingConventions.Internal
|
||||
{
|
||||
var identifier = StoreObjectIdentifier.Create(entityType, storeObjectType);
|
||||
if (identifier is null)
|
||||
continue;
|
||||
|
||||
if (property.GetColumnNameConfigurationSource(identifier.Value) == ConfigurationSource.Convention)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (property.GetColumnNameConfigurationSource(identifier.Value) != ConfigurationSource.Convention)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
columnName = property.GetColumnName(identifier.Value);
|
||||
if (columnName.StartsWith(entityType.ShortName() + '_', StringComparison.Ordinal))
|
||||
{
|
||||
@@ -233,7 +234,6 @@ namespace EFCore.NamingConventions.Internal
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RewriteColumnName(IConventionPropertyBuilder propertyBuilder)
|
||||
{
|
||||
@@ -254,7 +254,9 @@ namespace EFCore.NamingConventions.Internal
|
||||
{
|
||||
var identifier = StoreObjectIdentifier.Create(entityType, storeObjectType);
|
||||
if (identifier is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (property.GetColumnNameConfigurationSource(identifier.Value) == ConfigurationSource.Convention)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user