From 1fc59049e1c940f2ac3d2e8a23ee31711404ec9a Mon Sep 17 00:00:00 2001 From: Arthur Vickers Date: Tue, 7 Apr 2020 13:19:44 -0700 Subject: [PATCH] Enable internal code usage analyzer on the providers Fixes #15393 --- src/EFCore.Cosmos/EFCore.Cosmos.csproj | 1 + ...jectionBindingRemovingExpressionVisitor.cs | 15 ++++ .../Storage/Internal/CosmosDatabaseWrapper.cs | 12 ++++ .../Update/Internal/DocumentSource.cs | 23 +++++- src/EFCore.InMemory/EFCore.InMemory.csproj | 1 + ...yableMethodTranslatingExpressionVisitor.cs | 3 + src/EFCore.Proxies/EFCore.Proxies.csproj | 1 + .../Internal/PropertyChangedInterceptor.cs | 4 +- .../Internal/PropertyChangingInterceptor.cs | 4 +- .../Proxies/Internal/ProxyBindingRewriter.cs | 8 +++ .../Internal/ProxyChangeTrackingConvention.cs | 2 + .../EFCore.Relational.csproj | 2 +- .../RelationalExpressionExtensions.cs | 30 -------- .../Query/ExpressionExtensions.cs | 6 ++ .../EFCore.SqlServer.NTS.csproj | 1 + src/EFCore.SqlServer/EFCore.SqlServer.csproj | 1 + ...rchConditionConvertingExpressionVisitor.cs | 1 - .../EFCore.Sqlite.Core.csproj | 1 + .../Internal/SqliteLoggerExtensions.cs | 6 +- .../EFCore.Sqlite.NTS.csproj | 1 + ...ySuiteDbContextOptionsBuilderExtensions.cs | 3 + src/EFCore.Sqlite/EFCore.Sqlite.csproj | 1 + src/EFCore/EFCore.csproj | 2 +- src/EFCore/Extensions/PropertyExtensions.cs | 70 +++++++------------ src/EFCore/Infrastructure/ModelValidator.cs | 3 +- .../Metadata/Internal/EntityTypeExtensions.cs | 2 +- .../Metadata/Internal/PropertyExtensions.cs | 13 +--- src/EFCore/Storage/TypeMappingInfo.cs | 3 +- 28 files changed, 120 insertions(+), 100 deletions(-) delete mode 100644 src/EFCore.Relational/Extensions/Internal/RelationalExpressionExtensions.cs diff --git a/src/EFCore.Cosmos/EFCore.Cosmos.csproj b/src/EFCore.Cosmos/EFCore.Cosmos.csproj index 15e577e056b..039a3d58f05 100644 --- a/src/EFCore.Cosmos/EFCore.Cosmos.csproj +++ b/src/EFCore.Cosmos/EFCore.Cosmos.csproj @@ -17,6 +17,7 @@ + diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.CosmosProjectionBindingRemovingExpressionVisitor.cs b/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.CosmosProjectionBindingRemovingExpressionVisitor.cs index b764af30792..517ca013c26 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.CosmosProjectionBindingRemovingExpressionVisitor.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.CosmosProjectionBindingRemovingExpressionVisitor.cs @@ -365,9 +365,12 @@ private void AddInclude( var includeMethod = navigation.IsCollection ? _includeCollectionMethodInfo : _includeReferenceMethodInfo; var includingClrType = navigation.DeclaringEntityType.ClrType; var relatedEntityClrType = navigation.TargetEntityType.ClrType; +#pragma warning disable EF1001 // Internal EF Core API usage. + // #16707 var entityEntryVariable = _trackQueryResults ? shaperBlock.Variables.Single(v => v.Type == typeof(InternalEntityEntry)) : (Expression)Expression.Constant(null, typeof(InternalEntityEntry)); +#pragma warning restore EF1001 // Internal EF Core API usage. var concreteEntityTypeVariable = shaperBlock.Variables.Single(v => v.Type == typeof(IEntityType)); var inverseNavigation = navigation.Inverse; var fixup = GenerateFixup( @@ -394,7 +397,10 @@ private static readonly MethodInfo _includeReferenceMethodInfo .GetDeclaredMethod(nameof(IncludeReference)); private static void IncludeReference( +#pragma warning disable EF1001 // Internal EF Core API usage. + // #16707 InternalEntityEntry entry, +#pragma warning restore EF1001 // Internal EF Core API usage. object entity, IEntityType entityType, TIncludedEntity relatedEntity, @@ -426,7 +432,10 @@ private static void IncludeReference( // For non-null relatedEntity StateManager will set the flag else if (relatedEntity == null) { +#pragma warning disable EF1001 // Internal EF Core API usage. + // #16707 entry.SetIsLoaded(navigation); +#pragma warning restore EF1001 // Internal EF Core API usage. } } @@ -435,7 +444,10 @@ private static readonly MethodInfo _includeCollectionMethodInfo .GetDeclaredMethod(nameof(IncludeCollection)); private static void IncludeCollection( +#pragma warning disable EF1001 // Internal EF Core API usage. + // #16707 InternalEntityEntry entry, +#pragma warning restore EF1001 // Internal EF Core API usage. object entity, IEntityType entityType, IEnumerable relatedEntities, @@ -473,7 +485,10 @@ private static void IncludeCollection( } else { +#pragma warning disable EF1001 // Internal EF Core API usage. + // #16707 entry.SetIsLoaded(navigation); +#pragma warning restore EF1001 // Internal EF Core API usage. if (relatedEntities != null) { using var enumerator = relatedEntities.GetEnumerator(); diff --git a/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseWrapper.cs b/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseWrapper.cs index bde693d463b..2964ae28b0f 100644 --- a/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseWrapper.cs +++ b/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseWrapper.cs @@ -88,12 +88,18 @@ public override int SaveChanges(IList entries) if (!entityType.IsDocumentRoot()) { +#pragma warning disable EF1001 // Internal EF Core API usage. + // #16707 var root = GetRootDocument((InternalEntityEntry)entry); +#pragma warning restore EF1001 // Internal EF Core API usage. if (!entriesSaved.Contains(root) && rootEntriesToSave.Add(root) && root.EntityState == EntityState.Unchanged) { +#pragma warning disable EF1001 // Internal EF Core API usage. + // #16707 ((InternalEntityEntry)root).SetEntityState(EntityState.Modified); +#pragma warning restore EF1001 // Internal EF Core API usage. } continue; @@ -154,7 +160,10 @@ public override async Task SaveChangesAsync( && rootEntriesToSave.Add(root) && root.EntityState == EntityState.Unchanged) { +#pragma warning disable EF1001 // Internal EF Core API usage. + // #16707 ((InternalEntityEntry)root).SetEntityState(EntityState.Modified); +#pragma warning restore EF1001 // Internal EF Core API usage. } continue; @@ -325,6 +334,8 @@ public virtual DocumentSource GetDocumentSource([NotNull] IEntityType entityType return documentSource; } +#pragma warning disable EF1001 // Internal EF Core API usage. + // #16707 private IUpdateEntry GetRootDocument(InternalEntityEntry entry) { var stateManager = entry.StateManager; @@ -349,6 +360,7 @@ private IUpdateEntry GetRootDocument(InternalEntityEntry entry) return principal.EntityType.IsDocumentRoot() ? principal : GetRootDocument(principal); } +#pragma warning restore EF1001 // Internal EF Core API usage. private Exception ThrowUpdateException(CosmosException exception, IUpdateEntry entry) { diff --git a/src/EFCore.Cosmos/Update/Internal/DocumentSource.cs b/src/EFCore.Cosmos/Update/Internal/DocumentSource.cs index 426766649ef..0fe390110c7 100644 --- a/src/EFCore.Cosmos/Update/Internal/DocumentSource.cs +++ b/src/EFCore.Cosmos/Update/Internal/DocumentSource.cs @@ -112,8 +112,11 @@ public virtual JObject CreateDocument([NotNull] IUpdateEntry entry, int? ordinal } else if (fk.IsUnique) { +#pragma warning disable EF1001 // Internal EF Core API usage. + // #16707 var dependentEntry = ((InternalEntityEntry)entry).StateManager.TryGetEntry(embeddedValue, fk.DeclaringEntityType); document[embeddedPropertyName] = _database.GetDocumentSource(dependentEntry.EntityType).CreateDocument(dependentEntry); +#pragma warning restore EF1001 // Internal EF Core API usage. } else { @@ -121,8 +124,11 @@ public virtual JObject CreateDocument([NotNull] IUpdateEntry entry, int? ordinal var array = new JArray(); foreach (var dependent in (IEnumerable)embeddedValue) { +#pragma warning disable EF1001 // Internal EF Core API usage. + // #16707 var dependentEntry = ((InternalEntityEntry)entry).StateManager.TryGetEntry(dependent, fk.DeclaringEntityType); array.Add(_database.GetDocumentSource(dependentEntry.EntityType).CreateDocument(dependentEntry, embeddedOrdinal)); +#pragma warning restore EF1001 // Internal EF Core API usage. embeddedOrdinal++; } @@ -141,7 +147,7 @@ public virtual JObject CreateDocument([NotNull] IUpdateEntry entry, int? ordinal /// public virtual JObject UpdateDocument([NotNull] JObject document, [NotNull] IUpdateEntry entry) => UpdateDocument(document, entry, null); - + /// /// 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 @@ -151,7 +157,10 @@ public virtual JObject UpdateDocument([NotNull] JObject document, [NotNull] IUpd public virtual JObject UpdateDocument([NotNull] JObject document, [NotNull] IUpdateEntry entry, int? ordinal) { var anyPropertyUpdated = false; +#pragma warning disable EF1001 // Internal EF Core API usage. + // #16707 var stateManager = ((InternalEntityEntry)entry).StateManager; +#pragma warning restore EF1001 // Internal EF Core API usage. foreach (var property in entry.EntityType.GetProperties()) { if (entry.EntityState == EntityState.Added @@ -196,7 +205,10 @@ public virtual JObject UpdateDocument([NotNull] JObject document, [NotNull] IUpd } else if (fk.IsUnique) { +#pragma warning disable EF1001 // Internal EF Core API usage. + // #16707 var embeddedEntry = ((InternalEntityEntry)entry).StateManager.TryGetEntry(embeddedValue, fk.DeclaringEntityType); +#pragma warning restore EF1001 // Internal EF Core API usage. if (embeddedEntry == null) { continue; @@ -222,6 +234,8 @@ public virtual JObject UpdateDocument([NotNull] JObject document, [NotNull] IUpd var shouldSetTemporaryKeys = false; foreach (var dependent in (IEnumerable)embeddedValue) { +#pragma warning disable EF1001 // Internal EF Core API usage. + // #16707 var embeddedEntry = stateManager.TryGetEntry(dependent, fk.DeclaringEntityType); if (embeddedEntry == null) { @@ -233,6 +247,7 @@ public virtual JObject UpdateDocument([NotNull] JObject document, [NotNull] IUpd shouldSetTemporaryKeys = true; break; } +#pragma warning restore EF1001 // Internal EF Core API usage. embeddedOrdinal++; } @@ -242,6 +257,8 @@ public virtual JObject UpdateDocument([NotNull] JObject document, [NotNull] IUpd var temporaryOrdinal = -1; foreach (var dependent in (IEnumerable)embeddedValue) { +#pragma warning disable EF1001 // Internal EF Core API usage. + // #16707 var embeddedEntry = stateManager.TryGetEntry(dependent, fk.DeclaringEntityType); if (embeddedEntry == null) { @@ -249,6 +266,7 @@ public virtual JObject UpdateDocument([NotNull] JObject document, [NotNull] IUpd } embeddedEntry.SetTemporaryValue(ordinalKeyProperty, temporaryOrdinal, setModified: false); +#pragma warning restore EF1001 // Internal EF Core API usage. temporaryOrdinal--; } @@ -259,7 +277,10 @@ public virtual JObject UpdateDocument([NotNull] JObject document, [NotNull] IUpd var array = new JArray(); foreach (var dependent in (IEnumerable)embeddedValue) { +#pragma warning disable EF1001 // Internal EF Core API usage. + // #16707 var embeddedEntry = ((InternalEntityEntry)entry).StateManager.TryGetEntry(dependent, fk.DeclaringEntityType); +#pragma warning restore EF1001 // Internal EF Core API usage. if (embeddedEntry == null) { continue; diff --git a/src/EFCore.InMemory/EFCore.InMemory.csproj b/src/EFCore.InMemory/EFCore.InMemory.csproj index d5fa1fe00df..d34bb4da013 100644 --- a/src/EFCore.InMemory/EFCore.InMemory.csproj +++ b/src/EFCore.InMemory/EFCore.InMemory.csproj @@ -17,6 +17,7 @@ + diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs index 74da00424e6..d5cc97bb56c 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs @@ -459,7 +459,10 @@ private static (Expression, Expression) DecomposeJoinCondition(Expression joinCo // InMemory joins need to use AnonymousObject to perform correct key comparison for server side joins static Expression CreateAnonymousObject(List expressions) => Expression.New( +#pragma warning disable EF1001 // Internal EF Core API usage. + // #20565 AnonymousObject.AnonymousObjectCtor, +#pragma warning restore EF1001 // Internal EF Core API usage. Expression.NewArrayInit( typeof(object), expressions.Select(e => Expression.Convert(e, typeof(object))))); diff --git a/src/EFCore.Proxies/EFCore.Proxies.csproj b/src/EFCore.Proxies/EFCore.Proxies.csproj index 7821e805ec0..c148cb25b5d 100644 --- a/src/EFCore.Proxies/EFCore.Proxies.csproj +++ b/src/EFCore.Proxies/EFCore.Proxies.csproj @@ -21,6 +21,7 @@ + diff --git a/src/EFCore.Proxies/Proxies/Internal/PropertyChangedInterceptor.cs b/src/EFCore.Proxies/Proxies/Internal/PropertyChangedInterceptor.cs index eb02368a6f5..22cf8f29867 100644 --- a/src/EFCore.Proxies/Proxies/Internal/PropertyChangedInterceptor.cs +++ b/src/EFCore.Proxies/Proxies/Internal/PropertyChangedInterceptor.cs @@ -8,7 +8,6 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Metadata.Internal; namespace Microsoft.EntityFrameworkCore.Proxies.Internal { @@ -70,7 +69,8 @@ public virtual void Intercept(IInvocation invocation) var property = _entityType.FindProperty(propertyName); if (property != null) { - var comparer = property.IsKeyOrForeignKey() + var comparer = property.IsKey() + || property.IsForeignKey() ? property.GetKeyValueComparer() : property.GetValueComparer(); diff --git a/src/EFCore.Proxies/Proxies/Internal/PropertyChangingInterceptor.cs b/src/EFCore.Proxies/Proxies/Internal/PropertyChangingInterceptor.cs index dc2ffd19018..ebd9dacfeb7 100644 --- a/src/EFCore.Proxies/Proxies/Internal/PropertyChangingInterceptor.cs +++ b/src/EFCore.Proxies/Proxies/Internal/PropertyChangingInterceptor.cs @@ -8,7 +8,6 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Metadata.Internal; namespace Microsoft.EntityFrameworkCore.Proxies.Internal { @@ -70,7 +69,8 @@ public virtual void Intercept(IInvocation invocation) var property = _entityType.FindProperty(propertyName); if (property != null) { - var comparer = property.IsKeyOrForeignKey() + var comparer = property.IsKey() + || property.IsForeignKey() ? property.GetKeyValueComparer() : property.GetValueComparer(); diff --git a/src/EFCore.Proxies/Proxies/Internal/ProxyBindingRewriter.cs b/src/EFCore.Proxies/Proxies/Internal/ProxyBindingRewriter.cs index 8fda79e6570..309dd0a2b5b 100644 --- a/src/EFCore.Proxies/Proxies/Internal/ProxyBindingRewriter.cs +++ b/src/EFCore.Proxies/Proxies/Internal/ProxyBindingRewriter.cs @@ -73,14 +73,18 @@ public virtual void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, var proxyType = _proxyFactory.CreateProxyType(_options, entityType); // WARNING: This code is EF internal; it should not be copied. See #10789 #14554 +#pragma warning disable EF1001 // Internal EF Core API usage. var binding = (InstantiationBinding)entityType[CoreAnnotationNames.ConstructorBinding]; +#pragma warning restore EF1001 // Internal EF Core API usage. if (binding == null) { _directBindingConvention.ProcessModelFinalizing(modelBuilder, context); } // WARNING: This code is EF internal; it should not be copied. See #10789 #14554 +#pragma warning disable EF1001 // Internal EF Core API usage. binding = (InstantiationBinding)entityType[CoreAnnotationNames.ConstructorBinding]; +#pragma warning restore EF1001 // Internal EF Core API usage. if (_options.UseLazyLoadingProxies) { @@ -106,7 +110,9 @@ public virtual void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, entityType.SetAnnotation( // WARNING: This code is EF internal; it should not be copied. See #10789 #14554 +#pragma warning disable EF1001 // Internal EF Core API usage. CoreAnnotationNames.ConstructorBinding, +#pragma warning restore EF1001 // Internal EF Core API usage. new FactoryMethodBinding( _proxyFactory, _createLazyLoadingProxyMethod, @@ -123,7 +129,9 @@ public virtual void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, { entityType.SetAnnotation( // WARNING: This code is EF internal; it should not be copied. See #10789 #14554 +#pragma warning disable EF1001 // Internal EF Core API usage. CoreAnnotationNames.ConstructorBinding, +#pragma warning restore EF1001 // Internal EF Core API usage. new FactoryMethodBinding( _proxyFactory, _createProxyMethod, diff --git a/src/EFCore.Proxies/Proxies/Internal/ProxyChangeTrackingConvention.cs b/src/EFCore.Proxies/Proxies/Internal/ProxyChangeTrackingConvention.cs index bcf2ccbff33..37d91b91988 100644 --- a/src/EFCore.Proxies/Proxies/Internal/ProxyChangeTrackingConvention.cs +++ b/src/EFCore.Proxies/Proxies/Internal/ProxyChangeTrackingConvention.cs @@ -40,7 +40,9 @@ public virtual void ProcessModelInitialized(IConventionModelBuilder modelBuilder if (_options?.UseChangeTrackingProxies == true) { modelBuilder.HasChangeTrackingStrategy(ChangeTrackingStrategy.ChangingAndChangedNotifications); +#pragma warning disable EF1001 // Internal EF Core API usage. modelBuilder.HasAnnotation(CoreAnnotationNames.SkipChangeTrackingStrategyValidationAnnotation, "true"); +#pragma warning restore EF1001 // Internal EF Core API usage. } } } diff --git a/src/EFCore.Relational/EFCore.Relational.csproj b/src/EFCore.Relational/EFCore.Relational.csproj index 7acf0d15c3a..86fefdaea88 100644 --- a/src/EFCore.Relational/EFCore.Relational.csproj +++ b/src/EFCore.Relational/EFCore.Relational.csproj @@ -16,7 +16,7 @@ - + diff --git a/src/EFCore.Relational/Extensions/Internal/RelationalExpressionExtensions.cs b/src/EFCore.Relational/Extensions/Internal/RelationalExpressionExtensions.cs deleted file mode 100644 index edd3fb51962..00000000000 --- a/src/EFCore.Relational/Extensions/Internal/RelationalExpressionExtensions.cs +++ /dev/null @@ -1,30 +0,0 @@ -// 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.Linq.Expressions; -using JetBrains.Annotations; -using Microsoft.EntityFrameworkCore.Query.SqlExpressions; - -// ReSharper disable once CheckNamespace -namespace Microsoft.EntityFrameworkCore.Internal -{ - /// - /// 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. - /// - public static class RelationalExpressionExtensions - { - /// - /// 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. - /// - public static bool IsLogicalNot([NotNull] this SqlUnaryExpression sqlUnaryExpression) - => sqlUnaryExpression.OperatorType == ExpressionType.Not - && (sqlUnaryExpression.Type == typeof(bool) - || sqlUnaryExpression.Type == typeof(bool?)); - } -} diff --git a/src/EFCore.Relational/Query/ExpressionExtensions.cs b/src/EFCore.Relational/Query/ExpressionExtensions.cs index 5e1b628cc04..3db3e085ae8 100644 --- a/src/EFCore.Relational/Query/ExpressionExtensions.cs +++ b/src/EFCore.Relational/Query/ExpressionExtensions.cs @@ -1,6 +1,7 @@ // 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.Linq.Expressions; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; @@ -10,6 +11,11 @@ namespace Microsoft.EntityFrameworkCore.Query { public static class ExpressionExtensions { + public static bool IsLogicalNot([NotNull] this SqlUnaryExpression sqlUnaryExpression) + => sqlUnaryExpression.OperatorType == ExpressionType.Not + && (sqlUnaryExpression.Type == typeof(bool) + || sqlUnaryExpression.Type == typeof(bool?)); + public static RelationalTypeMapping InferTypeMapping([NotNull] params SqlExpression[] expressions) { Check.NotNull(expressions, nameof(expressions)); diff --git a/src/EFCore.SqlServer.NTS/EFCore.SqlServer.NTS.csproj b/src/EFCore.SqlServer.NTS/EFCore.SqlServer.NTS.csproj index c5b9a094107..01874124980 100644 --- a/src/EFCore.SqlServer.NTS/EFCore.SqlServer.NTS.csproj +++ b/src/EFCore.SqlServer.NTS/EFCore.SqlServer.NTS.csproj @@ -24,6 +24,7 @@ + diff --git a/src/EFCore.SqlServer/EFCore.SqlServer.csproj b/src/EFCore.SqlServer/EFCore.SqlServer.csproj index 73cf7177bb2..14e06590e57 100644 --- a/src/EFCore.SqlServer/EFCore.SqlServer.csproj +++ b/src/EFCore.SqlServer/EFCore.SqlServer.csproj @@ -17,6 +17,7 @@ + diff --git a/src/EFCore.SqlServer/Query/Internal/SearchConditionConvertingExpressionVisitor.cs b/src/EFCore.SqlServer/Query/Internal/SearchConditionConvertingExpressionVisitor.cs index 7df5a435198..488ca0ba35c 100644 --- a/src/EFCore.SqlServer/Query/Internal/SearchConditionConvertingExpressionVisitor.cs +++ b/src/EFCore.SqlServer/Query/Internal/SearchConditionConvertingExpressionVisitor.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.Linq.Expressions; using JetBrains.Annotations; -using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.SqlServer.Internal; diff --git a/src/EFCore.Sqlite.Core/EFCore.Sqlite.Core.csproj b/src/EFCore.Sqlite.Core/EFCore.Sqlite.Core.csproj index 6ecb032e807..f7fb1ce3703 100644 --- a/src/EFCore.Sqlite.Core/EFCore.Sqlite.Core.csproj +++ b/src/EFCore.Sqlite.Core/EFCore.Sqlite.Core.csproj @@ -19,6 +19,7 @@ + diff --git a/src/EFCore.Sqlite.Core/Internal/SqliteLoggerExtensions.cs b/src/EFCore.Sqlite.Core/Internal/SqliteLoggerExtensions.cs index f5c1a306585..3eabab12042 100644 --- a/src/EFCore.Sqlite.Core/Internal/SqliteLoggerExtensions.cs +++ b/src/EFCore.Sqlite.Core/Internal/SqliteLoggerExtensions.cs @@ -4,7 +4,7 @@ using System; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Diagnostics; -using Microsoft.EntityFrameworkCore.Internal; +using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Sqlite.Diagnostics.Internal; @@ -319,7 +319,7 @@ public static void UnexpectedConnectionTypeWarning( if (diagnostics.ShouldLog(definition)) { - definition.Log(diagnostics, connectionType.DisplayName()); + definition.Log(diagnostics, connectionType.ShortDisplayName()); } if (diagnostics.NeedsEventData(definition, out var diagnosticSourceEnabled, out var simpleLogEnabled)) @@ -338,7 +338,7 @@ private static string UnexpectedConnectionTypeWarning(EventDefinitionBase defini var d = (EventDefinition)definition; var p = (UnexpectedConnectionTypeEventData)payload; - return d.GenerateMessage(p.ConnectionType.DisplayName()); + return d.GenerateMessage(p.ConnectionType.ShortDisplayName()); } } } diff --git a/src/EFCore.Sqlite.NTS/EFCore.Sqlite.NTS.csproj b/src/EFCore.Sqlite.NTS/EFCore.Sqlite.NTS.csproj index e2708d6f2c1..5639ca01707 100644 --- a/src/EFCore.Sqlite.NTS/EFCore.Sqlite.NTS.csproj +++ b/src/EFCore.Sqlite.NTS/EFCore.Sqlite.NTS.csproj @@ -25,6 +25,7 @@ + diff --git a/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuiteDbContextOptionsBuilderExtensions.cs b/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuiteDbContextOptionsBuilderExtensions.cs index ddcc47ac318..93f04d25409 100644 --- a/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuiteDbContextOptionsBuilderExtensions.cs +++ b/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuiteDbContextOptionsBuilderExtensions.cs @@ -26,12 +26,15 @@ public static SqliteDbContextOptionsBuilder UseNetTopologySuite( var coreOptionsBuilder = ((IRelationalDbContextOptionsBuilderInfrastructure)optionsBuilder).OptionsBuilder; var infrastructure = (IDbContextOptionsBuilderInfrastructure)coreOptionsBuilder; +#pragma warning disable EF1001 // Internal EF Core API usage. + // #20566 var sqliteExtension = coreOptionsBuilder.Options.FindExtension() ?? new SqliteOptionsExtension(); var ntsExtension = coreOptionsBuilder.Options.FindExtension() ?? new SqliteNetTopologySuiteOptionsExtension(); infrastructure.AddOrUpdateExtension(sqliteExtension.WithLoadSpatialite(true)); +#pragma warning restore EF1001 // Internal EF Core API usage. infrastructure.AddOrUpdateExtension(ntsExtension); return optionsBuilder; diff --git a/src/EFCore.Sqlite/EFCore.Sqlite.csproj b/src/EFCore.Sqlite/EFCore.Sqlite.csproj index 0163f33a067..674f2106e9d 100644 --- a/src/EFCore.Sqlite/EFCore.Sqlite.csproj +++ b/src/EFCore.Sqlite/EFCore.Sqlite.csproj @@ -16,6 +16,7 @@ + diff --git a/src/EFCore/EFCore.csproj b/src/EFCore/EFCore.csproj index 3fef935637f..88eb09fa3f9 100644 --- a/src/EFCore/EFCore.csproj +++ b/src/EFCore/EFCore.csproj @@ -35,7 +35,7 @@ Microsoft.EntityFrameworkCore.DbSet - + diff --git a/src/EFCore/Extensions/PropertyExtensions.cs b/src/EFCore/Extensions/PropertyExtensions.cs index 8d3f8e94c08..f6173ddc04d 100644 --- a/src/EFCore/Extensions/PropertyExtensions.cs +++ b/src/EFCore/Extensions/PropertyExtensions.cs @@ -46,7 +46,7 @@ public static CoreTypeMapping GetTypeMapping([NotNull] this IProperty property) /// Returns the for the given property. /// /// The property. - /// The type mapping, or null if none was found. + /// The type mapping, or null if none was found. public static CoreTypeMapping FindTypeMapping([NotNull] this IProperty property) => (CoreTypeMapping)property[CoreAnnotationNames.TypeMapping]; @@ -55,7 +55,7 @@ public static CoreTypeMapping FindTypeMapping([NotNull] this IProperty property) /// if the given property is part of a foreign key. /// /// The foreign key property. - /// The first associated principal property, or null if none exists. + /// The first associated principal property, or null if none exists. public static IProperty FindFirstPrincipal([NotNull] this IProperty property) { Check.NotNull(property, nameof(property)); @@ -120,9 +120,7 @@ private static void AddPrincipals(IProperty property, List visited) /// Gets a value indicating whether this property is used as a foreign key (or part of a composite foreign key). /// /// The property to check. - /// - /// true if the property is used as a foreign key, otherwise false. - /// + /// True if the property is used as a foreign key, otherwise false. /// public static bool IsForeignKey([NotNull] this IProperty property) => Check.NotNull(property, nameof(property)).AsProperty().ForeignKeys != null; @@ -130,9 +128,7 @@ public static bool IsForeignKey([NotNull] this IProperty property) /// Gets a value indicating whether this property is used as an index (or part of a composite index). /// /// The property to check. - /// - /// true if the property is used as an index, otherwise false. - /// + /// True if the property is used as an index, otherwise false. public static bool IsIndex([NotNull] this IProperty property) => Check.NotNull(property, nameof(property)).AsProperty().Indexes != null; @@ -140,9 +136,7 @@ public static bool IsIndex([NotNull] this IProperty property) /// Gets a value indicating whether this property is used as a unique index (or part of a unique composite index). /// /// The property to check. - /// - /// true if the property is used as an uniqueindex, otherwise false. - /// + /// True if the property is used as an unique index, otherwise false. public static bool IsUniqueIndex([NotNull] this IProperty property) => Check.NotNull(property, nameof(property)).AsProperty().Indexes?.Any(e => e.IsUnique) == true; @@ -150,20 +144,16 @@ public static bool IsUniqueIndex([NotNull] this IProperty property) /// Gets a value indicating whether this property is used as the primary key (or part of a composite primary key). /// /// The property to check. - /// - /// true if the property is used as the primary key, otherwise false. - /// + /// True if the property is used as the primary key, otherwise false. public static bool IsPrimaryKey([NotNull] this IProperty property) => FindContainingPrimaryKey(property) != null; /// - /// Gets a value indicating whether this property is used as part of a primary or alternate key + /// Gets a value indicating whether this property is used as the primary key or alternate key /// (or part of a composite primary or alternate key). /// /// The property to check. - /// - /// true if the property is part of a key, otherwise false. - /// + /// True if the property is used as a key, otherwise false. public static bool IsKey([NotNull] this IProperty property) => Check.NotNull(property, nameof(property)).AsProperty().Keys != null; @@ -172,9 +162,7 @@ public static bool IsKey([NotNull] this IProperty property) /// is included). /// /// The property to get foreign keys for. - /// - /// The foreign keys that use this property. - /// + /// The foreign keys that use this property. public static IEnumerable GetContainingForeignKeys([NotNull] this IProperty property) => Check.NotNull(property, nameof(property)).AsProperty().GetContainingForeignKeys(); @@ -183,9 +171,7 @@ public static IEnumerable GetContainingForeignKeys([NotNull] this I /// is included). /// /// The property to get indexes for. - /// - /// The indexes that use this property. - /// + /// The indexes that use this property. public static IEnumerable GetContainingIndexes([NotNull] this IProperty property) => Check.NotNull(property, nameof(property)).AsProperty().GetContainingIndexes(); @@ -194,9 +180,7 @@ public static IEnumerable GetContainingIndexes([NotNull] this IProperty /// is included). /// /// The property to get primary key for. - /// - /// The primary that use this property, or null if it is not part of the primary key. - /// + /// The primary that use this property, or null if it is not part of the primary key. public static IKey FindContainingPrimaryKey([NotNull] this IProperty property) => Check.NotNull(property, nameof(property)).AsProperty().PrimaryKey; @@ -205,9 +189,7 @@ public static IKey FindContainingPrimaryKey([NotNull] this IProperty property) /// is included). /// /// The property to get primary and alternate keys for. - /// - /// The primary and alternate keys that use this property. - /// + /// The primary and alternate keys that use this property. public static IEnumerable GetContainingKeys([NotNull] this IProperty property) => Check.NotNull(property, nameof(property)).AsProperty().GetContainingKeys(); @@ -216,7 +198,7 @@ public static IEnumerable GetContainingKeys([NotNull] this IProperty prope /// then this is the maximum number of characters. /// /// The property to get the maximum length of. - /// The maximum length, or null if none if defined. + /// The maximum length, or null if none if defined. public static int? GetMaxLength([NotNull] this IProperty property) { Check.NotNull(property, nameof(property)); @@ -230,7 +212,7 @@ public static IEnumerable GetContainingKeys([NotNull] this IProperty prope /// then this is the maximum number of digits. /// /// The property to get the precision of. - /// The precision, or null if none if defined. + /// The precision, or null if none if defined. public static int? GetPrecision([NotNull] this IProperty property) { Check.NotNull(property, nameof(property)); @@ -244,7 +226,7 @@ public static IEnumerable GetContainingKeys([NotNull] this IProperty prope /// then this is the maximum number of decimal places. /// /// The property to get the scale of. - /// The scale, or null if none if defined. + /// The scale, or null if none if defined. public static int? GetScale([NotNull] this IProperty property) { Check.NotNull(property, nameof(property)); @@ -256,7 +238,7 @@ public static IEnumerable GetContainingKeys([NotNull] this IProperty prope /// Gets a value indicating whether or not the property can persist Unicode characters. /// /// The property to get the Unicode setting for. - /// The Unicode setting, or null if none if defined. + /// The Unicode setting, or null if none if defined. public static bool? IsUnicode([NotNull] this IProperty property) { Check.NotNull(property, nameof(property)); @@ -313,7 +295,7 @@ public static PropertySaveBehavior GetAfterSaveBehavior([NotNull] this IProperty /// Gets the factory that has been set to generate values for this property, if any. /// /// The property to get the value generator factory for. - /// The factory, or null if no factory has been set. + /// The factory, or null if no factory has been set. public static Func GetValueGeneratorFactory([NotNull] this IProperty property) => (Func) Check.NotNull(property, nameof(property))[CoreAnnotationNames.ValueGeneratorFactory]; @@ -322,7 +304,7 @@ public static Func GetValueGeneratorFact /// Gets the custom set for this property. /// /// The property. - /// The converter, or null if none has been set. + /// The converter, or null if none has been set. public static ValueConverter GetValueConverter([NotNull] this IProperty property) => (ValueConverter)Check.NotNull(property, nameof(property))[CoreAnnotationNames.ValueConverter]; @@ -330,16 +312,16 @@ public static ValueConverter GetValueConverter([NotNull] this IProperty property /// Gets the type that the property value will be converted to before being sent to the database provider. /// /// The property. - /// The provider type, or null if none has been set. + /// The provider type, or null if none has been set. public static Type GetProviderClrType([NotNull] this IProperty property) => (Type)Check.NotNull(property, nameof(property))[CoreAnnotationNames.ProviderClrType]; /// - /// Gets the for this property, or null if none is set. + /// Gets the for this property, or null if none is set. /// /// The property. /// If true, then the default comparer is returned when the explicit comparer is not set. - /// The comparer, or null if none has been set. + /// The comparer, or null if none has been set. public static ValueComparer GetValueComparer([NotNull] this IProperty property, bool fallback = true) { Check.NotNull(property, nameof(property)); @@ -353,11 +335,11 @@ public static ValueComparer GetValueComparer([NotNull] this IProperty property, } /// - /// Gets the to use with keys for this property, or null if none is set. + /// Gets the to use with keys for this property, or null if none is set. /// /// The property. /// If true, then the regular comparer is returned when the key comparer is not set. - /// The comparer, or null if none has been set. + /// The comparer, or null if none has been set. public static ValueComparer GetKeyValueComparer([NotNull] this IProperty property, bool fallback = true) { Check.NotNull(property, nameof(property)); @@ -372,11 +354,11 @@ public static ValueComparer GetKeyValueComparer([NotNull] this IProperty propert } /// - /// Gets the to use for structural copies for this property, or null if none is set. + /// Gets the to use for structural copies for this property, or null if none is set. /// /// The property. /// If true, then the key comparer is returned when the structural comparer is not set. - /// The comparer, or null if none has been set. + /// The comparer, or null if none has been set. [Obsolete( "Use GetKeyValueComparer. Starting with EF Core 5.0, key comparers must implement structural comparisons and deep copies.")] public static ValueComparer GetStructuralValueComparer([NotNull] this IProperty property, bool fallback = true) @@ -419,7 +401,7 @@ public int GetHashCode(TNullableKey obj) /// when throwing exceptions about keys, indexes, etc. that use the properties. /// /// The properties to format. - /// If true, then type names are included in the string. The default is false. + /// If true, then type names are included in the string. The default is false. /// The string representation. public static string Format([NotNull] this IEnumerable properties, bool includeTypes = false) => "{" diff --git a/src/EFCore/Infrastructure/ModelValidator.cs b/src/EFCore/Infrastructure/ModelValidator.cs index 398feb8d8a7..1110b723149 100644 --- a/src/EFCore/Infrastructure/ModelValidator.cs +++ b/src/EFCore/Infrastructure/ModelValidator.cs @@ -890,7 +890,8 @@ protected virtual void ValidateTypeMappings( } } - if (property.IsKeyOrForeignKey() + if (property.IsKey() + || property.IsForeignKey() || property.IsUniqueIndex()) { var _ = property.GetCurrentValueComparer(); // Will throw if there is no way to compare diff --git a/src/EFCore/Metadata/Internal/EntityTypeExtensions.cs b/src/EFCore/Metadata/Internal/EntityTypeExtensions.cs index 72934286df8..0660fad736b 100644 --- a/src/EFCore/Metadata/Internal/EntityTypeExtensions.cs +++ b/src/EFCore/Metadata/Internal/EntityTypeExtensions.cs @@ -290,7 +290,7 @@ public static PropertyCounts CalculateCounts([NotNull] this EntityType entityTyp index: index++, originalValueIndex: property.RequiresOriginalValue() ? originalValueIndex++ : -1, shadowIndex: property.IsShadowProperty() ? shadowIndex++ : -1, - relationshipIndex: property.IsKeyOrForeignKey() ? relationshipIndex++ : -1, + relationshipIndex: property.IsKey() || property.IsForeignKey() ? relationshipIndex++ : -1, storeGenerationIndex: property.MayBeStoreGenerated() ? storeGenerationIndex++ : -1); property.PropertyIndexes = indexes; diff --git a/src/EFCore/Metadata/Internal/PropertyExtensions.cs b/src/EFCore/Metadata/Internal/PropertyExtensions.cs index 5c00432d21a..33208854bcc 100644 --- a/src/EFCore/Metadata/Internal/PropertyExtensions.cs +++ b/src/EFCore/Metadata/Internal/PropertyExtensions.cs @@ -120,7 +120,8 @@ public static bool MayBeStoreGenerated([NotNull] this IProperty property) return true; } - if (property.IsKeyOrForeignKey()) + if (property.IsKey() + || property.IsForeignKey()) { var generationProperty = property.GetGenerationProperty(); return (generationProperty != null) @@ -143,16 +144,6 @@ public static bool RequiresOriginalValue([NotNull] this IProperty property) || property.IsForeignKey() || property.IsUniqueIndex(); - /// - /// 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. - /// - public static bool IsKeyOrForeignKey([NotNull] this IProperty property) - => property.IsKey() - || property.IsForeignKey(); - /// /// 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 diff --git a/src/EFCore/Storage/TypeMappingInfo.cs b/src/EFCore/Storage/TypeMappingInfo.cs index 02993a66406..d940464e9ad 100644 --- a/src/EFCore/Storage/TypeMappingInfo.cs +++ b/src/EFCore/Storage/TypeMappingInfo.cs @@ -6,7 +6,6 @@ using System.Reflection; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Utilities; @@ -112,7 +111,7 @@ public TypeMappingInfo( var mappingHints = customConverter?.MappingHints; var property = principals[0]; - IsKeyOrIndex = property.IsKeyOrForeignKey() || property.IsIndex(); + IsKeyOrIndex = property.IsKey() || property.IsForeignKey() || property.IsIndex(); Size = size ?? mappingHints?.Size ?? fallbackSize; IsUnicode = isUnicode ?? mappingHints?.IsUnicode ?? fallbackUnicode; IsRowVersion = property.IsConcurrencyToken && property.ValueGenerated == ValueGenerated.OnAddOrUpdate;