Skip to content

Commit

Permalink
Add model building support for SProc mapping
Browse files Browse the repository at this point in the history
Part of #245
  • Loading branch information
AndriySvyryd authored Jul 24, 2022
1 parent 8152d15 commit 08a1b45
Show file tree
Hide file tree
Showing 61 changed files with 6,442 additions and 296 deletions.
16 changes: 8 additions & 8 deletions src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ private void GenerateTableMapping(

if (hasOverrides)
{
GenerateOverrides("t", entityType, table!.Value, stringBuilder);
GeneratePropertyOverrides("t", entityType, table!.Value, stringBuilder);
}
}

Expand Down Expand Up @@ -959,7 +959,7 @@ private void GenerateSplitTableMapping(
using (stringBuilder.Indent())
{
GenerateTriggers("t", entityType, table.Name, table.Schema, stringBuilder);
GenerateOverrides("t", entityType, table, stringBuilder);
GeneratePropertyOverrides("t", entityType, table, stringBuilder);
GenerateEntityTypeMappingFragmentAnnotations("t", fragment, stringBuilder);
}

Expand Down Expand Up @@ -1023,7 +1023,7 @@ private void GenerateViewMapping(string entityTypeBuilderName, IEntityType entit

using (stringBuilder.Indent())
{
GenerateOverrides("v", entityType, view!.Value, stringBuilder);
GeneratePropertyOverrides("v", entityType, view!.Value, stringBuilder);
}

stringBuilder.Append("}");
Expand Down Expand Up @@ -1055,7 +1055,7 @@ private void GenerateSplitViewMapping(

using (stringBuilder.Indent())
{
GenerateOverrides("v", entityType, fragment.StoreObject, stringBuilder);
GeneratePropertyOverrides("v", entityType, fragment.StoreObject, stringBuilder);
GenerateEntityTypeMappingFragmentAnnotations("v", fragment, stringBuilder);
}

Expand Down Expand Up @@ -1266,7 +1266,7 @@ protected virtual void GenerateTriggerAnnotations(
/// <param name="entityType">The entity type.</param>
/// <param name="storeObject">The store object identifier.</param>
/// <param name="stringBuilder">The builder code is added to.</param>
protected virtual void GenerateOverrides(
protected virtual void GeneratePropertyOverrides(
string tableBuilderName,
IEntityType entityType,
StoreObjectIdentifier storeObject,
Expand All @@ -1277,7 +1277,7 @@ protected virtual void GenerateOverrides(
var overrides = property.FindOverrides(storeObject);
if (overrides != null)
{
GenerateOverride(tableBuilderName, overrides, stringBuilder);
GeneratePropertyOverride(tableBuilderName, overrides, stringBuilder);
}
}
}
Expand All @@ -1288,7 +1288,7 @@ protected virtual void GenerateOverrides(
/// <param name="tableBuilderName">The name of the table builder variable.</param>
/// <param name="overrides">The overrides.</param>
/// <param name="stringBuilder">The builder code is added to.</param>
protected virtual void GenerateOverride(
protected virtual void GeneratePropertyOverride(
string tableBuilderName,
IRelationalPropertyOverrides overrides,
IndentedStringBuilder stringBuilder)
Expand All @@ -1301,7 +1301,7 @@ protected virtual void GenerateOverride(
// Note that GenerateAnnotations below does the corresponding decrement
stringBuilder.IncrementIndent();

if (overrides.ColumnNameOverridden)
if (overrides.IsColumnNameOverridden)
{
stringBuilder
.AppendLine()
Expand Down
3 changes: 3 additions & 0 deletions src/EFCore.Relational/Design/AnnotationCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class AnnotationCodeGenerator : IAnnotationCodeGenerator
RelationalAnnotationNames.Triggers,
RelationalAnnotationNames.Sequences,
RelationalAnnotationNames.DbFunctions,
RelationalAnnotationNames.DeleteStoredProcedure,
RelationalAnnotationNames.InsertStoredProcedure,
RelationalAnnotationNames.UpdateStoredProcedure,
RelationalAnnotationNames.MappingFragments,
RelationalAnnotationNames.RelationalOverrides
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ private void Create(
AppendLiteral(storeObject, mainBuilder, code);

mainBuilder.AppendLine(",")
.Append(code.Literal(overrides.ColumnNameOverridden)).AppendLine(",")
.Append(code.Literal(overrides.IsColumnNameOverridden)).AppendLine(",")
.Append(code.Literal(overrides.ColumnName)).AppendLine(");").DecrementIndent();

CreateAnnotations(
Expand Down
6 changes: 3 additions & 3 deletions src/EFCore.Relational/Diagnostics/RelationalEventId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private enum Id
DuplicateColumnOrders,
ForeignKeyTpcPrincipalWarning,
TpcStoreGeneratedIdentityWarning,
KeyUnmappedProperties,
KeyPropertiesNotMappedToTable,

// Update events
BatchReadyForExecution = CoreEventId.RelationalBaseId + 700,
Expand Down Expand Up @@ -825,8 +825,8 @@ private static EventId MakeValidationId(Id id)
/// This event uses the <see cref="KeyEventData" /> payload when used with a <see cref="DiagnosticSource" />.
/// </para>
/// </remarks>
public static readonly EventId KeyUnmappedProperties =
MakeValidationId(Id.KeyUnmappedProperties);
public static readonly EventId KeyPropertiesNotMappedToTable =
MakeValidationId(Id.KeyPropertiesNotMappedToTable);

/// <summary>
/// A foreign key specifies properties which don't map to the related tables.
Expand Down
10 changes: 5 additions & 5 deletions src/EFCore.Relational/Diagnostics/RelationalLoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2775,15 +2775,15 @@ private static string NamedIndexPropertiesMappedToNonOverlappingTables(EventDefi
}

/// <summary>
/// Logs the <see cref="RelationalEventId.KeyUnmappedProperties" /> event.
/// Logs the <see cref="RelationalEventId.KeyPropertiesNotMappedToTable" /> event.
/// </summary>
/// <param name="diagnostics">The diagnostics logger to use.</param>
/// <param name="key">The foreign key.</param>
public static void KeyUnmappedProperties(
public static void KeyPropertiesNotMappedToTable(
this IDiagnosticsLogger<DbLoggerCategory.Model.Validation> diagnostics,
IKey key)
{
var definition = RelationalResources.LogKeyUnmappedProperties(diagnostics);
var definition = RelationalResources.LogKeyPropertiesNotMappedToTable(diagnostics);

if (diagnostics.ShouldLog(definition))
{
Expand All @@ -2798,14 +2798,14 @@ public static void KeyUnmappedProperties(
{
var eventData = new KeyEventData(
definition,
KeyUnmappedProperties,
KeyPropertiesNotMappedToTable,
key);

diagnostics.DispatchEventData(definition, eventData, diagnosticSourceEnabled, simpleLogEnabled);
}
}

private static string KeyUnmappedProperties(EventDefinitionBase definition, EventData payload)
private static string KeyPropertiesNotMappedToTable(EventDefinitionBase definition, EventData payload)
{
var d = (EventDefinition<string, string, string>)definition;
var p = (KeyEventData)payload;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ public abstract class RelationalLoggingDefinitions : LoggingDefinitions
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
[EntityFrameworkInternal]
public EventDefinitionBase? LogKeyUnmappedProperties;
public EventDefinitionBase? LogKeyPropertiesNotMappedToTable;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Loading

0 comments on commit 08a1b45

Please sign in to comment.