-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ForeignKeyConstraint to the relational model.
Part of #12846
- Loading branch information
1 parent
725adf7
commit dfbf480
Showing
23 changed files
with
643 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Metadata | ||
{ | ||
/// <summary> | ||
/// Represents a foreign key constraint. | ||
/// </summary> | ||
public interface IForeignKeyConstraint : IAnnotatable | ||
{ | ||
/// <summary> | ||
/// The name of the foreign key constraint. | ||
/// </summary> | ||
string Name { get; } | ||
|
||
/// <summary> | ||
/// The mapped foreign keys. | ||
/// </summary> | ||
IEnumerable<IForeignKey> MappedForeignKeys { get; } | ||
|
||
/// <summary> | ||
/// The table on with the foreign key constraint is declared. | ||
/// </summary> | ||
ITable Table { get; } | ||
|
||
/// <summary> | ||
/// The table that is referenced by the foreign key constraint. | ||
/// </summary> | ||
ITable PrincipalTable { get; } | ||
|
||
/// <summary> | ||
/// The columns that are participating in the foreign key constraint. | ||
/// </summary> | ||
IReadOnlyList<IColumn> Columns { get; } | ||
|
||
/// <summary> | ||
/// The columns that are referenced by the foreign key constraint. | ||
/// </summary> | ||
IReadOnlyList<IColumn> PrincipalColumns { get; } | ||
|
||
/// <summary> | ||
/// The action to be performed when the referenced row is deleted. | ||
/// </summary> | ||
ReferentialAction OnDeleteAction { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/EFCore.Relational/Metadata/Internal/ColumnListComparer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Metadata.Internal | ||
{ | ||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
// Sealed for perf | ||
public sealed class ColumnListComparer : IComparer<IReadOnlyList<IColumn>>, IEqualityComparer<IReadOnlyList<IColumn>> | ||
{ | ||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public static readonly ColumnListComparer Instance = new ColumnListComparer(); | ||
|
||
private ColumnListComparer() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public int Compare(IReadOnlyList<IColumn> x, IReadOnlyList<IColumn> y) | ||
{ | ||
var result = x.Count - y.Count; | ||
|
||
if (result != 0) | ||
{ | ||
return result; | ||
} | ||
|
||
var index = 0; | ||
while ((result == 0) | ||
&& (index < x.Count)) | ||
{ | ||
result = StringComparer.Ordinal.Compare(x[index].Name, y[index].Name); | ||
index++; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public bool Equals(IReadOnlyList<IColumn> x, IReadOnlyList<IColumn> y) | ||
=> Compare(x, y) == 0; | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public int GetHashCode(IReadOnlyList<IColumn> obj) | ||
{ | ||
var hash = new HashCode(); | ||
for (var i = 0; i < obj.Count; i++) | ||
{ | ||
hash.Add(obj[i]); | ||
} | ||
|
||
return hash.ToHashCode(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.