Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup Relational for internal API usage #20398

Merged
merged 1 commit into from
Mar 25, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Design.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations.Operations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Collections.Generic;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations.Operations;

namespace Microsoft.EntityFrameworkCore.Migrations.Design
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;

namespace Microsoft.EntityFrameworkCore.Migrations.Design
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Design.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
Expand Down
1 change: 1 addition & 0 deletions src/EFCore.Relational/EFCore.Relational.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<ItemGroup>
<ProjectReference Include="..\EFCore\EFCore.csproj" PrivateAssets="contentfiles;build" />
<ProjectReference Include="..\EFCore.Analyzers\EFCore.Analyzers.csproj" ReferenceOutputAssembly="False" OutputItemType="Analyzer" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,14 @@ public static int ExecuteSqlRaw(
Check.NotNull(parameters, nameof(parameters));

var facadeDependencies = GetFacadeDependencies(databaseFacade);
#pragma warning disable EF1001 // Internal EF Core API usage.
var concurrencyDetector = facadeDependencies.ConcurrencyDetector;
var logger = facadeDependencies.CommandLogger;
#pragma warning restore EF1001 // Internal EF Core API usage.

using (concurrencyDetector.EnterCriticalSection())
{
var rawSqlCommand = GetFacadeDependencies(databaseFacade).RawSqlCommandBuilder
var rawSqlCommand = facadeDependencies.RawSqlCommandBuilder
.Build(sql, parameters);

return rawSqlCommand
Expand All @@ -218,7 +220,9 @@ public static int ExecuteSqlRaw(
facadeDependencies.RelationalConnection,
rawSqlCommand.ParameterValues,
null,
#pragma warning disable EF1001 // Internal EF Core API usage.
((IDatabaseFacadeDependenciesAccessor)databaseFacade).Context,
#pragma warning restore EF1001 // Internal EF Core API usage.
logger));
}
}
Expand Down Expand Up @@ -356,12 +360,14 @@ public static async Task<int> ExecuteSqlRawAsync(
Check.NotNull(parameters, nameof(parameters));

var facadeDependencies = GetFacadeDependencies(databaseFacade);
#pragma warning disable EF1001 // Internal EF Core API usage.
var concurrencyDetector = facadeDependencies.ConcurrencyDetector;
var logger = facadeDependencies.CommandLogger;
#pragma warning restore EF1001 // Internal EF Core API usage.

using (concurrencyDetector.EnterCriticalSection())
{
var rawSqlCommand = GetFacadeDependencies(databaseFacade).RawSqlCommandBuilder
var rawSqlCommand = facadeDependencies.RawSqlCommandBuilder
.Build(sql, parameters);

return await rawSqlCommand
Expand All @@ -371,7 +377,9 @@ public static async Task<int> ExecuteSqlRawAsync(
facadeDependencies.RelationalConnection,
rawSqlCommand.ParameterValues,
null,
#pragma warning disable EF1001 // Internal EF Core API usage.
((IDatabaseFacadeDependenciesAccessor)databaseFacade).Context,
#pragma warning restore EF1001 // Internal EF Core API usage.
logger),
cancellationToken);
}
Expand Down Expand Up @@ -612,11 +620,15 @@ public static string GenerateCreateScript([NotNull] this DatabaseFacade database
/// <param name="databaseFacade"> The facade from <see cref="DbContext.Database" />. </param>
/// <returns> True if a relational database provider is being used; false otherwise. </returns>
public static bool IsRelational([NotNull] this DatabaseFacade databaseFacade)
#pragma warning disable EF1001 // Internal EF Core API usage.
=> ((IDatabaseFacadeDependenciesAccessor)Check.NotNull(databaseFacade, nameof(databaseFacade))).Dependencies is IRelationalDatabaseFacadeDependencies;
#pragma warning restore EF1001 // Internal EF Core API usage.

private static IRelationalDatabaseFacadeDependencies GetFacadeDependencies(DatabaseFacade databaseFacade)
{
#pragma warning disable EF1001 // Internal EF Core API usage.
var dependencies = ((IDatabaseFacadeDependenciesAccessor)databaseFacade).Dependencies;
#pragma warning restore EF1001 // Internal EF Core API usage.

if (dependencies is IRelationalDatabaseFacadeDependencies relationalDependencies)
{
Expand All @@ -640,6 +652,8 @@ private static TService GetRelationalService<TService>(this IInfrastructure<ISer
}

private static IDbContextTransactionManager GetTransactionManager([NotNull] this DatabaseFacade databaseFacade)
#pragma warning disable EF1001 // Internal EF Core API usage.
=> ((IDatabaseFacadeDependenciesAccessor)Check.NotNull(databaseFacade, nameof(databaseFacade))).Dependencies.TransactionManager;
#pragma warning restore EF1001 // Internal EF Core API usage.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

namespace Microsoft.EntityFrameworkCore.Internal
{
#pragma warning disable EF1001 // Internal EF Core API usage.
public class RelationalDatabaseFacadeDependencies : DatabaseFacadeDependencies, IRelationalDatabaseFacadeDependencies
#pragma warning restore EF1001 // Internal EF Core API usage.
{
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;

Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Metadata/ITable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore.Metadata
{
Expand Down
1 change: 1 addition & 0 deletions src/EFCore.Relational/Metadata/Internal/CheckConstraint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore.Metadata.Internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public int Compare(IColumnMappingBase x, IColumnMappingBase y)
return result;
}

#pragma warning disable EF1001 // Internal EF Core API usage.
result = EntityTypePathComparer.Instance.Compare(x.Property.DeclaringEntityType, y.Property.DeclaringEntityType);
#pragma warning restore EF1001 // Internal EF Core API usage.
if (result != 0)
{
return result;
Expand Down Expand Up @@ -88,7 +90,9 @@ public int GetHashCode(IColumnMappingBase obj)
var hashCode = new HashCode();
hashCode.Add(obj.Property.Name);
hashCode.Add(obj.Column.Name);
#pragma warning disable EF1001 // Internal EF Core API usage.
hashCode.Add(obj.Property.DeclaringEntityType, EntityTypePathComparer.Instance);
#pragma warning restore EF1001 // Internal EF Core API usage.
hashCode.Add(obj.Column.Table.Name);
hashCode.Add(obj.Column.Table.Schema);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public ForeignKeyConstraint(
/// 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>
#pragma warning disable EF1001 // Internal EF Core API usage.
public virtual SortedSet<IForeignKey> MappedForeignKeys { get; } = new SortedSet<IForeignKey>(ForeignKeyComparer.Instance);
#pragma warning restore EF1001 // Internal EF Core API usage.

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
10 changes: 10 additions & 0 deletions src/EFCore.Relational/Metadata/Internal/RelationalModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -486,20 +486,26 @@ private static void PopulateInternalForeignKeys(TableBase table)
{
if (internalForeignKeys == null)
{
#pragma warning disable EF1001 // Internal EF Core API usage.
internalForeignKeys = new SortedSet<IForeignKey>(ForeignKeyComparer.Instance);
#pragma warning restore EF1001 // Internal EF Core API usage.
}
internalForeignKeys.Add(foreignKey);

if (referencingInternalForeignKeyMap == null)
{
referencingInternalForeignKeyMap =
#pragma warning disable EF1001 // Internal EF Core API usage.
new SortedDictionary<IEntityType, IEnumerable<IForeignKey>>(EntityTypePathComparer.Instance);
#pragma warning restore EF1001 // Internal EF Core API usage.
}

var principalEntityType = foreignKey.PrincipalEntityType;
if (!referencingInternalForeignKeyMap.TryGetValue(principalEntityType, out var internalReferencingForeignKeys))
{
#pragma warning disable EF1001 // Internal EF Core API usage.
internalReferencingForeignKeys = new SortedSet<IForeignKey>(ForeignKeyComparer.Instance);
#pragma warning restore EF1001 // Internal EF Core API usage.
referencingInternalForeignKeyMap[principalEntityType] = internalReferencingForeignKeys;
}
((SortedSet<IForeignKey>)internalReferencingForeignKeys).Add(foreignKey);
Expand All @@ -511,7 +517,9 @@ private static void PopulateInternalForeignKeys(TableBase table)
if (internalForeignKeyMap == null)
{
internalForeignKeyMap =
#pragma warning disable EF1001 // Internal EF Core API usage.
new SortedDictionary<IEntityType, IEnumerable<IForeignKey>>(EntityTypePathComparer.Instance);
#pragma warning restore EF1001 // Internal EF Core API usage.
table.InternalForeignKeys = internalForeignKeyMap;
}

Expand Down Expand Up @@ -558,7 +566,9 @@ private static ReferentialAction ToReferentialAction(DeleteBehavior deleteBehavi
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual DebugView DebugView
#pragma warning disable EF1001 // Internal EF Core API usage.
=> new DebugView(
#pragma warning restore EF1001 // Internal EF Core API usage.
() => this.ToDebugString(MetadataDebugStringOptions.ShortDefault),
() => this.ToDebugString(MetadataDebugStringOptions.LongDefault));

Expand Down
1 change: 1 addition & 0 deletions src/EFCore.Relational/Metadata/Internal/Sequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Text;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Utilities;

Expand Down
2 changes: 2 additions & 0 deletions src/EFCore.Relational/Metadata/Internal/TableIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public TableIndex(
/// 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>
#pragma warning disable EF1001 // Internal EF Core API usage.
public virtual SortedSet<IIndex> MappedIndexes { get; } = new SortedSet<IIndex>(IndexComparer.Instance);
#pragma warning restore EF1001 // Internal EF Core API usage.

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ private TableMappingBaseComparer()
/// </summary>
public int Compare(ITableMappingBase x, ITableMappingBase y)
{
#pragma warning disable EF1001 // Internal EF Core API usage.
var result = EntityTypePathComparer.Instance.Compare(x.EntityType, y.EntityType);
#pragma warning restore EF1001 // Internal EF Core API usage.
if (result != 0)
{
return result;
Expand Down Expand Up @@ -95,7 +97,9 @@ public bool Equals(ITableMappingBase x, ITableMappingBase y)
public int GetHashCode(ITableMappingBase obj)
{
var hashCode = new HashCode();
#pragma warning disable EF1001 // Internal EF Core API usage.
hashCode.Add(obj.EntityType, EntityTypePathComparer.Instance);
#pragma warning restore EF1001 // Internal EF Core API usage.
hashCode.Add(obj.Table.Name);
hashCode.Add(obj.Table.Schema);
foreach (var columnMapping in obj.ColumnMappings)
Expand Down
2 changes: 2 additions & 0 deletions src/EFCore.Relational/Metadata/Internal/UniqueConstraint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public UniqueConstraint(
/// 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>
#pragma warning disable EF1001 // Internal EF Core API usage.
public virtual SortedSet<IKey> MappedKeys { get; } = new SortedSet<IKey>(KeyComparer.Instance);
#pragma warning restore EF1001 // Internal EF Core API usage.

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,9 @@ private static string GetDefiningNavigationName(IEntityType entityType)
return entityType.DefiningNavigationName;
}

#pragma warning disable EF1001 // Internal EF Core API usage.
var primaryKey = entityType.FindDeclaredPrimaryKey();
#pragma warning restore EF1001 // Internal EF Core API usage.
if (primaryKey != null)
{
var definingForeignKey = entityType
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,7 @@ protected virtual bool HasLegacyRenameOperations([CanBeNull] IModel model)
/// <returns> True if the version could be retrieved. </returns>
protected virtual bool TryGetVersion([CanBeNull] IModel model, out string version)
{
if (!(model?[CoreAnnotationNames.ProductVersion] is string versionString))
if (!(model?.GetProductVersion() is string versionString))
{
version = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Reflection;
using System.Text;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Utilities;

namespace Microsoft.EntityFrameworkCore.Storage.Internal
{
Expand Down
1 change: 1 addition & 0 deletions src/EFCore.Relational/Storage/RelationalCommandBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Collections.Generic;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Utilities;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ public RelationalExecutionStrategyFactory([NotNull] ExecutionStrategyDependencie
/// current database provider.
/// </summary>
protected virtual IExecutionStrategy CreateDefaultStrategy([NotNull] ExecutionStrategyDependencies dependencies)
#pragma warning disable EF1001 // Internal EF Core API usage.
=> new NoopExecutionStrategy(Dependencies);
#pragma warning restore EF1001 // Internal EF Core API usage.

/// <summary>
/// Creates an <see cref="IExecutionStrategy" /> for the current database provider.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.EntityFrameworkCore.Update.Internal
Expand Down Expand Up @@ -455,7 +456,7 @@ private void Format(IIndex index, ModificationCommand source, ModificationComman
// Builds a map from foreign key values to list of modification commands, with an entry for every command
// that may need to precede some other command involving that foreign key value.
private Dictionary<IKeyValueIndex, List<ModificationCommand>> CreateKeyValuePredecessorMap(
Graph<ModificationCommand> commandGraph)
Multigraph<ModificationCommand, IAnnotatable> commandGraph)
{
var predecessorsMap = new Dictionary<IKeyValueIndex, List<ModificationCommand>>();
foreach (var command in commandGraph.Vertices)
Expand Down Expand Up @@ -653,15 +654,19 @@ private void AddUniqueValueEdges(Multigraph<ModificationCommand, IAnnotatable> c
}
}

#pragma warning disable EF1001 // Internal EF Core API usage.
var valueFactory = index.GetNullableValueFactory<object[]>();
if (valueFactory.TryCreateFromOriginalValues(
(InternalEntityEntry)entry, out var indexValue))
#pragma warning restore EF1001 // Internal EF Core API usage.
{
predecessorsMap ??= new Dictionary<IIndex, Dictionary<object[], ModificationCommand>>();
if (!predecessorsMap.TryGetValue(index, out var predecessorCommands))
{
predecessorCommands =
#pragma warning disable EF1001 // Internal EF Core API usage.
new Dictionary<object[], ModificationCommand>(valueFactory.EqualityComparer);
#pragma warning restore EF1001 // Internal EF Core API usage.
predecessorsMap.Add(index, predecessorCommands);
}

Expand Down Expand Up @@ -696,8 +701,10 @@ private void AddUniqueValueEdges(Multigraph<ModificationCommand, IAnnotatable> c
if (command.EntityState == EntityState.Added
|| indexColumnModifications.Any())
{
#pragma warning disable EF1001 // Internal EF Core API usage.
var valueFactory = index.GetNullableValueFactory<object[]>();
if (valueFactory.TryCreateFromCurrentValues((InternalEntityEntry)entry, out var indexValue)
#pragma warning restore EF1001 // Internal EF Core API usage.
&& predecessorsMap.TryGetValue(index, out var predecessorCommands)
&& predecessorCommands.TryGetValue(indexValue, out var predecessor)
&& predecessor != command)
Expand Down
Loading