diff --git a/src/EFCore.Cosmos/Query/Internal/ContainsTranslator.cs b/src/EFCore.Cosmos/Query/Internal/ContainsTranslator.cs index 5efc9f5a8ef..ee5eff7e9d7 100644 --- a/src/EFCore.Cosmos/Query/Internal/ContainsTranslator.cs +++ b/src/EFCore.Cosmos/Query/Internal/ContainsTranslator.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal { @@ -34,7 +35,8 @@ public ContainsTranslator([NotNull] ISqlExpressionFactory sqlExpressionFactory) /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments, + IDiagnosticsLogger logger) { if (method.IsGenericMethod && method.GetGenericMethodDefinition().Equals(EnumerableMethods.Contains) diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosMemberTranslatorProvider.cs b/src/EFCore.Cosmos/Query/Internal/CosmosMemberTranslatorProvider.cs index 381fe0c3c25..73aba51a107 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosMemberTranslatorProvider.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosMemberTranslatorProvider.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal @@ -46,14 +47,16 @@ public CosmosMemberTranslatorProvider( /// 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 virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType) + public virtual SqlExpression Translate( + SqlExpression instance, MemberInfo member, Type returnType, IDiagnosticsLogger logger) { Check.NotNull(instance, nameof(instance)); Check.NotNull(member, nameof(member)); Check.NotNull(returnType, nameof(returnType)); + Check.NotNull(logger, nameof(logger)); return _plugins.Concat(_translators) - .Select(t => t.Translate(instance, member, returnType)).FirstOrDefault(t => t != null); + .Select(t => t.Translate(instance, member, returnType, logger)).FirstOrDefault(t => t != null); } /// diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosMethodCallTranslatorProvider.cs b/src/EFCore.Cosmos/Query/Internal/CosmosMethodCallTranslatorProvider.cs index 37e983cbd81..2b386a5e0d1 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosMethodCallTranslatorProvider.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosMethodCallTranslatorProvider.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Utilities; @@ -53,14 +54,16 @@ public CosmosMethodCallTranslatorProvider( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual SqlExpression Translate( - IModel model, SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + IModel model, SqlExpression instance, MethodInfo method, IReadOnlyList arguments, + IDiagnosticsLogger logger) { Check.NotNull(model, nameof(model)); Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); return _plugins.Concat(_translators) - .Select(t => t.Translate(instance, method, arguments)) + .Select(t => t.Translate(instance, method, arguments, logger)) .FirstOrDefault(t => t != null); } diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosSqlTranslatingExpressionVisitor.cs b/src/EFCore.Cosmos/Query/Internal/CosmosSqlTranslatingExpressionVisitor.cs index 1ca05f0a247..b45f697199d 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosSqlTranslatingExpressionVisitor.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosSqlTranslatingExpressionVisitor.cs @@ -344,7 +344,8 @@ protected override Expression VisitMember(MemberExpression memberExpression) return TryBindMember(innerExpression, MemberIdentity.Create(memberExpression.Member)) ?? (TranslationFailed(memberExpression.Expression, innerExpression, out var sqlInnerExpression) ? null - : _memberTranslatorProvider.Translate(sqlInnerExpression, memberExpression.Member, memberExpression.Type)); + : _memberTranslatorProvider.Translate( + sqlInnerExpression, memberExpression.Member, memberExpression.Type, _queryCompilationContext.Logger)); } /// @@ -490,7 +491,8 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp } } - var translation = _methodCallTranslatorProvider.Translate(_model, sqlObject, methodCallExpression.Method, arguments); + var translation = _methodCallTranslatorProvider.Translate( + _model, sqlObject, methodCallExpression.Method, arguments, _queryCompilationContext.Logger); if (translation == null) { diff --git a/src/EFCore.Cosmos/Query/Internal/EqualsTranslator.cs b/src/EFCore.Cosmos/Query/Internal/EqualsTranslator.cs index b04cafc5a75..f7104d9d436 100644 --- a/src/EFCore.Cosmos/Query/Internal/EqualsTranslator.cs +++ b/src/EFCore.Cosmos/Query/Internal/EqualsTranslator.cs @@ -6,6 +6,7 @@ using System.Linq.Expressions; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal @@ -37,10 +38,12 @@ public EqualsTranslator([NotNull] ISqlExpressionFactory sqlExpressionFactory) /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); SqlExpression left = null; SqlExpression right = null; diff --git a/src/EFCore.Cosmos/Query/Internal/IMemberTranslator.cs b/src/EFCore.Cosmos/Query/Internal/IMemberTranslator.cs index be1070559f8..01d4d7291e4 100644 --- a/src/EFCore.Cosmos/Query/Internal/IMemberTranslator.cs +++ b/src/EFCore.Cosmos/Query/Internal/IMemberTranslator.cs @@ -4,6 +4,7 @@ using System; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal { @@ -21,6 +22,7 @@ public interface IMemberTranslator /// 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. /// - SqlExpression Translate([NotNull] SqlExpression instance, [NotNull] MemberInfo member, [NotNull] Type returnType); + SqlExpression Translate([NotNull] SqlExpression instance, [NotNull] MemberInfo member, [NotNull] Type returnType, + [NotNull] IDiagnosticsLogger logger); } } diff --git a/src/EFCore.Cosmos/Query/Internal/IMemberTranslatorProvider.cs b/src/EFCore.Cosmos/Query/Internal/IMemberTranslatorProvider.cs index 2f92117be5f..86ab4caa381 100644 --- a/src/EFCore.Cosmos/Query/Internal/IMemberTranslatorProvider.cs +++ b/src/EFCore.Cosmos/Query/Internal/IMemberTranslatorProvider.cs @@ -4,6 +4,7 @@ using System; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal { @@ -21,6 +22,7 @@ public interface IMemberTranslatorProvider /// 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. /// - SqlExpression Translate([NotNull] SqlExpression instance, [NotNull] MemberInfo member, [NotNull] Type returnType); + SqlExpression Translate([NotNull] SqlExpression instance, [NotNull] MemberInfo member, [NotNull] Type returnType, + [NotNull] IDiagnosticsLogger logger); } } diff --git a/src/EFCore.Cosmos/Query/Internal/IMethodCallTranslator.cs b/src/EFCore.Cosmos/Query/Internal/IMethodCallTranslator.cs index 00aafb3c7a0..a0b323f9388 100644 --- a/src/EFCore.Cosmos/Query/Internal/IMethodCallTranslator.cs +++ b/src/EFCore.Cosmos/Query/Internal/IMethodCallTranslator.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal { @@ -22,6 +23,7 @@ public interface IMethodCallTranslator /// doing so can result in application failures when updating to a new Entity Framework Core release. /// SqlExpression Translate( - [CanBeNull] SqlExpression instance, [NotNull] MethodInfo method, [NotNull] IReadOnlyList arguments); + [CanBeNull] SqlExpression instance, [NotNull] MethodInfo method, [NotNull] IReadOnlyList arguments, + [NotNull] IDiagnosticsLogger logger); } } diff --git a/src/EFCore.Cosmos/Query/Internal/IMethodCallTranslatorProvider.cs b/src/EFCore.Cosmos/Query/Internal/IMethodCallTranslatorProvider.cs index dcdcf043986..93267e3c41e 100644 --- a/src/EFCore.Cosmos/Query/Internal/IMethodCallTranslatorProvider.cs +++ b/src/EFCore.Cosmos/Query/Internal/IMethodCallTranslatorProvider.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Metadata; namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal @@ -26,6 +27,7 @@ SqlExpression Translate( [NotNull] IModel model, [CanBeNull] SqlExpression instance, [NotNull] MethodInfo method, - [NotNull] IReadOnlyList arguments); + [NotNull] IReadOnlyList arguments, + [NotNull] IDiagnosticsLogger logger); } } diff --git a/src/EFCore.Cosmos/Query/Internal/StringMethodTranslator.cs b/src/EFCore.Cosmos/Query/Internal/StringMethodTranslator.cs index 142d658aff5..99e30a84739 100644 --- a/src/EFCore.Cosmos/Query/Internal/StringMethodTranslator.cs +++ b/src/EFCore.Cosmos/Query/Internal/StringMethodTranslator.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal @@ -56,10 +57,12 @@ public StringMethodTranslator([NotNull] ISqlExpressionFactory sqlExpressionFacto /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); if (_containsMethodInfo.Equals(method)) { diff --git a/src/EFCore.Relational/Diagnostics/RelationalLoggerExtensions.cs b/src/EFCore.Relational/Diagnostics/RelationalLoggerExtensions.cs index aed1335de3b..900215032da 100644 --- a/src/EFCore.Relational/Diagnostics/RelationalLoggerExtensions.cs +++ b/src/EFCore.Relational/Diagnostics/RelationalLoggerExtensions.cs @@ -15,10 +15,13 @@ using System.Transactions; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Diagnostics.Internal; +using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations.Internal; +using Microsoft.EntityFrameworkCore.Query; +using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage.Internal; using Microsoft.EntityFrameworkCore.Update; @@ -4129,24 +4132,27 @@ private static string MigrationAttributeMissingWarning(EventDefinitionBase defin /// Logs for the event. /// /// The diagnostics logger to use. - /// The expression representing the problematic method call. + /// The left SQL expression of the Equals. + /// The right SQL expression of the Equals. public static void QueryPossibleUnintendedUseOfEqualsWarning( [NotNull] this IDiagnosticsLogger diagnostics, - [NotNull] MethodCallExpression methodCallExpression) + [NotNull] SqlExpression left, + [NotNull] SqlExpression right) { var definition = RelationalResources.LogPossibleUnintendedUseOfEquals(diagnostics); if (diagnostics.ShouldLog(definition)) { - definition.Log(diagnostics, methodCallExpression); + definition.Log(diagnostics, left.Print(), right.Print()); } if (diagnostics.NeedsEventData(definition, out var diagnosticSourceEnabled, out var simpleLogEnabled)) { - var eventData = new ExpressionEventData( + var eventData = new TwoSqlExpressionEventData( definition, QueryPossibleUnintendedUseOfEqualsWarning, - methodCallExpression); + left, + right); diagnostics.DispatchEventData(definition, eventData, diagnosticSourceEnabled, simpleLogEnabled); } @@ -4154,9 +4160,9 @@ public static void QueryPossibleUnintendedUseOfEqualsWarning( private static string QueryPossibleUnintendedUseOfEqualsWarning(EventDefinitionBase definition, EventData payload) { - var d = (EventDefinition)definition; - var p = (ExpressionEventData)payload; - return d.GenerateMessage(p.Expression); + var d = (EventDefinition)definition; + var p = (TwoSqlExpressionEventData)payload; + return d.GenerateMessage(p.Left.Print(), p.Right.Print()); } /// diff --git a/src/EFCore.Relational/Diagnostics/TwoSqlExpressionEventData.cs b/src/EFCore.Relational/Diagnostics/TwoSqlExpressionEventData.cs new file mode 100644 index 00000000000..786b16e8f41 --- /dev/null +++ b/src/EFCore.Relational/Diagnostics/TwoSqlExpressionEventData.cs @@ -0,0 +1,45 @@ +// 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.Diagnostics; +using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Query.SqlExpressions; + +namespace Microsoft.EntityFrameworkCore.Diagnostics +{ + /// + /// The event payload base class for events that + /// references two . + /// + public class TwoSqlExpressionEventData : EventData + { + /// + /// Constructs the event payload. + /// + /// The event definition. + /// A delegate that generates a log message for this event. + /// The left SqlExpression. + /// The right SqlExpression. + public TwoSqlExpressionEventData( + [NotNull] EventDefinitionBase eventDefinition, + [NotNull] Func messageGenerator, + [NotNull] SqlExpression left, + [NotNull] SqlExpression right) + : base(eventDefinition, messageGenerator) + { + Left = left; + Right = right; + } + + /// + /// The left SqlExpression. + /// + public virtual SqlExpression Left { get; } + + /// + /// The right SqlExpression. + /// + public virtual SqlExpression Right { get; } + } +} diff --git a/src/EFCore.Relational/Properties/RelationalStrings.Designer.cs b/src/EFCore.Relational/Properties/RelationalStrings.Designer.cs index 8b2799d500e..0ac8ffbb476 100644 --- a/src/EFCore.Relational/Properties/RelationalStrings.Designer.cs +++ b/src/EFCore.Relational/Properties/RelationalStrings.Designer.cs @@ -1618,27 +1618,27 @@ public static EventDefinition LogAmbientTransaction([NotNull] IDiagnosticsLogger } /// - /// Possible unintended use of method Equals(object) for arguments of different types in expression '{expression}'. This comparison will always return 'false'. + /// Possible unintended use of method Equals(object) for arguments '{left}' and '{right}' of different types in query. This comparison will always return 'false'. /// - public static EventDefinition LogPossibleUnintendedUseOfEquals([NotNull] IDiagnosticsLogger logger) + public static EventDefinition LogPossibleUnintendedUseOfEquals([NotNull] IDiagnosticsLogger logger) { var definition = ((RelationalLoggingDefinitions)logger.Definitions).LogPossibleUnintendedUseOfEquals; if (definition == null) { definition = LazyInitializer.EnsureInitialized( ref ((RelationalLoggingDefinitions)logger.Definitions).LogPossibleUnintendedUseOfEquals, - () => new EventDefinition( + () => new EventDefinition( logger.Options, RelationalEventId.QueryPossibleUnintendedUseOfEqualsWarning, LogLevel.Warning, "RelationalEventId.QueryPossibleUnintendedUseOfEqualsWarning", - level => LoggerMessage.Define( + level => LoggerMessage.Define( level, RelationalEventId.QueryPossibleUnintendedUseOfEqualsWarning, _resourceManager.GetString("LogPossibleUnintendedUseOfEquals")))); } - return (EventDefinition)definition; + return (EventDefinition)definition; } /// diff --git a/src/EFCore.Relational/Properties/RelationalStrings.resx b/src/EFCore.Relational/Properties/RelationalStrings.resx index 18e9c9c92b0..938a565331b 100644 --- a/src/EFCore.Relational/Properties/RelationalStrings.resx +++ b/src/EFCore.Relational/Properties/RelationalStrings.resx @@ -267,8 +267,8 @@ Warning RelationalEventId.AmbientTransactionWarning - Possible unintended use of method Equals(object) for arguments of different types in expression '{expression}'. This comparison will always return 'false'. - Warning RelationalEventId.QueryPossibleUnintendedUseOfEqualsWarning object + Possible unintended use of method Equals(object) for arguments '{left}' and '{right}' of different types in query. This comparison will always return 'false'. + Warning RelationalEventId.QueryPossibleUnintendedUseOfEqualsWarning string string Possible unintended use of a potentially throwing aggregate method (Min, Max, Average) in a subquery. Client evaluation will be used and operator will throw if no data exists. Changing the subquery result type to a nullable type will allow full translation. diff --git a/src/EFCore.Relational/Query/IMemberTranslator.cs b/src/EFCore.Relational/Query/IMemberTranslator.cs index 99e789e42ab..a81ee61a085 100644 --- a/src/EFCore.Relational/Query/IMemberTranslator.cs +++ b/src/EFCore.Relational/Query/IMemberTranslator.cs @@ -5,6 +5,7 @@ using System.Linq.Expressions; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; namespace Microsoft.EntityFrameworkCore.Query @@ -26,7 +27,12 @@ public interface IMemberTranslator /// A SQL representation of . /// The member info from . /// The return type from . + /// The query logger to use. /// A SQL translation of the . - SqlExpression Translate([CanBeNull] SqlExpression instance, [NotNull] MemberInfo member, [NotNull] Type returnType); + SqlExpression Translate( + [CanBeNull] SqlExpression instance, + [NotNull] MemberInfo member, + [NotNull] Type returnType, + [NotNull] IDiagnosticsLogger logger); } } diff --git a/src/EFCore.Relational/Query/IMemberTranslatorProvider.cs b/src/EFCore.Relational/Query/IMemberTranslatorProvider.cs index 75392671592..9791f59c817 100644 --- a/src/EFCore.Relational/Query/IMemberTranslatorProvider.cs +++ b/src/EFCore.Relational/Query/IMemberTranslatorProvider.cs @@ -5,6 +5,7 @@ using System.Linq.Expressions; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.Extensions.DependencyInjection; @@ -28,7 +29,12 @@ public interface IMemberTranslatorProvider /// A SQL representation of . /// The member info from . /// The return type from . + /// The query logger to use. /// A SQL translation of the . - SqlExpression Translate([CanBeNull] SqlExpression instance, [NotNull] MemberInfo member, [NotNull] Type returnType); + SqlExpression Translate( + [CanBeNull] SqlExpression instance, + [NotNull] MemberInfo member, + [NotNull] Type returnType, + [NotNull] IDiagnosticsLogger logger); } } diff --git a/src/EFCore.Relational/Query/IMethodCallTranslator.cs b/src/EFCore.Relational/Query/IMethodCallTranslator.cs index 5eefb20d922..d2e0abe0d35 100644 --- a/src/EFCore.Relational/Query/IMethodCallTranslator.cs +++ b/src/EFCore.Relational/Query/IMethodCallTranslator.cs @@ -1,10 +1,12 @@ // 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; using System.Linq.Expressions; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; namespace Microsoft.EntityFrameworkCore.Query @@ -26,8 +28,12 @@ public interface IMethodCallTranslator /// A SQL representation of . /// The method info from . /// SQL representations of . + /// The query logger to use. /// A SQL translation of the . SqlExpression Translate( - [CanBeNull] SqlExpression instance, [NotNull] MethodInfo method, [NotNull] IReadOnlyList arguments); + [CanBeNull] SqlExpression instance, + [NotNull] MethodInfo method, + [NotNull] IReadOnlyList arguments, + [NotNull] IDiagnosticsLogger logger); } } diff --git a/src/EFCore.Relational/Query/IMethodCallTranslatorProvider.cs b/src/EFCore.Relational/Query/IMethodCallTranslatorProvider.cs index cb44690811a..358d4f83d9f 100644 --- a/src/EFCore.Relational/Query/IMethodCallTranslatorProvider.cs +++ b/src/EFCore.Relational/Query/IMethodCallTranslatorProvider.cs @@ -1,10 +1,12 @@ // 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; using System.Linq.Expressions; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.Extensions.DependencyInjection; @@ -30,11 +32,13 @@ public interface IMethodCallTranslatorProvider /// A SQL representation of . /// The method info from . /// SQL representations of . + /// The query logger to use. /// A SQL translation of the . SqlExpression Translate( [NotNull] IModel model, [CanBeNull] SqlExpression instance, [NotNull] MethodInfo method, - [NotNull] IReadOnlyList arguments); + [NotNull] IReadOnlyList arguments, + [NotNull] IDiagnosticsLogger logger); } } diff --git a/src/EFCore.Relational/Query/Internal/ByteArraySequenceEqualTranslator.cs b/src/EFCore.Relational/Query/Internal/ByteArraySequenceEqualTranslator.cs index 3ff46495b1f..fbe3e918304 100644 --- a/src/EFCore.Relational/Query/Internal/ByteArraySequenceEqualTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/ByteArraySequenceEqualTranslator.cs @@ -4,7 +4,9 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; +using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.Internal { @@ -35,8 +37,16 @@ public ByteArraySequenceEqualTranslator([NotNull] ISqlExpressionFactory sqlExpre /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, + MethodInfo method, + IReadOnlyList arguments, + IDiagnosticsLogger logger) { + Check.NotNull(method, nameof(method)); + Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); + if (method.IsGenericMethod && method.GetGenericMethodDefinition().Equals(EnumerableMethods.SequenceEqual) && arguments[0].Type == typeof(byte[])) diff --git a/src/EFCore.Relational/Query/Internal/CollateTranslator.cs b/src/EFCore.Relational/Query/Internal/CollateTranslator.cs index 5187220dd5b..cb5b958d107 100644 --- a/src/EFCore.Relational/Query/Internal/CollateTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/CollateTranslator.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Reflection; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -25,10 +26,15 @@ private static readonly MethodInfo _methodInfo /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, + MethodInfo method, + IReadOnlyList arguments, + IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); return method.IsGenericMethod && Equals(method.GetGenericMethodDefinition(), _methodInfo) diff --git a/src/EFCore.Relational/Query/Internal/ComparisonTranslator.cs b/src/EFCore.Relational/Query/Internal/ComparisonTranslator.cs index 6a2bcdec03e..ac06c0e49a2 100644 --- a/src/EFCore.Relational/Query/Internal/ComparisonTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/ComparisonTranslator.cs @@ -1,10 +1,10 @@ // 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; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -37,10 +37,15 @@ public ComparisonTranslator([NotNull] ISqlExpressionFactory sqlExpressionFactory /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, + MethodInfo method, + IReadOnlyList arguments, + IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); if (method.ReturnType == typeof(int)) { diff --git a/src/EFCore.Relational/Query/Internal/ContainsTranslator.cs b/src/EFCore.Relational/Query/Internal/ContainsTranslator.cs index cc59723e4f2..89528ca4dd1 100644 --- a/src/EFCore.Relational/Query/Internal/ContainsTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/ContainsTranslator.cs @@ -5,6 +5,7 @@ using System.Linq.Expressions; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -37,10 +38,15 @@ public ContainsTranslator([NotNull] ISqlExpressionFactory sqlExpressionFactory) /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, + MethodInfo method, + IReadOnlyList arguments, + IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); if (method.IsGenericMethod && method.GetGenericMethodDefinition().Equals(EnumerableMethods.Contains) diff --git a/src/EFCore.Relational/Query/Internal/EnumHasFlagTranslator.cs b/src/EFCore.Relational/Query/Internal/EnumHasFlagTranslator.cs index f9afc45ab0e..af6c451b9ed 100644 --- a/src/EFCore.Relational/Query/Internal/EnumHasFlagTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/EnumHasFlagTranslator.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -40,10 +41,15 @@ public EnumHasFlagTranslator([NotNull] ISqlExpressionFactory sqlExpressionFactor /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, + MethodInfo method, + IReadOnlyList arguments, + IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); if (Equals(method, _methodInfo)) { diff --git a/src/EFCore.Relational/Query/Internal/EqualsTranslator.cs b/src/EFCore.Relational/Query/Internal/EqualsTranslator.cs index a94ef7703e1..d47cfae56f9 100644 --- a/src/EFCore.Relational/Query/Internal/EqualsTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/EqualsTranslator.cs @@ -6,6 +6,7 @@ using System.Linq.Expressions; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -38,10 +39,15 @@ public EqualsTranslator([NotNull] ISqlExpressionFactory sqlExpressionFactory) /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, + MethodInfo method, + IReadOnlyList arguments, + IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); SqlExpression left = null; SqlExpression right = null; @@ -64,11 +70,16 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method if (left != null && right != null) { - return left.Type == right.Type + if (left.Type == right.Type || (right.Type == typeof(object) && right is SqlParameterExpression) - || (left.Type == typeof(object) && left is SqlParameterExpression) - ? _sqlExpressionFactory.Equal(left, right) - : (SqlExpression)_sqlExpressionFactory.Constant(false); + || (left.Type == typeof(object) && left is SqlParameterExpression)) + { + return _sqlExpressionFactory.Equal(left, right); + } + + logger.QueryPossibleUnintendedUseOfEqualsWarning(left, right); + + return _sqlExpressionFactory.Constant(false); } return null; diff --git a/src/EFCore.Relational/Query/Internal/GetValueOrDefaultTranslator.cs b/src/EFCore.Relational/Query/Internal/GetValueOrDefaultTranslator.cs index 58f25daf294..2820847d952 100644 --- a/src/EFCore.Relational/Query/Internal/GetValueOrDefaultTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/GetValueOrDefaultTranslator.cs @@ -6,6 +6,7 @@ using System.Linq.Expressions; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -38,10 +39,15 @@ public GetValueOrDefaultTranslator([NotNull] ISqlExpressionFactory sqlExpression /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, + MethodInfo method, + IReadOnlyList arguments, + IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); if (method.Name == nameof(Nullable.GetValueOrDefault) && method.ReturnType.IsNumeric()) diff --git a/src/EFCore.Relational/Query/Internal/LikeTranslator.cs b/src/EFCore.Relational/Query/Internal/LikeTranslator.cs index 367f1722590..9eae550a94d 100644 --- a/src/EFCore.Relational/Query/Internal/LikeTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/LikeTranslator.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -46,10 +47,15 @@ public LikeTranslator([NotNull] ISqlExpressionFactory sqlExpressionFactory) /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, + MethodInfo method, + IReadOnlyList arguments, + IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); if (Equals(method, _methodInfo)) { diff --git a/src/EFCore.Relational/Query/Internal/NullableMemberTranslator.cs b/src/EFCore.Relational/Query/Internal/NullableMemberTranslator.cs index 1d35f7ba40c..f093453569e 100644 --- a/src/EFCore.Relational/Query/Internal/NullableMemberTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/NullableMemberTranslator.cs @@ -4,6 +4,7 @@ using System; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -36,10 +37,12 @@ public NullableMemberTranslator([NotNull] ISqlExpressionFactory sqlExpressionFac /// 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 virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType) + public virtual SqlExpression Translate( + SqlExpression instance, MemberInfo member, Type returnType, IDiagnosticsLogger logger) { Check.NotNull(member, nameof(member)); Check.NotNull(returnType, nameof(returnType)); + Check.NotNull(logger, nameof(logger)); if (member.DeclaringType.IsNullableValueType()) { diff --git a/src/EFCore.Relational/Query/Internal/StringMethodTranslator.cs b/src/EFCore.Relational/Query/Internal/StringMethodTranslator.cs index 08a552827ec..e2b77948e74 100644 --- a/src/EFCore.Relational/Query/Internal/StringMethodTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/StringMethodTranslator.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -42,10 +43,15 @@ public StringMethodTranslator([NotNull] ISqlExpressionFactory sqlExpressionFacto /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, + MethodInfo method, + IReadOnlyList arguments, + IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); if (Equals(method, _isNullOrEmptyMethodInfo)) { diff --git a/src/EFCore.Relational/Query/RelationalMemberTranslatorProvider.cs b/src/EFCore.Relational/Query/RelationalMemberTranslatorProvider.cs index 9a72933ffd1..ff3f735c14a 100644 --- a/src/EFCore.Relational/Query/RelationalMemberTranslatorProvider.cs +++ b/src/EFCore.Relational/Query/RelationalMemberTranslatorProvider.cs @@ -7,6 +7,7 @@ using System.Linq.Expressions; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.Internal; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -44,13 +45,15 @@ public RelationalMemberTranslatorProvider([NotNull] RelationalMemberTranslatorPr } /// - public virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType) + public virtual SqlExpression Translate( + SqlExpression instance, MemberInfo member, Type returnType, IDiagnosticsLogger logger) { Check.NotNull(member, nameof(member)); Check.NotNull(returnType, nameof(returnType)); + Check.NotNull(logger, nameof(logger)); return _plugins.Concat(_translators) - .Select(t => t.Translate(instance, member, returnType)).FirstOrDefault(t => t != null); + .Select(t => t.Translate(instance, member, returnType, logger)).FirstOrDefault(t => t != null); } /// diff --git a/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProvider.cs b/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProvider.cs index 3a9db59ac1e..8ec56ddb1bb 100644 --- a/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProvider.cs +++ b/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProvider.cs @@ -7,6 +7,7 @@ using System.Linq.Expressions; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Query.Internal; @@ -63,11 +64,13 @@ public RelationalMethodCallTranslatorProvider([NotNull] RelationalMethodCallTran /// public virtual SqlExpression Translate( - IModel model, SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + IModel model, SqlExpression instance, MethodInfo method, IReadOnlyList arguments, + IDiagnosticsLogger logger) { Check.NotNull(model, nameof(model)); Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); var dbFunction = model.FindDbFunction(method); if (dbFunction != null) @@ -98,7 +101,7 @@ public virtual SqlExpression Translate( } return _plugins.Concat(_translators) - .Select(t => t.Translate(instance, method, arguments)) + .Select(t => t.Translate(instance, method, arguments, logger)) .FirstOrDefault(t => t != null); } diff --git a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs index f88cabe121e..c22cb038134 100644 --- a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs @@ -432,7 +432,8 @@ protected override Expression VisitMember(MemberExpression memberExpression) return TryBindMember(innerExpression, MemberIdentity.Create(memberExpression.Member)) ?? (TranslationFailed(memberExpression.Expression, Visit(memberExpression.Expression), out var sqlInnerExpression) ? null - : Dependencies.MemberTranslatorProvider.Translate(sqlInnerExpression, memberExpression.Member, memberExpression.Type)); + : Dependencies.MemberTranslatorProvider.Translate( + sqlInnerExpression, memberExpression.Member, memberExpression.Type, _queryCompilationContext.Logger)); } /// @@ -835,7 +836,8 @@ static bool IsAggregateResultWithCustomShaper(MethodInfo method) } } - var translation = Dependencies.MethodCallTranslatorProvider.Translate(_model, sqlObject, methodCallExpression.Method, arguments); + var translation = Dependencies.MethodCallTranslatorProvider.Translate( + _model, sqlObject, methodCallExpression.Method, arguments, _queryCompilationContext.Logger); if (translation == null) { diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMemberTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMemberTranslator.cs index b91003c23b2..3f7a0d27bcf 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMemberTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMemberTranslator.cs @@ -4,6 +4,7 @@ using System; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -39,10 +40,11 @@ public SqlServerGeometryCollectionMemberTranslator([NotNull] ISqlExpressionFacto /// 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 virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType) + public virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType, IDiagnosticsLogger logger) { Check.NotNull(member, nameof(member)); Check.NotNull(returnType, nameof(returnType)); + Check.NotNull(logger, nameof(logger)); if (Equals(member, _count)) { diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMethodTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMethodTranslator.cs index 82bc3f42d3b..3a09a4c7260 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMethodTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMethodTranslator.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; @@ -44,10 +45,12 @@ public SqlServerGeometryCollectionMethodTranslator( /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); if (Equals(method, _item)) { diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMemberTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMemberTranslator.cs index b59ff0d404a..f91dba96050 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMemberTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMemberTranslator.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; @@ -69,10 +70,12 @@ public SqlServerGeometryMemberTranslator( /// 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 virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType) + public virtual SqlExpression Translate( + SqlExpression instance, MemberInfo member, Type returnType, IDiagnosticsLogger logger) { Check.NotNull(member, nameof(member)); Check.NotNull(returnType, nameof(returnType)); + Check.NotNull(logger, nameof(logger)); if (typeof(Geometry).IsAssignableFrom(member.DeclaringType)) { diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMethodTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMethodTranslator.cs index 2d10a10d77c..0f57dc29983 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMethodTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMethodTranslator.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; @@ -79,10 +80,12 @@ public SqlServerGeometryMethodTranslator( /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); if (typeof(Geometry).IsAssignableFrom(method.DeclaringType)) { diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMemberTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMemberTranslator.cs index 903fc859c6f..e639687f534 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMemberTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMemberTranslator.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; @@ -54,10 +55,12 @@ public SqlServerLineStringMemberTranslator( /// 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 virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType) + public virtual SqlExpression Translate( + SqlExpression instance, MemberInfo member, Type returnType, IDiagnosticsLogger logger) { Check.NotNull(member, nameof(member)); Check.NotNull(returnType, nameof(returnType)); + Check.NotNull(logger, nameof(logger)); if (_memberToFunctionName.TryGetValue(member, out var functionName)) { diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMethodTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMethodTranslator.cs index 2ca69cc981c..07bb6018b92 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMethodTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMethodTranslator.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; @@ -46,10 +47,12 @@ public SqlServerLineStringMethodTranslator( /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); if (Equals(method, _getPointN)) { diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerMultiLineStringMemberTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerMultiLineStringMemberTranslator.cs index 64a5be87e89..7978604c26d 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerMultiLineStringMemberTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerMultiLineStringMemberTranslator.cs @@ -4,6 +4,7 @@ using System; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -39,10 +40,12 @@ public SqlServerMultiLineStringMemberTranslator([NotNull] ISqlExpressionFactory /// 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 virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType) + public virtual SqlExpression Translate( + SqlExpression instance, MemberInfo member, Type returnType, IDiagnosticsLogger logger) { Check.NotNull(member, nameof(member)); Check.NotNull(returnType, nameof(returnType)); + Check.NotNull(logger, nameof(logger)); if (Equals(member, _isClosed)) { diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPointMemberTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPointMemberTranslator.cs index 7f4de3b751f..3333bb56ca9 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPointMemberTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPointMemberTranslator.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Reflection; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -35,8 +36,13 @@ public SqlServerPointMemberTranslator(ISqlExpressionFactory sqlExpressionFactory _sqlExpressionFactory = sqlExpressionFactory; } - public SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType) + public SqlExpression Translate( + SqlExpression instance, MemberInfo member, Type returnType, IDiagnosticsLogger logger) { + Check.NotNull(member, nameof(member)); + Check.NotNull(returnType, nameof(returnType)); + Check.NotNull(logger, nameof(logger)); + if (typeof(Point).IsAssignableFrom(member.DeclaringType)) { Check.DebugAssert(instance.TypeMapping != null, "Instance must have typeMapping assigned."); diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMemberTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMemberTranslator.cs index a1329465ca9..f655fa75e49 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMemberTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMemberTranslator.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; @@ -52,10 +53,12 @@ public SqlServerPolygonMemberTranslator( /// 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 virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType) + public virtual SqlExpression Translate( + SqlExpression instance, MemberInfo member, Type returnType, IDiagnosticsLogger logger) { Check.NotNull(member, nameof(member)); Check.NotNull(returnType, nameof(returnType)); + Check.NotNull(logger, nameof(logger)); if (typeof(Polygon).IsAssignableFrom(member.DeclaringType)) { diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMethodTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMethodTranslator.cs index d516e602d15..38b7b7a6a61 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMethodTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMethodTranslator.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; @@ -47,10 +48,12 @@ public SqlServerPolygonMethodTranslator( /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); if (Equals(method, _getInteriorRingN)) { diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerByteArrayMethodTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerByteArrayMethodTranslator.cs index 93fe4c79598..fb568dc6758 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerByteArrayMethodTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerByteArrayMethodTranslator.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -37,10 +38,12 @@ public SqlServerByteArrayMethodTranslator([NotNull] ISqlExpressionFactory sqlExp /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); if (method.IsGenericMethod && method.GetGenericMethodDefinition().Equals(EnumerableMethods.Contains) diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerConvertTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerConvertTranslator.cs index 33ef813855c..134f9e4f80d 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerConvertTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerConvertTranslator.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -73,10 +74,12 @@ public SqlServerConvertTranslator([NotNull] ISqlExpressionFactory sqlExpressionF /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); return _supportedMethods.Contains(method) ? _sqlExpressionFactory.Function( diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerDataLengthFunctionTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerDataLengthFunctionTranslator.cs index fb97162bb82..55fd42fcfe8 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerDataLengthFunctionTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerDataLengthFunctionTranslator.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -81,10 +82,12 @@ public SqlServerDataLengthFunctionTranslator([NotNull] ISqlExpressionFactory sql /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); if (_methodInfoDataLengthMapping.Contains(method)) { diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerDateDiffFunctionsTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerDateDiffFunctionsTranslator.cs index 6f0aafd6b78..523608868d7 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerDateDiffFunctionsTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerDateDiffFunctionsTranslator.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -356,10 +357,12 @@ public SqlServerDateDiffFunctionsTranslator( /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); if (_methodInfoDateDiffMapping.TryGetValue(method, out var datePart)) { diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerDateTimeMemberTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerDateTimeMemberTranslator.cs index fa068e137e8..353fc8df397 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerDateTimeMemberTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerDateTimeMemberTranslator.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; @@ -58,10 +59,12 @@ public SqlServerDateTimeMemberTranslator( /// 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 virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType) + public virtual SqlExpression Translate( + SqlExpression instance, MemberInfo member, Type returnType, IDiagnosticsLogger logger) { Check.NotNull(member, nameof(member)); Check.NotNull(returnType, nameof(returnType)); + Check.NotNull(logger, nameof(logger)); var declaringType = member.DeclaringType; diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerDateTimeMethodTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerDateTimeMethodTranslator.cs index 6358b006004..5937501ec6c 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerDateTimeMethodTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerDateTimeMethodTranslator.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -56,10 +57,12 @@ public SqlServerDateTimeMethodTranslator([NotNull] ISqlExpressionFactory sqlExpr /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); if (_methodInfoDatePartMapping.TryGetValue(method, out var datePart)) { diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerFromPartsFunctionTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerFromPartsFunctionTranslator.cs index 1a9fda7dd5a..516c5d041ff 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerFromPartsFunctionTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerFromPartsFunctionTranslator.cs @@ -5,9 +5,11 @@ using System.Linq; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; +using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal { @@ -80,8 +82,13 @@ public SqlServerFromPartsFunctionTranslator( /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) { + Check.NotNull(method, nameof(method)); + Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); + if (_methodFunctionMapping.TryGetValue(method, out var value)) { return _sqlExpressionFactory.Function( diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerFullTextSearchFunctionsTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerFullTextSearchFunctionsTranslator.cs index b6f165c2861..65f19b5318d 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerFullTextSearchFunctionsTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerFullTextSearchFunctionsTranslator.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.SqlServer.Internal; @@ -72,10 +73,12 @@ public SqlServerFullTextSearchFunctionsTranslator([NotNull] ISqlExpressionFactor /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); if (_functionMapping.TryGetValue(method, out var functionName)) { diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerIsDateFunctionTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerIsDateFunctionTranslator.cs index 40937ed0cde..80f2c774e22 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerIsDateFunctionTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerIsDateFunctionTranslator.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -38,10 +39,12 @@ public SqlServerIsDateFunctionTranslator([NotNull] ISqlExpressionFactory sqlExpr /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); return _methodInfo.Equals(method) ? _sqlExpressionFactory.Convert( diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerMathTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerMathTranslator.cs index f19fea2046b..f28065b1eca 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerMathTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerMathTranslator.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -88,10 +89,12 @@ public SqlServerMathTranslator([NotNull] ISqlExpressionFactory sqlExpressionFact /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); if (_supportedMethodTranslations.TryGetValue(method, out var sqlFunctionName)) { diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerNewGuidTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerNewGuidTranslator.cs index f99ed6f9509..03d2d598380 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerNewGuidTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerNewGuidTranslator.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -39,10 +40,12 @@ public SqlServerNewGuidTranslator([NotNull] ISqlExpressionFactory sqlExpressionF /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); return _methodInfo.Equals(method) ? _sqlExpressionFactory.Function( diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerObjectToStringTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerObjectToStringTranslator.cs index 862094515b9..c347b8cb4be 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerObjectToStringTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerObjectToStringTranslator.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -62,10 +63,12 @@ public SqlServerObjectToStringTranslator([NotNull] ISqlExpressionFactory sqlExpr /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); return method.Name == nameof(ToString) && arguments.Count == 0 diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerStringMemberTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerStringMemberTranslator.cs index 81fb5d99401..ccf0a16441e 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerStringMemberTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerStringMemberTranslator.cs @@ -4,6 +4,7 @@ using System; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -37,10 +38,12 @@ public SqlServerStringMemberTranslator([NotNull] ISqlExpressionFactory sqlExpres /// 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 virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType) + public virtual SqlExpression Translate( + SqlExpression instance, MemberInfo member, Type returnType, IDiagnosticsLogger logger) { Check.NotNull(member, nameof(member)); Check.NotNull(returnType, nameof(returnType)); + Check.NotNull(logger, nameof(logger)); if (member.Name == nameof(string.Length) && instance?.Type == typeof(string)) diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerStringMethodTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerStringMethodTranslator.cs index 4ee83471a00..cc3a8e429a7 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerStringMethodTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerStringMethodTranslator.cs @@ -7,6 +7,7 @@ using System.Reflection; using System.Text; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -100,10 +101,12 @@ public SqlServerStringMethodTranslator([NotNull] ISqlExpressionFactory sqlExpres /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); if (_indexOfMethodInfo.Equals(method)) { diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerTimeSpanMemberTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerTimeSpanMemberTranslator.cs index 23b24c9de35..157ba379b51 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerTimeSpanMemberTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerTimeSpanMemberTranslator.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -46,10 +47,12 @@ public SqlServerTimeSpanMemberTranslator([NotNull] ISqlExpressionFactory sqlExpr /// 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 virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType) + public virtual SqlExpression Translate( + SqlExpression instance, MemberInfo member, Type returnType, IDiagnosticsLogger logger) { Check.NotNull(member, nameof(member)); Check.NotNull(returnType, nameof(returnType)); + Check.NotNull(logger, nameof(logger)); if (member.DeclaringType == typeof(TimeSpan) && _datePartMappings.TryGetValue(member.Name, out string value)) { diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteByteArrayMethodTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteByteArrayMethodTranslator.cs index 93ab19b3e86..9fa34b98c29 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteByteArrayMethodTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteByteArrayMethodTranslator.cs @@ -4,8 +4,10 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; +using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal { @@ -36,8 +38,12 @@ public SqliteByteArrayMethodTranslator([NotNull] ISqlExpressionFactory sqlExpres /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) { + Check.NotNull(method, nameof(method)); + Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); + if (method.IsGenericMethod && method.GetGenericMethodDefinition().Equals(EnumerableMethods.Contains) && arguments[0].Type == typeof(byte[])) diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteDateTimeAddTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteDateTimeAddTranslator.cs index 44bc84da709..3f2ccfecf48 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteDateTimeAddTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteDateTimeAddTranslator.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -54,10 +55,12 @@ public SqliteDateTimeAddTranslator([NotNull] ISqlExpressionFactory sqlExpression /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); SqlExpression modifier = null; if (_addMilliseconds.Equals(method)) diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteDateTimeMemberTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteDateTimeMemberTranslator.cs index ee955d59d24..87bf51dc016 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteDateTimeMemberTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteDateTimeMemberTranslator.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -51,10 +52,12 @@ public SqliteDateTimeMemberTranslator([NotNull] ISqlExpressionFactory sqlExpress /// 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 virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType) + public virtual SqlExpression Translate( + SqlExpression instance, MemberInfo member, Type returnType, IDiagnosticsLogger logger) { Check.NotNull(member, nameof(member)); Check.NotNull(returnType, nameof(returnType)); + Check.NotNull(logger, nameof(logger)); if (member.DeclaringType == typeof(DateTime)) { diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteMathTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteMathTranslator.cs index ee531b7e2a0..c44aa2a2393 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteMathTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteMathTranslator.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; @@ -70,10 +71,12 @@ public SqliteMathTranslator([NotNull] ISqlExpressionFactory sqlExpressionFactory /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); if (_supportedMethods.TryGetValue(method, out var sqlFunctionName)) { diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteStringLengthTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteStringLengthTranslator.cs index db694f386ce..a16107ad30b 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteStringLengthTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteStringLengthTranslator.cs @@ -4,6 +4,7 @@ using System; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -37,10 +38,11 @@ public SqliteStringLengthTranslator([NotNull] ISqlExpressionFactory sqlExpressio /// 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 virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType) + public virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType, IDiagnosticsLogger logger) { Check.NotNull(member, nameof(member)); Check.NotNull(returnType, nameof(returnType)); + Check.NotNull(logger, nameof(logger)); return instance?.Type == typeof(string) && member.Name == nameof(string.Length) diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteStringMethodTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteStringMethodTranslator.cs index eb855b2acb6..2c76fce0277 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteStringMethodTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteStringMethodTranslator.cs @@ -7,6 +7,7 @@ using System.Reflection; using System.Text; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -107,10 +108,12 @@ public SqliteStringMethodTranslator([NotNull] ISqlExpressionFactory sqlExpressio /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + SqlExpression instance, MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); if (_indexOfMethodInfo.Equals(method)) { diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMemberTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMemberTranslator.cs index da81ed3dc4f..ea1d9dff1e4 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMemberTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMemberTranslator.cs @@ -4,6 +4,7 @@ using System; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -39,10 +40,12 @@ public SqliteGeometryCollectionMemberTranslator([NotNull] ISqlExpressionFactory /// 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 virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType) + public virtual SqlExpression Translate( + SqlExpression instance, MemberInfo member, Type returnType, IDiagnosticsLogger logger) { Check.NotNull(member, nameof(member)); Check.NotNull(returnType, nameof(returnType)); + Check.NotNull(logger, nameof(logger)); return Equals(member, _count) ? _sqlExpressionFactory.Function( diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMethodTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMethodTranslator.cs index 3f41df868c7..33bf41e4555 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMethodTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMethodTranslator.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -39,10 +40,11 @@ public SqliteGeometryCollectionMethodTranslator([NotNull] ISqlExpressionFactory /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); if (Equals(method, _item)) { diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMemberTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMemberTranslator.cs index 82f4dba547e..dfda78815f2 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMemberTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMemberTranslator.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -59,10 +60,11 @@ public SqliteGeometryMemberTranslator([NotNull] ISqlExpressionFactory sqlExpress /// 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 virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType) + public virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType, IDiagnosticsLogger logger) { Check.NotNull(member, nameof(member)); Check.NotNull(returnType, nameof(returnType)); + Check.NotNull(logger, nameof(logger)); if (_memberToFunctionName.TryGetValue(member, out var functionName)) { diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMethodTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMethodTranslator.cs index 7bff9b15805..df688019a69 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMethodTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMethodTranslator.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -75,10 +76,11 @@ public SqliteGeometryMethodTranslator([NotNull] ISqlExpressionFactory sqlExpress /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); if (_methodToFunctionName.TryGetValue(method, out var functionName)) { diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMemberTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMemberTranslator.cs index 234ac14253e..d72a24876e3 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMemberTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMemberTranslator.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -49,10 +50,11 @@ public SqliteLineStringMemberTranslator([NotNull] ISqlExpressionFactory sqlExpre /// 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 virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType) + public virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType, IDiagnosticsLogger logger) { Check.NotNull(member, nameof(member)); Check.NotNull(returnType, nameof(returnType)); + Check.NotNull(logger, nameof(logger)); if (_memberToFunctionName.TryGetValue(member, out var functionName)) { diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMethodTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMethodTranslator.cs index 9b1bbdd880b..266c47c5b8e 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMethodTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMethodTranslator.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -41,10 +42,11 @@ public SqliteLineStringMethodTranslator([NotNull] ISqlExpressionFactory sqlExpre /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); if (Equals(method, _getPointN)) { diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteMultiLineStringMemberTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteMultiLineStringMemberTranslator.cs index f79d09c731e..bb8bd9db899 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteMultiLineStringMemberTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteMultiLineStringMemberTranslator.cs @@ -4,6 +4,7 @@ using System; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -39,10 +40,11 @@ public SqliteMultiLineStringMemberTranslator([NotNull] ISqlExpressionFactory sql /// 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 virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType) + public virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType, IDiagnosticsLogger logger) { Check.NotNull(member, nameof(member)); Check.NotNull(returnType, nameof(returnType)); + Check.NotNull(logger, nameof(logger)); if (Equals(member, _isClosed)) { diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePointMemberTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePointMemberTranslator.cs index 433d2ac820b..fafe4886541 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePointMemberTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePointMemberTranslator.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -47,10 +48,11 @@ public SqlitePointMemberTranslator([NotNull] ISqlExpressionFactory sqlExpression /// 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 virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType) + public virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType, IDiagnosticsLogger logger) { Check.NotNull(member, nameof(member)); Check.NotNull(returnType, nameof(returnType)); + Check.NotNull(logger, nameof(logger)); return _memberToFunctionName.TryGetValue(member, out var functionName) ? _sqlExpressionFactory.Function( diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMemberTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMemberTranslator.cs index df0a65ec13d..197a6101755 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMemberTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMemberTranslator.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -46,10 +47,11 @@ public SqlitePolygonMemberTranslator([NotNull] ISqlExpressionFactory sqlExpressi /// 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 virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType) + public virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType, IDiagnosticsLogger logger) { Check.NotNull(member, nameof(member)); Check.NotNull(returnType, nameof(returnType)); + Check.NotNull(logger, nameof(logger)); return _memberToFunctionName.TryGetValue(member, out var functionName) ? _sqlExpressionFactory.Function( diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMethodTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMethodTranslator.cs index ed9484d5327..e5011250283 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMethodTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMethodTranslator.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Utilities; @@ -41,10 +42,11 @@ public SqlitePolygonMethodTranslator([NotNull] ISqlExpressionFactory sqlExpressi /// 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 virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); + Check.NotNull(logger, nameof(logger)); if (Equals(method, _getInteriorRingN)) { diff --git a/test/EFCore.Relational.Tests/RelationalEventIdTest.cs b/test/EFCore.Relational.Tests/RelationalEventIdTest.cs index 8a706aafb44..150473521f5 100644 --- a/test/EFCore.Relational.Tests/RelationalEventIdTest.cs +++ b/test/EFCore.Relational.Tests/RelationalEventIdTest.cs @@ -11,6 +11,7 @@ using System.Threading; using System.Threading.Tasks; using System.Transactions; +using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -18,6 +19,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions; using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Query; +using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.TestUtilities; @@ -72,7 +75,8 @@ public void Every_eventId_has_a_logger_method_and_logs_when_level_enabled() { typeof(TypeInfo), () => typeof(object).GetTypeInfo() }, { typeof(Type), () => typeof(object) }, { typeof(ValueConverter), () => new BoolToZeroOneConverter() }, - { typeof(DbContext), () => new FakeDbContext() } + { typeof(DbContext), () => new FakeDbContext() }, + { typeof(SqlExpression), () => new FakeSqlExpression() } }; TestEventLogging( @@ -118,6 +122,16 @@ private class FakeMigration : Migration protected override void Up(MigrationBuilder migrationBuilder) => throw new NotImplementedException(); } + private class FakeSqlExpression : SqlExpression + { + public FakeSqlExpression() + : base(typeof(object), null) + { + } + + protected override void Print([NotNull] ExpressionPrinter expressionPrinter) => expressionPrinter.Append("FakeSqlExpression"); + } + private class FakeMigrator : IMigrator { public void Migrate(string targetMigration = null) => throw new NotImplementedException(); diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindWhereQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindWhereQuerySqlServerTest.cs index 6a7ed6406e6..1a0be44c6fb 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindWhereQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindWhereQuerySqlServerTest.cs @@ -1,7 +1,10 @@ // 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; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Diagnostics; +using Microsoft.EntityFrameworkCore.Diagnostics.Internal; using Microsoft.EntityFrameworkCore.TestUtilities; using Xunit; using Xunit.Abstractions; @@ -526,10 +529,7 @@ public override async Task Where_equals_using_object_overload_on_mismatched_type FROM [Employees] AS [e] WHERE 0 = 1"); - // See issue#17498 - //Assert.Contains( - // RelationalStrings.LogPossibleUnintendedUseOfEquals.GenerateMessage( - // "e.EmployeeID.Equals(Convert(__longPrm_0, Object))"), Fixture.TestSqlLoggerFactory.Log.Select(l => l.Message)); + Assert.Contains("Possible unintended use of method Equals(object) for arguments 'e.EmployeeID' and '@__longPrm_0' of different types in query. This comparison will always return 'false'.", Fixture.TestSqlLoggerFactory.Log.Select(l => l.Message)); } public override async Task Where_equals_using_int_overload_on_mismatched_types(bool async) @@ -557,14 +557,8 @@ FROM [Employees] AS [e] FROM [Employees] AS [e] WHERE 0 = 1"); - // See issue#17498 - //Assert.Contains( - // RelationalStrings.LogPossibleUnintendedUseOfEquals.GenerateMessage( - // "__longPrm_0.Equals(Convert(e.ReportsTo, Object))"), Fixture.TestSqlLoggerFactory.Log.Select(l => l.Message)); - - //Assert.Contains( - // RelationalStrings.LogPossibleUnintendedUseOfEquals.GenerateMessage( - // "e.ReportsTo.Equals(Convert(__longPrm_0, Object))"), Fixture.TestSqlLoggerFactory.Log.Select(l => l.Message)); + Assert.Contains("Possible unintended use of method Equals(object) for arguments 'e.ReportsTo' and '@__longPrm_0' of different types in query. This comparison will always return 'false'.", Fixture.TestSqlLoggerFactory.Log.Select(l => l.Message)); + Assert.Contains("Possible unintended use of method Equals(object) for arguments '@__longPrm_0' and 'e.ReportsTo' of different types in query. This comparison will always return 'false'.", Fixture.TestSqlLoggerFactory.Log.Select(l => l.Message)); } public override async Task Where_equals_on_mismatched_types_nullable_long_nullable_int(bool async) @@ -580,16 +574,8 @@ FROM [Employees] AS [e] FROM [Employees] AS [e] WHERE 0 = 1"); - // See issue#17498 - //Assert.Contains( - // RelationalStrings.LogPossibleUnintendedUseOfEquals.GenerateMessage( - // "__nullableLongPrm_0.Equals(Convert(e.ReportsTo, Object))"), - // Fixture.TestSqlLoggerFactory.Log.Select(l => l.Message)); - - //Assert.Contains( - // RelationalStrings.LogPossibleUnintendedUseOfEquals.GenerateMessage( - // "e.ReportsTo.Equals(Convert(__nullableLongPrm_0, Object))"), - // Fixture.TestSqlLoggerFactory.Log.Select(l => l.Message)); + Assert.Contains("Possible unintended use of method Equals(object) for arguments 'e.ReportsTo' and '@__nullableLongPrm_0' of different types in query. This comparison will always return 'false'.", Fixture.TestSqlLoggerFactory.Log.Select(l => l.Message)); + Assert.Contains("Possible unintended use of method Equals(object) for arguments '@__nullableLongPrm_0' and 'e.ReportsTo' of different types in query. This comparison will always return 'false'.", Fixture.TestSqlLoggerFactory.Log.Select(l => l.Message)); } public override async Task Where_equals_on_mismatched_types_int_nullable_int(bool async)