Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/EFCore.Relational/EFCore.Relational.baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -3174,7 +3174,7 @@
]
},
{
"Type": "interface Microsoft.EntityFrameworkCore.Metadata.IColumnMapping : Microsoft.EntityFrameworkCore.Metadata.IColumnMappingBase, Microsoft.EntityFrameworkCore.Infrastructure.IAnnotatable, Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable",
"Type": "interface Microsoft.EntityFrameworkCore.Metadata.IColumnMapping : Microsoft.EntityFrameworkCore.Metadata.IColumnMappingBase, Microsoft.EntityFrameworkCore.Infrastructure.IAnnotatable, Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable, System.IComparable<Microsoft.EntityFrameworkCore.Metadata.IColumnMappingBase>",
"Methods": [
{
"Member": "string ToDebugString(Microsoft.EntityFrameworkCore.Infrastructure.MetadataDebugStringOptions options = Microsoft.EntityFrameworkCore.Infrastructure.MetadataDebugStringOptions.ShortDefault, int indent = 0);"
Expand All @@ -3190,7 +3190,7 @@
]
},
{
"Type": "interface Microsoft.EntityFrameworkCore.Metadata.IColumnMappingBase : Microsoft.EntityFrameworkCore.Infrastructure.IAnnotatable, Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable",
"Type": "interface Microsoft.EntityFrameworkCore.Metadata.IColumnMappingBase : Microsoft.EntityFrameworkCore.Infrastructure.IAnnotatable, Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable, System.IComparable<Microsoft.EntityFrameworkCore.Metadata.IColumnMappingBase>",
"Properties": [
{
"Member": "Microsoft.EntityFrameworkCore.Metadata.IColumnBase Column { get; }"
Expand Down Expand Up @@ -4251,7 +4251,7 @@
]
},
{
"Type": "interface Microsoft.EntityFrameworkCore.Metadata.IFunctionColumnMapping : Microsoft.EntityFrameworkCore.Metadata.IColumnMappingBase, Microsoft.EntityFrameworkCore.Infrastructure.IAnnotatable, Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable",
"Type": "interface Microsoft.EntityFrameworkCore.Metadata.IFunctionColumnMapping : Microsoft.EntityFrameworkCore.Metadata.IColumnMappingBase, Microsoft.EntityFrameworkCore.Infrastructure.IAnnotatable, Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable, System.IComparable<Microsoft.EntityFrameworkCore.Metadata.IColumnMappingBase>",
"Methods": [
{
"Member": "string ToDebugString(Microsoft.EntityFrameworkCore.Infrastructure.MetadataDebugStringOptions options = Microsoft.EntityFrameworkCore.Infrastructure.MetadataDebugStringOptions.ShortDefault, int indent = 0);"
Expand All @@ -4267,7 +4267,7 @@
]
},
{
"Type": "interface Microsoft.EntityFrameworkCore.Metadata.IFunctionMapping : Microsoft.EntityFrameworkCore.Metadata.ITableMappingBase, Microsoft.EntityFrameworkCore.Infrastructure.IAnnotatable, Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable",
"Type": "interface Microsoft.EntityFrameworkCore.Metadata.IFunctionMapping : Microsoft.EntityFrameworkCore.Metadata.ITableMappingBase, Microsoft.EntityFrameworkCore.Infrastructure.IAnnotatable, Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable, System.IComparable<Microsoft.EntityFrameworkCore.Metadata.ITableMappingBase>",
"Properties": [
{
"Member": "System.Collections.Generic.IEnumerable<Microsoft.EntityFrameworkCore.Metadata.IFunctionColumnMapping> ColumnMappings { get; }"
Expand Down Expand Up @@ -6305,7 +6305,7 @@
]
},
{
"Type": "interface Microsoft.EntityFrameworkCore.Metadata.ISqlQueryColumnMapping : Microsoft.EntityFrameworkCore.Metadata.IColumnMappingBase, Microsoft.EntityFrameworkCore.Infrastructure.IAnnotatable, Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable",
"Type": "interface Microsoft.EntityFrameworkCore.Metadata.ISqlQueryColumnMapping : Microsoft.EntityFrameworkCore.Metadata.IColumnMappingBase, Microsoft.EntityFrameworkCore.Infrastructure.IAnnotatable, Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable, System.IComparable<Microsoft.EntityFrameworkCore.Metadata.IColumnMappingBase>",
"Methods": [
{
"Member": "string ToDebugString(Microsoft.EntityFrameworkCore.Infrastructure.MetadataDebugStringOptions options = Microsoft.EntityFrameworkCore.Infrastructure.MetadataDebugStringOptions.ShortDefault, int indent = 0);"
Expand All @@ -6321,7 +6321,7 @@
]
},
{
"Type": "interface Microsoft.EntityFrameworkCore.Metadata.ISqlQueryMapping : Microsoft.EntityFrameworkCore.Metadata.ITableMappingBase, Microsoft.EntityFrameworkCore.Infrastructure.IAnnotatable, Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable",
"Type": "interface Microsoft.EntityFrameworkCore.Metadata.ISqlQueryMapping : Microsoft.EntityFrameworkCore.Metadata.ITableMappingBase, Microsoft.EntityFrameworkCore.Infrastructure.IAnnotatable, Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable, System.IComparable<Microsoft.EntityFrameworkCore.Metadata.ITableMappingBase>",
"Properties": [
{
"Member": "System.Collections.Generic.IEnumerable<Microsoft.EntityFrameworkCore.Metadata.ISqlQueryColumnMapping> ColumnMappings { get; }"
Expand Down Expand Up @@ -6375,7 +6375,7 @@
]
},
{
"Type": "interface Microsoft.EntityFrameworkCore.Metadata.IStoredProcedureMapping : Microsoft.EntityFrameworkCore.Metadata.ITableMappingBase, Microsoft.EntityFrameworkCore.Infrastructure.IAnnotatable, Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable",
"Type": "interface Microsoft.EntityFrameworkCore.Metadata.IStoredProcedureMapping : Microsoft.EntityFrameworkCore.Metadata.ITableMappingBase, Microsoft.EntityFrameworkCore.Infrastructure.IAnnotatable, Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable, System.IComparable<Microsoft.EntityFrameworkCore.Metadata.ITableMappingBase>",
"Properties": [
{
"Member": "System.Collections.Generic.IEnumerable<Microsoft.EntityFrameworkCore.Metadata.IStoredProcedureParameterMapping> ParameterMappings { get; }"
Expand Down Expand Up @@ -6409,7 +6409,7 @@
]
},
{
"Type": "interface Microsoft.EntityFrameworkCore.Metadata.IStoredProcedureParameterMapping : Microsoft.EntityFrameworkCore.Metadata.IColumnMappingBase, Microsoft.EntityFrameworkCore.Infrastructure.IAnnotatable, Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable",
"Type": "interface Microsoft.EntityFrameworkCore.Metadata.IStoredProcedureParameterMapping : Microsoft.EntityFrameworkCore.Metadata.IColumnMappingBase, Microsoft.EntityFrameworkCore.Infrastructure.IAnnotatable, Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable, System.IComparable<Microsoft.EntityFrameworkCore.Metadata.IColumnMappingBase>",
"Methods": [
{
"Member": "string ToDebugString(Microsoft.EntityFrameworkCore.Infrastructure.MetadataDebugStringOptions options = Microsoft.EntityFrameworkCore.Infrastructure.MetadataDebugStringOptions.ShortDefault, int indent = 0);"
Expand Down Expand Up @@ -6439,7 +6439,7 @@
]
},
{
"Type": "interface Microsoft.EntityFrameworkCore.Metadata.IStoredProcedureResultColumnMapping : Microsoft.EntityFrameworkCore.Metadata.IColumnMappingBase, Microsoft.EntityFrameworkCore.Infrastructure.IAnnotatable, Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable",
"Type": "interface Microsoft.EntityFrameworkCore.Metadata.IStoredProcedureResultColumnMapping : Microsoft.EntityFrameworkCore.Metadata.IColumnMappingBase, Microsoft.EntityFrameworkCore.Infrastructure.IAnnotatable, Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable, System.IComparable<Microsoft.EntityFrameworkCore.Metadata.IColumnMappingBase>",
"Methods": [
{
"Member": "string ToDebugString(Microsoft.EntityFrameworkCore.Infrastructure.MetadataDebugStringOptions options = Microsoft.EntityFrameworkCore.Infrastructure.MetadataDebugStringOptions.ShortDefault, int indent = 0);"
Expand Down Expand Up @@ -6728,7 +6728,7 @@
]
},
{
"Type": "interface Microsoft.EntityFrameworkCore.Metadata.ITableMapping : Microsoft.EntityFrameworkCore.Metadata.ITableMappingBase, Microsoft.EntityFrameworkCore.Infrastructure.IAnnotatable, Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable",
"Type": "interface Microsoft.EntityFrameworkCore.Metadata.ITableMapping : Microsoft.EntityFrameworkCore.Metadata.ITableMappingBase, Microsoft.EntityFrameworkCore.Infrastructure.IAnnotatable, Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable, System.IComparable<Microsoft.EntityFrameworkCore.Metadata.ITableMappingBase>",
"Properties": [
{
"Member": "System.Collections.Generic.IEnumerable<Microsoft.EntityFrameworkCore.Metadata.IColumnMapping> ColumnMappings { get; }"
Expand All @@ -6748,7 +6748,7 @@
]
},
{
"Type": "interface Microsoft.EntityFrameworkCore.Metadata.ITableMappingBase : Microsoft.EntityFrameworkCore.Infrastructure.IAnnotatable, Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable",
"Type": "interface Microsoft.EntityFrameworkCore.Metadata.ITableMappingBase : Microsoft.EntityFrameworkCore.Infrastructure.IAnnotatable, Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable, System.IComparable<Microsoft.EntityFrameworkCore.Metadata.ITableMappingBase>",
"Methods": [
{
"Member": "string ToDebugString(Microsoft.EntityFrameworkCore.Infrastructure.MetadataDebugStringOptions options = Microsoft.EntityFrameworkCore.Infrastructure.MetadataDebugStringOptions.ShortDefault, int indent = 0);"
Expand Down Expand Up @@ -6897,7 +6897,7 @@
]
},
{
"Type": "interface Microsoft.EntityFrameworkCore.Metadata.IViewColumnMapping : Microsoft.EntityFrameworkCore.Metadata.IColumnMappingBase, Microsoft.EntityFrameworkCore.Infrastructure.IAnnotatable, Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable",
"Type": "interface Microsoft.EntityFrameworkCore.Metadata.IViewColumnMapping : Microsoft.EntityFrameworkCore.Metadata.IColumnMappingBase, Microsoft.EntityFrameworkCore.Infrastructure.IAnnotatable, Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable, System.IComparable<Microsoft.EntityFrameworkCore.Metadata.IColumnMappingBase>",
"Methods": [
{
"Member": "string ToDebugString(Microsoft.EntityFrameworkCore.Infrastructure.MetadataDebugStringOptions options = Microsoft.EntityFrameworkCore.Infrastructure.MetadataDebugStringOptions.ShortDefault, int indent = 0);"
Expand All @@ -6913,7 +6913,7 @@
]
},
{
"Type": "interface Microsoft.EntityFrameworkCore.Metadata.IViewMapping : Microsoft.EntityFrameworkCore.Metadata.ITableMappingBase, Microsoft.EntityFrameworkCore.Infrastructure.IAnnotatable, Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable",
"Type": "interface Microsoft.EntityFrameworkCore.Metadata.IViewMapping : Microsoft.EntityFrameworkCore.Metadata.ITableMappingBase, Microsoft.EntityFrameworkCore.Infrastructure.IAnnotatable, Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable, System.IComparable<Microsoft.EntityFrameworkCore.Metadata.ITableMappingBase>",
"Properties": [
{
"Member": "System.Collections.Generic.IEnumerable<Microsoft.EntityFrameworkCore.Metadata.IViewColumnMapping> ColumnMappings { get; }"
Expand Down
8 changes: 7 additions & 1 deletion src/EFCore.Relational/Metadata/IColumnMappingBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata;
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see> for more information and examples.
/// </remarks>
public interface IColumnMappingBase : IAnnotatable
public interface IColumnMappingBase : IAnnotatable, IComparable<IColumnMappingBase>
{
/// <summary>
/// Gets the mapped property.
Expand All @@ -30,4 +30,10 @@ public interface IColumnMappingBase : IAnnotatable
/// Gets the containing table mapping.
/// </summary>
ITableMappingBase TableMapping { get; }

/// <summary>
/// Compares the current instance with another object of the same type.
/// </summary>
int IComparable<IColumnMappingBase>.CompareTo(IColumnMappingBase? other)
=> other is null ? 1 : 0;
}
8 changes: 7 additions & 1 deletion src/EFCore.Relational/Metadata/ITableMappingBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata;
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see> for more information and examples.
/// </remarks>
public interface ITableMappingBase : IAnnotatable
public interface ITableMappingBase : IAnnotatable, IComparable<ITableMappingBase>
{
/// <summary>
/// Gets the mapped type base.
Expand Down Expand Up @@ -135,4 +135,10 @@ string ToDebugString(MetadataDebugStringOptions options = MetadataDebugStringOpt

return builder.ToString();
}

/// <summary>
/// Compares the current instance with another object of the same type.
/// </summary>
int IComparable<ITableMappingBase>.CompareTo(ITableMappingBase? other)
=> other is null ? 1 : 0;
}
29 changes: 29 additions & 0 deletions src/EFCore.Relational/Metadata/Internal/ColumnMappingBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,33 @@ ITableMappingBase IColumnMappingBase.TableMapping
[DebuggerStepThrough]
get => TableMapping;
}

/// <inheritdoc />
public virtual int CompareTo(IColumnMappingBase? other)
{
if (ReferenceEquals(this, other))
{
return 0;
}

if (other is null)
{
return 1;
}

var result = other.Property.IsPrimaryKey().CompareTo(Property.IsPrimaryKey());
if (result != 0)
{
return result;
}

result = TableMapping.CompareTo(other.TableMapping);
if (result != 0)
{
return result;
}

result = StringComparer.Ordinal.Compare(Property.Name, other.Property.Name);
return result != 0 ? result : StringComparer.Ordinal.Compare(Column.Name, other.Column.Name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,9 @@ private ColumnMappingBaseComparer()
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public int Compare(IColumnMappingBase? x, IColumnMappingBase? y)
{
if (ReferenceEquals(x, y))
{
return 0;
}

if (x is null)
{
return -1;
}

if (y is null)
{
return 1;
}

var result = y.Property.IsPrimaryKey().CompareTo(x.Property.IsPrimaryKey());
if (result != 0)
{
return result;
}

result = TableMappingBaseComparer.Instance.Compare(x.TableMapping, y.TableMapping);
if (result != 0)
{
return result;
}

result = StringComparer.Ordinal.Compare(x.Property.Name, y.Property.Name);
return result != 0 ? result : StringComparer.Ordinal.Compare(x.Column.Name, y.Column.Name);
}
=> x is null
? y is null ? 0 : -1
: y is null ? 1 : x.CompareTo(y);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
67 changes: 67 additions & 0 deletions src/EFCore.Relational/Metadata/Internal/FunctionMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,71 @@ IEnumerable<IFunctionColumnMapping> IFunctionMapping.ColumnMappings
[DebuggerStepThrough]
get => ColumnMappings;
}

/// <inheritdoc />
protected override int CompareTableDetails(ITableMappingBase other)
{
if (other is not IFunctionMapping otherFunctionMapping)
{
return 1;
}

if (Table is StoreFunction storeFunction
&& otherFunctionMapping.Table is StoreFunction otherStoreFunction)
{
var xParams = storeFunction.Parameters;
var yParams = otherStoreFunction.Parameters;
var result = xParams.Length.CompareTo(yParams.Length);
if (result != 0)
{
return result;
}

for (var i = 0; i < xParams.Length; i++)
{
var xp = xParams[i];
var yp = yParams[i];
result = StringComparer.Ordinal.Compare(xp.StoreType, yp.StoreType);
if (result != 0)
{
return result;
}

result = StringComparer.Ordinal.Compare(xp.Name, yp.Name);
if (result != 0)
{
return result;
}
}

return 0;
}

var xList = StoreFunction.Parameters.ToList();
var yList = otherFunctionMapping.StoreFunction.Parameters.ToList();
var countResult = xList.Count.CompareTo(yList.Count);
if (countResult != 0)
{
return countResult;
}

for (var i = 0; i < xList.Count; i++)
{
var xp = xList[i];
var yp = yList[i];
var result = StringComparer.Ordinal.Compare(xp.StoreType, yp.StoreType);
if (result != 0)
{
return result;
}

result = StringComparer.Ordinal.Compare(xp.Name, yp.Name);
if (result != 0)
{
return result;
}
}

return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,45 @@ IEnumerable<IStoredProcedureParameterMapping> IStoredProcedureMapping.ParameterM
[DebuggerStepThrough]
get => ParameterMappings;
}

/// <inheritdoc />
protected override int CompareTableDetails(ITableMappingBase other)
{
if (other is IFunctionMapping)
{
return -1;
}

if (other is not IStoredProcedureMapping otherSprocMapping)
{
return 1;
}

var xSproc = StoreStoredProcedure;
var ySproc = otherSprocMapping.StoreStoredProcedure;
var result = xSproc.Parameters.Count.CompareTo(ySproc.Parameters.Count);
if (result != 0)
{
return result;
}

for (var i = 0; i < xSproc.Parameters.Count; i++)
{
var xp = xSproc.Parameters[i];
var yp = ySproc.Parameters[i];
result = StringComparer.Ordinal.Compare(xp.StoreType, yp.StoreType);
if (result != 0)
{
return result;
}

result = StringComparer.Ordinal.Compare(xp.Name, yp.Name);
if (result != 0)
{
return result;
}
}

return 0;
}
}
Loading
Loading