From 94620d77f72c71aef1f2bb0414f1380772e83e54 Mon Sep 17 00:00:00 2001 From: Arthur Vickers Date: Tue, 2 Nov 2021 16:01:43 +0000 Subject: [PATCH] Evolve null-checking approach in EFCore.InMemory Part of #19233 --- .../Internal/InMemoryDesignTimeServices.cs | 4 +- .../InMemoryEntityTypeExtensions.cs | 7 +- .../InMemoryServiceCollectionExtensions.cs | 3 - .../InMemoryDbContextOptionsBuilder.cs | 3 - .../Internal/InMemoryModelValidator.cs | 3 - .../CollectionResultShaperExpression.cs | 15 +- .../Internal/EntityProjectionExpression.cs | 3 - ...yExpressionTranslatingExpressionVisitor.cs | 26 --- ...emoryProjectionBindingExpressionVisitor.cs | 6 - .../InMemoryQueryExpression.Helper.cs | 6 +- .../Query/Internal/InMemoryQueryExpression.cs | 2 - ...yableMethodTranslatingExpressionVisitor.cs | 184 ++---------------- ...thodTranslatingExpressionVisitorFactory.cs | 6 +- ...erExpressionProcessingExpressionVisitor.cs | 4 - ...ryShapedQueryCompilingExpressionVisitor.cs | 5 - ...moryShapedQueryExpressionVisitorFactory.cs | 7 +- .../Query/Internal/InMemoryTableExpression.cs | 13 +- .../Internal/SingleResultShaperExpression.cs | 5 - .../Storage/Internal/InMemoryDatabase.cs | 10 +- .../Internal/InMemoryDatabaseCreator.cs | 3 - .../Storage/Internal/InMemoryTable.cs | 7 - .../Storage/Internal/InMemoryTableFactory.cs | 4 - .../Internal/InMemoryTransactionManager.cs | 3 - .../Internal/InMemoryIntegerValueGenerator.cs | 3 - .../InMemoryValueGeneratorSelector.cs | 10 +- 25 files changed, 30 insertions(+), 312 deletions(-) diff --git a/src/EFCore.InMemory/Design/Internal/InMemoryDesignTimeServices.cs b/src/EFCore.InMemory/Design/Internal/InMemoryDesignTimeServices.cs index 37f6609e5d4..6252cc7ccb0 100644 --- a/src/EFCore.InMemory/Design/Internal/InMemoryDesignTimeServices.cs +++ b/src/EFCore.InMemory/Design/Internal/InMemoryDesignTimeServices.cs @@ -3,7 +3,6 @@ using Microsoft.EntityFrameworkCore.Design; using Microsoft.EntityFrameworkCore.Design.Internal; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; [assembly: DesignTimeProviderServices("Microsoft.EntityFrameworkCore.InMemory.Design.Internal.InMemoryDesignTimeServices")] @@ -26,9 +25,8 @@ public class InMemoryDesignTimeServices : IDesignTimeServices /// public virtual void ConfigureDesignTimeServices(IServiceCollection serviceCollection) { - Check.NotNull(serviceCollection, nameof(serviceCollection)); - serviceCollection.AddEntityFrameworkInMemoryDatabase(); + #pragma warning disable EF1001 // Internal EF Core API usage. new EntityFrameworkDesignServicesBuilder(serviceCollection) .TryAdd() diff --git a/src/EFCore.InMemory/Extensions/InMemoryEntityTypeExtensions.cs b/src/EFCore.InMemory/Extensions/InMemoryEntityTypeExtensions.cs index aff987b553a..42e50eb83fc 100644 --- a/src/EFCore.InMemory/Extensions/InMemoryEntityTypeExtensions.cs +++ b/src/EFCore.InMemory/Extensions/InMemoryEntityTypeExtensions.cs @@ -4,7 +4,6 @@ using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Metadata.Internal; -using Microsoft.EntityFrameworkCore.Utilities; // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore @@ -26,7 +25,7 @@ public static class InMemoryEntityTypeExtensions public static LambdaExpression? GetInMemoryQuery(this IReadOnlyEntityType entityType) #pragma warning disable EF1001 // Internal EF Core API usage. #pragma warning disable CS0612 // Type or member is obsolete - => (LambdaExpression?)Check.NotNull(entityType, nameof(entityType))[CoreAnnotationNames.DefiningQuery]; + => (LambdaExpression?)entityType[CoreAnnotationNames.DefiningQuery]; #pragma warning restore CS0612 // Type or member is obsolete #pragma warning restore EF1001 // Internal EF Core API usage. @@ -38,7 +37,7 @@ public static class InMemoryEntityTypeExtensions public static void SetInMemoryQuery( this IMutableEntityType entityType, LambdaExpression? inMemoryQuery) - => Check.NotNull(entityType, nameof(entityType)) + => entityType #pragma warning disable EF1001 // Internal EF Core API usage. #pragma warning disable CS0612 // Type or member is obsolete .SetOrRemoveAnnotation(CoreAnnotationNames.DefiningQuery, inMemoryQuery); @@ -56,7 +55,7 @@ public static void SetInMemoryQuery( this IConventionEntityType entityType, LambdaExpression? inMemoryQuery, bool fromDataAnnotation = false) - => (LambdaExpression?)Check.NotNull(entityType, nameof(entityType)) + => (LambdaExpression?)entityType #pragma warning disable EF1001 // Internal EF Core API usage. #pragma warning disable CS0612 // Type or member is obsolete .SetOrRemoveAnnotation(CoreAnnotationNames.DefiningQuery, inMemoryQuery, fromDataAnnotation) diff --git a/src/EFCore.InMemory/Extensions/InMemoryServiceCollectionExtensions.cs b/src/EFCore.InMemory/Extensions/InMemoryServiceCollectionExtensions.cs index 0ac5642e3f2..57ea4ad9b0c 100644 --- a/src/EFCore.InMemory/Extensions/InMemoryServiceCollectionExtensions.cs +++ b/src/EFCore.InMemory/Extensions/InMemoryServiceCollectionExtensions.cs @@ -14,7 +14,6 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.EntityFrameworkCore.ValueGeneration; // ReSharper disable once CheckNamespace @@ -43,8 +42,6 @@ public static class InMemoryServiceCollectionExtensions [EditorBrowsable(EditorBrowsableState.Never)] public static IServiceCollection AddEntityFrameworkInMemoryDatabase(this IServiceCollection serviceCollection) { - Check.NotNull(serviceCollection, nameof(serviceCollection)); - var builder = new EntityFrameworkServicesBuilder(serviceCollection) .TryAdd() .TryAdd>() diff --git a/src/EFCore.InMemory/Infrastructure/InMemoryDbContextOptionsBuilder.cs b/src/EFCore.InMemory/Infrastructure/InMemoryDbContextOptionsBuilder.cs index 477b533d549..d81cbbf4e43 100644 --- a/src/EFCore.InMemory/Infrastructure/InMemoryDbContextOptionsBuilder.cs +++ b/src/EFCore.InMemory/Infrastructure/InMemoryDbContextOptionsBuilder.cs @@ -3,7 +3,6 @@ using System.ComponentModel; using Microsoft.EntityFrameworkCore.InMemory.Infrastructure.Internal; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Infrastructure { @@ -30,8 +29,6 @@ public class InMemoryDbContextOptionsBuilder : IInMemoryDbContextOptionsBuilderI /// The options builder. public InMemoryDbContextOptionsBuilder(DbContextOptionsBuilder optionsBuilder) { - Check.NotNull(optionsBuilder, nameof(optionsBuilder)); - OptionsBuilder = optionsBuilder; } diff --git a/src/EFCore.InMemory/Infrastructure/Internal/InMemoryModelValidator.cs b/src/EFCore.InMemory/Infrastructure/Internal/InMemoryModelValidator.cs index eb8cd42cdc8..81be79e5840 100644 --- a/src/EFCore.InMemory/Infrastructure/Internal/InMemoryModelValidator.cs +++ b/src/EFCore.InMemory/Infrastructure/Internal/InMemoryModelValidator.cs @@ -5,7 +5,6 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.InMemory.Infrastructure.Internal { @@ -50,8 +49,6 @@ protected virtual void ValidateDefiningQuery( IModel model, IDiagnosticsLogger logger) { - Check.NotNull(model, nameof(model)); - foreach (var entityType in model.GetEntityTypes()) { if (entityType.GetInMemoryQuery() != null) diff --git a/src/EFCore.InMemory/Query/Internal/CollectionResultShaperExpression.cs b/src/EFCore.InMemory/Query/Internal/CollectionResultShaperExpression.cs index 9343d94c4a9..7ac8f89b046 100644 --- a/src/EFCore.InMemory/Query/Internal/CollectionResultShaperExpression.cs +++ b/src/EFCore.InMemory/Query/Internal/CollectionResultShaperExpression.cs @@ -7,7 +7,6 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Query; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.InMemory.Query.Internal { @@ -31,9 +30,6 @@ public CollectionResultShaperExpression( INavigationBase? navigation, Type elementType) { - Check.NotNull(projection, nameof(projection)); - Check.NotNull(innerShaper, nameof(innerShaper)); - Projection = projection; InnerShaper = innerShaper; Navigation = navigation; @@ -83,8 +79,6 @@ public override Type Type /// protected override Expression VisitChildren(ExpressionVisitor visitor) { - Check.NotNull(visitor, nameof(visitor)); - var projection = visitor.Visit(Projection); var innerShaper = visitor.Visit(InnerShaper); @@ -100,20 +94,13 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) public virtual CollectionResultShaperExpression Update( Expression projection, Expression innerShaper) - { - Check.NotNull(projection, nameof(projection)); - Check.NotNull(innerShaper, nameof(innerShaper)); - - return projection != Projection || innerShaper != InnerShaper + => projection != Projection || innerShaper != InnerShaper ? new CollectionResultShaperExpression(projection, innerShaper, Navigation, ElementType) : this; - } /// void IPrintableExpression.Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - expressionPrinter.AppendLine("CollectionResultShaperExpression:"); using (expressionPrinter.Indent()) { diff --git a/src/EFCore.InMemory/Query/Internal/EntityProjectionExpression.cs b/src/EFCore.InMemory/Query/Internal/EntityProjectionExpression.cs index 7b28065021f..647dd75bdbb 100644 --- a/src/EFCore.InMemory/Query/Internal/EntityProjectionExpression.cs +++ b/src/EFCore.InMemory/Query/Internal/EntityProjectionExpression.cs @@ -8,7 +8,6 @@ using Microsoft.EntityFrameworkCore.InMemory.Internal; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Query; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.InMemory.Query.Internal { @@ -177,8 +176,6 @@ public virtual EntityProjectionExpression Clone() /// void IPrintableExpression.Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - expressionPrinter.AppendLine(nameof(EntityProjectionExpression) + ":"); using (expressionPrinter.Indent()) { diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs index 4bb2adf8ec9..e2305f305d4 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs @@ -107,8 +107,6 @@ public InMemoryExpressionTranslatingExpressionVisitor( /// protected virtual void AddTranslationErrorDetails(string details) { - Check.NotNull(details, nameof(details)); - if (TranslationErrorDetails == null) { TranslationErrorDetails = details; @@ -127,8 +125,6 @@ protected virtual void AddTranslationErrorDetails(string details) /// public virtual Expression? Translate(Expression expression) { - Check.NotNull(expression, nameof(expression)); - TranslationErrorDetails = null; return TranslateInternal(expression); @@ -152,8 +148,6 @@ protected virtual void AddTranslationErrorDetails(string details) /// protected override Expression VisitBinary(BinaryExpression binaryExpression) { - Check.NotNull(binaryExpression, nameof(binaryExpression)); - if (binaryExpression.Left.Type == typeof(object[]) && binaryExpression.Left is NewArrayExpression && binaryExpression.NodeType == ExpressionType.Equal) @@ -229,8 +223,6 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression) /// protected override Expression VisitConditional(ConditionalExpression conditionalExpression) { - Check.NotNull(conditionalExpression, nameof(conditionalExpression)); - var test = Visit(conditionalExpression.Test); var ifTrue = Visit(conditionalExpression.IfTrue); var ifFalse = Visit(conditionalExpression.IfFalse); @@ -265,8 +257,6 @@ protected override Expression VisitConditional(ConditionalExpression conditional /// protected override Expression VisitExtension(Expression extensionExpression) { - Check.NotNull(extensionExpression, nameof(extensionExpression)); - switch (extensionExpression) { case EntityProjectionExpression _: @@ -320,8 +310,6 @@ protected override Expression VisitListInit(ListInitExpression listInitExpressio /// protected override Expression VisitMember(MemberExpression memberExpression) { - Check.NotNull(memberExpression, nameof(memberExpression)); - var innerExpression = Visit(memberExpression.Expression); // when visiting unary we remove converts from nullable to non-nullable @@ -397,8 +385,6 @@ protected override MemberAssignment VisitMemberAssignment(MemberAssignment membe /// protected override Expression VisitMemberInit(MemberInitExpression memberInitExpression) { - Check.NotNull(memberInitExpression, nameof(memberInitExpression)); - var newExpression = Visit(memberInitExpression.NewExpression); if (newExpression == QueryCompilationContext.NotTranslatedExpression) { @@ -433,8 +419,6 @@ protected override Expression VisitMemberInit(MemberInitExpression memberInitExp /// protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression) { - Check.NotNull(methodCallExpression, nameof(methodCallExpression)); - if (methodCallExpression.Method.IsGenericMethod && methodCallExpression.Method.GetGenericMethodDefinition() == ExpressionExtensions.ValueBufferTryReadValueMethod) { @@ -721,8 +705,6 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp /// protected override Expression VisitNew(NewExpression newExpression) { - Check.NotNull(newExpression, nameof(newExpression)); - var newArguments = new List(); foreach (var argument in newExpression.Arguments) { @@ -751,8 +733,6 @@ protected override Expression VisitNew(NewExpression newExpression) /// protected override Expression VisitNewArray(NewArrayExpression newArrayExpression) { - Check.NotNull(newArrayExpression, nameof(newArrayExpression)); - var newExpressions = new List(); foreach (var expression in newArrayExpression.Expressions) { @@ -781,8 +761,6 @@ protected override Expression VisitNewArray(NewArrayExpression newArrayExpressio /// protected override Expression VisitParameter(ParameterExpression parameterExpression) { - Check.NotNull(parameterExpression, nameof(parameterExpression)); - if (parameterExpression.Name?.StartsWith(QueryCompilationContext.QueryParameterPrefix, StringComparison.Ordinal) == true) { return Expression.Call( @@ -802,8 +780,6 @@ protected override Expression VisitParameter(ParameterExpression parameterExpres /// protected override Expression VisitTypeBinary(TypeBinaryExpression typeBinaryExpression) { - Check.NotNull(typeBinaryExpression, nameof(typeBinaryExpression)); - if (typeBinaryExpression.NodeType == ExpressionType.TypeIs && Visit(typeBinaryExpression.Expression) is EntityReferenceExpression entityReferenceExpression) { @@ -851,8 +827,6 @@ protected override Expression VisitTypeBinary(TypeBinaryExpression typeBinaryExp /// protected override Expression VisitUnary(UnaryExpression unaryExpression) { - Check.NotNull(unaryExpression, nameof(unaryExpression)); - var newOperand = Visit(unaryExpression.Operand); if (newOperand == QueryCompilationContext.NotTranslatedExpression) { diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryProjectionBindingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryProjectionBindingExpressionVisitor.cs index b803b4aa596..c8ecb038cb9 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryProjectionBindingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryProjectionBindingExpressionVisitor.cs @@ -273,8 +273,6 @@ protected override Expression VisitConditional(ConditionalExpression conditional /// protected override Expression VisitExtension(Expression extensionExpression) { - Check.NotNull(extensionExpression, nameof(extensionExpression)); - if (extensionExpression is EntityShaperExpression entityShaperExpression) { EntityProjectionExpression entityProjectionExpression; @@ -395,8 +393,6 @@ protected override MemberAssignment VisitMemberAssignment(MemberAssignment membe /// protected override Expression VisitMemberInit(MemberInitExpression memberInitExpression) { - Check.NotNull(memberInitExpression, nameof(memberInitExpression)); - var newExpression = Visit(memberInitExpression.NewExpression); if (newExpression == QueryCompilationContext.NotTranslatedExpression) { @@ -469,8 +465,6 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp /// protected override Expression VisitNew(NewExpression newExpression) { - Check.NotNull(newExpression, nameof(newExpression)); - if (newExpression.Arguments.Count == 0) { return newExpression; diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.Helper.cs b/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.Helper.cs index af585efd23e..1466798f3ea 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.Helper.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.Helper.cs @@ -173,13 +173,9 @@ public ProjectionIndexRemappingExpressionVisitor( private sealed class EntityShaperNullableMarkingExpressionVisitor : ExpressionVisitor { protected override Expression VisitExtension(Expression extensionExpression) - { - Check.NotNull(extensionExpression, nameof(extensionExpression)); - - return extensionExpression is EntityShaperExpression entityShaper + => extensionExpression is EntityShaperExpression entityShaper ? entityShaper.MakeNullable() : base.VisitExtension(extensionExpression); - } } private sealed class QueryExpressionReplacingExpressionVisitor : ExpressionVisitor diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs b/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs index 56a19d61f0a..3fdbcb7c06e 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs @@ -800,8 +800,6 @@ public sealed override ExpressionType NodeType /// void IPrintableExpression.Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - expressionPrinter.AppendLine(nameof(InMemoryQueryExpression) + ": "); using (expressionPrinter.Indent()) { diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs index 9fa4cda167b..811d39a728a 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs @@ -147,9 +147,6 @@ private static ShapedQueryExpression CreateShapedQueryExpressionStatic(IEntityTy /// protected override ShapedQueryExpression? TranslateAll(ShapedQueryExpression source, LambdaExpression predicate) { - Check.NotNull(source, nameof(source)); - Check.NotNull(predicate, nameof(predicate)); - predicate = Expression.Lambda(Expression.Not(predicate.Body), predicate.Parameters); var newSource = TranslateWhere(source, predicate); if (newSource == null) @@ -219,12 +216,7 @@ private static ShapedQueryExpression CreateShapedQueryExpressionStatic(IEntityTy ShapedQueryExpression source, LambdaExpression? selector, Type resultType) - { - Check.NotNull(source, nameof(source)); - Check.NotNull(resultType, nameof(resultType)); - - return TranslateScalarAggregate(source, selector, nameof(Enumerable.Average), resultType); - } + => TranslateScalarAggregate(source, selector, nameof(Enumerable.Average), resultType); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -233,14 +225,9 @@ private static ShapedQueryExpression CreateShapedQueryExpressionStatic(IEntityTy /// doing so can result in application failures when updating to a new Entity Framework Core release. /// protected override ShapedQueryExpression? TranslateCast(ShapedQueryExpression source, Type resultType) - { - Check.NotNull(source, nameof(source)); - Check.NotNull(resultType, nameof(resultType)); - - return source.ShaperExpression.Type != resultType + => source.ShaperExpression.Type != resultType ? source.UpdateShaperExpression(Expression.Convert(source.ShaperExpression, resultType)) : source; - } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -249,12 +236,7 @@ private static ShapedQueryExpression CreateShapedQueryExpressionStatic(IEntityTy /// doing so can result in application failures when updating to a new Entity Framework Core release. /// protected override ShapedQueryExpression? TranslateConcat(ShapedQueryExpression source1, ShapedQueryExpression source2) - { - Check.NotNull(source1, nameof(source1)); - Check.NotNull(source2, nameof(source2)); - - return TranslateSetOperation(EnumerableMethods.Concat, source1, source2); - } + => TranslateSetOperation(EnumerableMethods.Concat, source1, source2); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -264,9 +246,6 @@ private static ShapedQueryExpression CreateShapedQueryExpressionStatic(IEntityTy /// protected override ShapedQueryExpression? TranslateContains(ShapedQueryExpression source, Expression item) { - Check.NotNull(source, nameof(source)); - Check.NotNull(item, nameof(item)); - var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression; var newItem = TranslateExpression(item, preserveType: true); if (newItem == null) @@ -299,8 +278,6 @@ private static ShapedQueryExpression CreateShapedQueryExpressionStatic(IEntityTy /// protected override ShapedQueryExpression? TranslateCount(ShapedQueryExpression source, LambdaExpression? predicate) { - Check.NotNull(source, nameof(source)); - if (predicate != null) { var newSource = TranslateWhere(source, predicate); @@ -335,8 +312,6 @@ private static ShapedQueryExpression CreateShapedQueryExpressionStatic(IEntityTy /// protected override ShapedQueryExpression? TranslateDefaultIfEmpty(ShapedQueryExpression source, Expression? defaultValue) { - Check.NotNull(source, nameof(source)); - if (defaultValue == null) { ((InMemoryQueryExpression)source.QueryExpression).ApplyDefaultIfEmpty(); @@ -354,8 +329,6 @@ private static ShapedQueryExpression CreateShapedQueryExpressionStatic(IEntityTy /// protected override ShapedQueryExpression? TranslateDistinct(ShapedQueryExpression source) { - Check.NotNull(source, nameof(source)); - ((InMemoryQueryExpression)source.QueryExpression).ApplyDistinct(); return source; @@ -371,12 +344,7 @@ private static ShapedQueryExpression CreateShapedQueryExpressionStatic(IEntityTy ShapedQueryExpression source, Expression index, bool returnDefault) - { - Check.NotNull(source, nameof(source)); - Check.NotNull(index, nameof(index)); - - return null; - } + => null; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -385,12 +353,7 @@ private static ShapedQueryExpression CreateShapedQueryExpressionStatic(IEntityTy /// doing so can result in application failures when updating to a new Entity Framework Core release. /// protected override ShapedQueryExpression? TranslateExcept(ShapedQueryExpression source1, ShapedQueryExpression source2) - { - Check.NotNull(source1, nameof(source1)); - Check.NotNull(source2, nameof(source2)); - - return TranslateSetOperation(EnumerableMethods.Except, source1, source2); - } + => TranslateSetOperation(EnumerableMethods.Except, source1, source2); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -403,18 +366,13 @@ private static ShapedQueryExpression CreateShapedQueryExpressionStatic(IEntityTy LambdaExpression? predicate, Type returnType, bool returnDefault) - { - Check.NotNull(source, nameof(source)); - Check.NotNull(returnType, nameof(returnType)); - - return TranslateSingleResultOperator( + => TranslateSingleResultOperator( source, predicate, returnType, returnDefault ? EnumerableMethods.FirstOrDefaultWithoutPredicate : EnumerableMethods.FirstWithoutPredicate); - } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -428,9 +386,6 @@ private static ShapedQueryExpression CreateShapedQueryExpressionStatic(IEntityTy LambdaExpression? elementSelector, LambdaExpression? resultSelector) { - Check.NotNull(source, nameof(source)); - Check.NotNull(keySelector, nameof(keySelector)); - var remappedKeySelector = RemapLambdaBody(source, keySelector); var translatedKey = TranslateGroupingKey(remappedKeySelector); @@ -537,15 +492,7 @@ private static ShapedQueryExpression CreateShapedQueryExpressionStatic(IEntityTy LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, LambdaExpression resultSelector) - { - Check.NotNull(outer, nameof(outer)); - Check.NotNull(inner, nameof(inner)); - Check.NotNull(outerKeySelector, nameof(outerKeySelector)); - Check.NotNull(innerKeySelector, nameof(innerKeySelector)); - Check.NotNull(resultSelector, nameof(resultSelector)); - - return null; - } + => null; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -554,12 +501,7 @@ private static ShapedQueryExpression CreateShapedQueryExpressionStatic(IEntityTy /// doing so can result in application failures when updating to a new Entity Framework Core release. /// protected override ShapedQueryExpression? TranslateIntersect(ShapedQueryExpression source1, ShapedQueryExpression source2) - { - Check.NotNull(source1, nameof(source1)); - Check.NotNull(source2, nameof(source2)); - - return TranslateSetOperation(EnumerableMethods.Intersect, source1, source2); - } + => TranslateSetOperation(EnumerableMethods.Intersect, source1, source2); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -574,12 +516,6 @@ private static ShapedQueryExpression CreateShapedQueryExpressionStatic(IEntityTy LambdaExpression innerKeySelector, LambdaExpression resultSelector) { - Check.NotNull(outer, nameof(outer)); - Check.NotNull(inner, nameof(inner)); - Check.NotNull(outerKeySelector, nameof(outerKeySelector)); - Check.NotNull(innerKeySelector, nameof(innerKeySelector)); - Check.NotNull(resultSelector, nameof(resultSelector)); - var (newOuterKeySelector, newInnerKeySelector) = ProcessJoinKeySelector(outer, inner, outerKeySelector, innerKeySelector); if (newOuterKeySelector == null @@ -720,18 +656,13 @@ static bool IsConvertedToNullable(Expression outer, Expression inner) LambdaExpression? predicate, Type returnType, bool returnDefault) - { - Check.NotNull(source, nameof(source)); - Check.NotNull(returnType, nameof(returnType)); - - return TranslateSingleResultOperator( + => TranslateSingleResultOperator( source, predicate, returnType, returnDefault ? EnumerableMethods.LastOrDefaultWithoutPredicate : EnumerableMethods.LastWithoutPredicate); - } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -746,12 +677,6 @@ static bool IsConvertedToNullable(Expression outer, Expression inner) LambdaExpression innerKeySelector, LambdaExpression resultSelector) { - Check.NotNull(outer, nameof(outer)); - Check.NotNull(inner, nameof(inner)); - Check.NotNull(outerKeySelector, nameof(outerKeySelector)); - Check.NotNull(innerKeySelector, nameof(innerKeySelector)); - Check.NotNull(resultSelector, nameof(resultSelector)); - var (newOuterKeySelector, newInnerKeySelector) = ProcessJoinKeySelector(outer, inner, outerKeySelector, innerKeySelector); if (newOuterKeySelector == null @@ -782,8 +707,6 @@ static bool IsConvertedToNullable(Expression outer, Expression inner) /// protected override ShapedQueryExpression? TranslateLongCount(ShapedQueryExpression source, LambdaExpression? predicate) { - Check.NotNull(source, nameof(source)); - if (predicate != null) { var newSource = TranslateWhere(source, predicate); @@ -821,11 +744,7 @@ static bool IsConvertedToNullable(Expression outer, Expression inner) ShapedQueryExpression source, LambdaExpression? selector, Type resultType) - { - Check.NotNull(source, nameof(source)); - - return TranslateScalarAggregate(source, selector, nameof(Enumerable.Max), resultType); - } + => TranslateScalarAggregate(source, selector, nameof(Enumerable.Max), resultType); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -834,11 +753,7 @@ static bool IsConvertedToNullable(Expression outer, Expression inner) /// doing so can result in application failures when updating to a new Entity Framework Core release. /// protected override ShapedQueryExpression? TranslateMin(ShapedQueryExpression source, LambdaExpression? selector, Type resultType) - { - Check.NotNull(source, nameof(source)); - - return TranslateScalarAggregate(source, selector, nameof(Enumerable.Min), resultType); - } + => TranslateScalarAggregate(source, selector, nameof(Enumerable.Min), resultType); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -848,9 +763,6 @@ static bool IsConvertedToNullable(Expression outer, Expression inner) /// protected override ShapedQueryExpression? TranslateOfType(ShapedQueryExpression source, Type resultType) { - Check.NotNull(source, nameof(source)); - Check.NotNull(resultType, nameof(resultType)); - if (source.ShaperExpression is EntityShaperExpression entityShaperExpression) { var entityType = entityShaperExpression.EntityType; @@ -908,9 +820,6 @@ static bool IsConvertedToNullable(Expression outer, Expression inner) LambdaExpression keySelector, bool ascending) { - Check.NotNull(source, nameof(source)); - Check.NotNull(keySelector, nameof(keySelector)); - var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression; var newKeySelector = TranslateLambdaExpression(source, keySelector); @@ -939,8 +848,6 @@ static bool IsConvertedToNullable(Expression outer, Expression inner) /// protected override ShapedQueryExpression? TranslateReverse(ShapedQueryExpression source) { - Check.NotNull(source, nameof(source)); - var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression; inMemoryQueryExpression.UpdateServerQueryExpression( @@ -959,9 +866,6 @@ static bool IsConvertedToNullable(Expression outer, Expression inner) /// protected override ShapedQueryExpression TranslateSelect(ShapedQueryExpression source, LambdaExpression selector) { - Check.NotNull(source, nameof(source)); - Check.NotNull(selector, nameof(selector)); - if (selector.Body == selector.Parameters[0]) { return source; @@ -985,10 +889,6 @@ protected override ShapedQueryExpression TranslateSelect(ShapedQueryExpression s LambdaExpression collectionSelector, LambdaExpression resultSelector) { - Check.NotNull(source, nameof(source)); - Check.NotNull(collectionSelector, nameof(collectionSelector)); - Check.NotNull(resultSelector, nameof(resultSelector)); - var defaultIfEmpty = new DefaultIfEmptyFindingExpressionVisitor().IsOptional(collectionSelector); var collectionSelectorBody = RemapLambdaBody(source, collectionSelector); @@ -1020,8 +920,6 @@ public bool IsOptional(LambdaExpression lambdaExpression) protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression) { - Check.NotNull(methodCallExpression, nameof(methodCallExpression)); - if (methodCallExpression.Method.IsGenericMethod && methodCallExpression.Method.GetGenericMethodDefinition() == QueryableMethods.DefaultIfEmptyWithoutArgument) { @@ -1040,9 +938,6 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp /// protected override ShapedQueryExpression? TranslateSelectMany(ShapedQueryExpression source, LambdaExpression selector) { - Check.NotNull(source, nameof(source)); - Check.NotNull(selector, nameof(selector)); - var innerParameter = Expression.Parameter(selector.ReturnType.GetSequenceType(), "i"); var resultSelector = Expression.Lambda( innerParameter, Expression.Parameter(source.Type.GetSequenceType()), innerParameter); @@ -1061,18 +956,13 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp LambdaExpression? predicate, Type returnType, bool returnDefault) - { - Check.NotNull(source, nameof(source)); - Check.NotNull(returnType, nameof(returnType)); - - return TranslateSingleResultOperator( + => TranslateSingleResultOperator( source, predicate, returnType, returnDefault ? EnumerableMethods.SingleOrDefaultWithoutPredicate : EnumerableMethods.SingleWithoutPredicate); - } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -1082,9 +972,6 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp /// protected override ShapedQueryExpression? TranslateSkip(ShapedQueryExpression source, Expression count) { - Check.NotNull(source, nameof(source)); - Check.NotNull(count, nameof(count)); - var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression; var newCount = TranslateExpression(count); if (newCount == null) @@ -1110,12 +997,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp /// doing so can result in application failures when updating to a new Entity Framework Core release. /// protected override ShapedQueryExpression? TranslateSkipWhile(ShapedQueryExpression source, LambdaExpression predicate) - { - Check.NotNull(source, nameof(source)); - Check.NotNull(predicate, nameof(predicate)); - - return null; - } + => null; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -1124,12 +1006,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp /// doing so can result in application failures when updating to a new Entity Framework Core release. /// protected override ShapedQueryExpression? TranslateSum(ShapedQueryExpression source, LambdaExpression? selector, Type resultType) - { - Check.NotNull(source, nameof(source)); - Check.NotNull(resultType, nameof(resultType)); - - return TranslateScalarAggregate(source, selector, nameof(Enumerable.Sum), resultType); - } + => TranslateScalarAggregate(source, selector, nameof(Enumerable.Sum), resultType); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -1139,9 +1016,6 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp /// protected override ShapedQueryExpression? TranslateTake(ShapedQueryExpression source, Expression count) { - Check.NotNull(source, nameof(source)); - Check.NotNull(count, nameof(count)); - var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression; var newCount = TranslateExpression(count); if (newCount == null) @@ -1167,12 +1041,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp /// doing so can result in application failures when updating to a new Entity Framework Core release. /// protected override ShapedQueryExpression? TranslateTakeWhile(ShapedQueryExpression source, LambdaExpression predicate) - { - Check.NotNull(source, nameof(source)); - Check.NotNull(predicate, nameof(predicate)); - - return null; - } + => null; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -1185,9 +1054,6 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp LambdaExpression keySelector, bool ascending) { - Check.NotNull(source, nameof(source)); - Check.NotNull(keySelector, nameof(keySelector)); - var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression; var newKeySelector = TranslateLambdaExpression(source, keySelector); if (newKeySelector == null) @@ -1214,12 +1080,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp /// doing so can result in application failures when updating to a new Entity Framework Core release. /// protected override ShapedQueryExpression? TranslateUnion(ShapedQueryExpression source1, ShapedQueryExpression source2) - { - Check.NotNull(source1, nameof(source1)); - Check.NotNull(source2, nameof(source2)); - - return TranslateSetOperation(EnumerableMethods.Union, source1, source2); - } + => TranslateSetOperation(EnumerableMethods.Union, source1, source2); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -1229,9 +1090,6 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp /// protected override ShapedQueryExpression? TranslateWhere(ShapedQueryExpression source, LambdaExpression predicate) { - Check.NotNull(source, nameof(source)); - Check.NotNull(predicate, nameof(predicate)); - var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression; var newPredicate = TranslateLambdaExpression(source, predicate, preserveType: true); if (newPredicate == null) @@ -1323,8 +1181,6 @@ public Expression Expand(InMemoryQueryExpression queryExpression, Expression lam protected override Expression VisitMember(MemberExpression memberExpression) { - Check.NotNull(memberExpression, nameof(memberExpression)); - var innerExpression = Visit(memberExpression.Expression); return TryExpand(innerExpression, MemberIdentity.Create(memberExpression.Member)) @@ -1333,8 +1189,6 @@ protected override Expression VisitMember(MemberExpression memberExpression) protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression) { - Check.NotNull(methodCallExpression, nameof(methodCallExpression)); - if (methodCallExpression.TryGetEFPropertyArguments(out var source, out var navigationName)) { source = Visit(source); @@ -1355,14 +1209,10 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp } protected override Expression VisitExtension(Expression extensionExpression) - { - Check.NotNull(extensionExpression, nameof(extensionExpression)); - - return extensionExpression is EntityShaperExpression + => extensionExpression is EntityShaperExpression || extensionExpression is ShapedQueryExpression ? extensionExpression : base.VisitExtension(extensionExpression); - } private Expression? TryExpand(Expression? source, MemberIdentity member) { diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitorFactory.cs b/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitorFactory.cs index 100e0fcbbc8..30315f3a334 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitorFactory.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitorFactory.cs @@ -38,10 +38,6 @@ public InMemoryQueryableMethodTranslatingExpressionVisitorFactory( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual QueryableMethodTranslatingExpressionVisitor Create(QueryCompilationContext queryCompilationContext) - { - Check.NotNull(queryCompilationContext, nameof(queryCompilationContext)); - - return new InMemoryQueryableMethodTranslatingExpressionVisitor(Dependencies, queryCompilationContext); - } + => new InMemoryQueryableMethodTranslatingExpressionVisitor(Dependencies, queryCompilationContext); } } diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.ShaperExpressionProcessingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.ShaperExpressionProcessingExpressionVisitor.cs index ceb46436932..838e5418d4a 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.ShaperExpressionProcessingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.ShaperExpressionProcessingExpressionVisitor.cs @@ -216,8 +216,6 @@ protected override Expression VisitExtension(Expression extensionExpression) protected override Expression VisitBinary(BinaryExpression binaryExpression) { - Check.NotNull(binaryExpression, nameof(binaryExpression)); - if (binaryExpression.NodeType == ExpressionType.Assign && binaryExpression.Left is ParameterExpression parameterExpression && parameterExpression.Type == typeof(MaterializationContext)) @@ -253,8 +251,6 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression) protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression) { - Check.NotNull(methodCallExpression, nameof(methodCallExpression)); - if (methodCallExpression.Method.IsGenericMethod && methodCallExpression.Method.GetGenericMethodDefinition() == ExpressionExtensions.ValueBufferTryReadValueMethod) { diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.cs index 7e49fa39665..26ffdbb2267 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.cs @@ -8,7 +8,6 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.InMemory.Query.Internal { @@ -40,8 +39,6 @@ public InMemoryShapedQueryCompilingExpressionVisitor( /// protected override Expression VisitExtension(Expression extensionExpression) { - Check.NotNull(extensionExpression, nameof(extensionExpression)); - switch (extensionExpression) { case InMemoryTableExpression inMemoryTableExpression: @@ -62,8 +59,6 @@ protected override Expression VisitExtension(Expression extensionExpression) /// protected override Expression VisitShapedQuery(ShapedQueryExpression shapedQueryExpression) { - Check.NotNull(shapedQueryExpression, nameof(shapedQueryExpression)); - var inMemoryQueryExpression = (InMemoryQueryExpression)shapedQueryExpression.QueryExpression; inMemoryQueryExpression.ApplyProjection(); diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryExpressionVisitorFactory.cs b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryExpressionVisitorFactory.cs index 003d9dfee72..e07ec1b202e 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryExpressionVisitorFactory.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryExpressionVisitorFactory.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.EntityFrameworkCore.Query; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.InMemory.Query.Internal { @@ -38,10 +37,6 @@ public InMemoryShapedQueryCompilingExpressionVisitorFactory( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual ShapedQueryCompilingExpressionVisitor Create(QueryCompilationContext queryCompilationContext) - { - Check.NotNull(queryCompilationContext, nameof(queryCompilationContext)); - - return new InMemoryShapedQueryCompilingExpressionVisitor(Dependencies, queryCompilationContext); - } + => new InMemoryShapedQueryCompilingExpressionVisitor(Dependencies, queryCompilationContext); } } diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryTableExpression.cs b/src/EFCore.InMemory/Query/Internal/InMemoryTableExpression.cs index 7a61c14ac2c..41a19bd9e08 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryTableExpression.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryTableExpression.cs @@ -7,7 +7,6 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.InMemory.Query.Internal { @@ -63,11 +62,7 @@ public sealed override ExpressionType NodeType /// doing so can result in application failures when updating to a new Entity Framework Core release. /// protected override Expression VisitChildren(ExpressionVisitor visitor) - { - Check.NotNull(visitor, nameof(visitor)); - - return this; - } + => this; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -76,10 +71,6 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// doing so can result in application failures when updating to a new Entity Framework Core release. /// void IPrintableExpression.Print(ExpressionPrinter expressionPrinter) - { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - - expressionPrinter.Append(nameof(InMemoryTableExpression) + ": Entity: " + EntityType.DisplayName()); - } + => expressionPrinter.Append(nameof(InMemoryTableExpression) + ": Entity: " + EntityType.DisplayName()); } } diff --git a/src/EFCore.InMemory/Query/Internal/SingleResultShaperExpression.cs b/src/EFCore.InMemory/Query/Internal/SingleResultShaperExpression.cs index c9252eaa48d..b1245603736 100644 --- a/src/EFCore.InMemory/Query/Internal/SingleResultShaperExpression.cs +++ b/src/EFCore.InMemory/Query/Internal/SingleResultShaperExpression.cs @@ -4,7 +4,6 @@ using System; using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Query; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.InMemory.Query.Internal { @@ -39,8 +38,6 @@ public SingleResultShaperExpression( /// protected override Expression VisitChildren(ExpressionVisitor visitor) { - Check.NotNull(visitor, nameof(visitor)); - var projection = visitor.Visit(Projection); var innerShaper = visitor.Visit(InnerShaper); @@ -99,8 +96,6 @@ public sealed override ExpressionType NodeType /// void IPrintableExpression.Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - expressionPrinter.AppendLine($"{nameof(SingleResultShaperExpression)}:"); using (expressionPrinter.Indent()) { diff --git a/src/EFCore.InMemory/Storage/Internal/InMemoryDatabase.cs b/src/EFCore.InMemory/Storage/Internal/InMemoryDatabase.cs index 38f80174d0b..8e83c7c143e 100644 --- a/src/EFCore.InMemory/Storage/Internal/InMemoryDatabase.cs +++ b/src/EFCore.InMemory/Storage/Internal/InMemoryDatabase.cs @@ -9,7 +9,6 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Update; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.InMemory.Storage.Internal { @@ -41,11 +40,6 @@ public InMemoryDatabase( IDiagnosticsLogger updateLogger) : base(dependencies) { - Check.NotNull(storeCache, nameof(storeCache)); - Check.NotNull(options, nameof(options)); - Check.NotNull(updateAdapterFactory, nameof(updateAdapterFactory)); - Check.NotNull(updateLogger, nameof(updateLogger)); - _store = storeCache.GetStore(options); _designTimeModel = designTimeModel; _updateAdapterFactory = updateAdapterFactory; @@ -68,7 +62,7 @@ public virtual IInMemoryStore Store /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public override int SaveChanges(IList entries) - => _store.ExecuteTransaction(Check.NotNull(entries, nameof(entries)), _updateLogger); + => _store.ExecuteTransaction(entries, _updateLogger); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -79,7 +73,7 @@ public override int SaveChanges(IList entries) public override Task SaveChangesAsync( IList entries, CancellationToken cancellationToken = default) - => Task.FromResult(_store.ExecuteTransaction(Check.NotNull(entries, nameof(entries)), _updateLogger)); + => Task.FromResult(_store.ExecuteTransaction(entries, _updateLogger)); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.InMemory/Storage/Internal/InMemoryDatabaseCreator.cs b/src/EFCore.InMemory/Storage/Internal/InMemoryDatabaseCreator.cs index a661e78a864..9914ee46c19 100644 --- a/src/EFCore.InMemory/Storage/Internal/InMemoryDatabaseCreator.cs +++ b/src/EFCore.InMemory/Storage/Internal/InMemoryDatabaseCreator.cs @@ -4,7 +4,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.InMemory.Storage.Internal { @@ -26,8 +25,6 @@ public class InMemoryDatabaseCreator : IDatabaseCreator /// public InMemoryDatabaseCreator(IDatabase database) { - Check.NotNull(database, nameof(database)); - _database = database; } diff --git a/src/EFCore.InMemory/Storage/Internal/InMemoryTable.cs b/src/EFCore.InMemory/Storage/Internal/InMemoryTable.cs index 26184706fa3..eb284c42927 100644 --- a/src/EFCore.InMemory/Storage/Internal/InMemoryTable.cs +++ b/src/EFCore.InMemory/Storage/Internal/InMemoryTable.cs @@ -12,7 +12,6 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Update; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.InMemory.Storage.Internal { @@ -384,9 +383,6 @@ private void ThrowNullabilityErrorException( IUpdateEntry entry, IList nullabilityErrors) { - Check.NotNull(entry, nameof(entry)); - Check.NotNull(nullabilityErrors, nameof(nullabilityErrors)); - if (_sensitiveLoggingEnabled) { throw new DbUpdateException( @@ -413,9 +409,6 @@ protected virtual void ThrowUpdateConcurrencyException( IUpdateEntry entry, Dictionary concurrencyConflicts) { - Check.NotNull(entry, nameof(entry)); - Check.NotNull(concurrencyConflicts, nameof(concurrencyConflicts)); - if (_sensitiveLoggingEnabled) { throw new DbUpdateConcurrencyException( diff --git a/src/EFCore.InMemory/Storage/Internal/InMemoryTableFactory.cs b/src/EFCore.InMemory/Storage/Internal/InMemoryTableFactory.cs index ca3484f66c5..4fa9e9df989 100644 --- a/src/EFCore.InMemory/Storage/Internal/InMemoryTableFactory.cs +++ b/src/EFCore.InMemory/Storage/Internal/InMemoryTableFactory.cs @@ -8,7 +8,6 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.InMemory.Infrastructure.Internal; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.InMemory.Storage.Internal { @@ -35,9 +34,6 @@ public InMemoryTableFactory( ILoggingOptions loggingOptions, IInMemorySingletonOptions options) { - Check.NotNull(loggingOptions, nameof(loggingOptions)); - Check.NotNull(options, nameof(options)); - _sensitiveLoggingEnabled = loggingOptions.IsSensitiveDataLoggingEnabled; _nullabilityCheckEnabled = options.IsNullabilityCheckEnabled; } diff --git a/src/EFCore.InMemory/Storage/Internal/InMemoryTransactionManager.cs b/src/EFCore.InMemory/Storage/Internal/InMemoryTransactionManager.cs index 744b5b4be84..85a92bea392 100644 --- a/src/EFCore.InMemory/Storage/Internal/InMemoryTransactionManager.cs +++ b/src/EFCore.InMemory/Storage/Internal/InMemoryTransactionManager.cs @@ -7,7 +7,6 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.InMemory.Internal; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.InMemory.Storage.Internal { @@ -32,8 +31,6 @@ public class InMemoryTransactionManager : IDbContextTransactionManager, ITransac public InMemoryTransactionManager( IDiagnosticsLogger logger) { - Check.NotNull(logger, nameof(logger)); - _logger = logger; } diff --git a/src/EFCore.InMemory/ValueGeneration/Internal/InMemoryIntegerValueGenerator.cs b/src/EFCore.InMemory/ValueGeneration/Internal/InMemoryIntegerValueGenerator.cs index 2a20036ae24..64dc681e9e9 100644 --- a/src/EFCore.InMemory/ValueGeneration/Internal/InMemoryIntegerValueGenerator.cs +++ b/src/EFCore.InMemory/ValueGeneration/Internal/InMemoryIntegerValueGenerator.cs @@ -5,7 +5,6 @@ using System.Globalization; using System.Threading; using Microsoft.EntityFrameworkCore.ChangeTracking; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.EntityFrameworkCore.ValueGeneration; namespace Microsoft.EntityFrameworkCore.InMemory.ValueGeneration.Internal @@ -40,8 +39,6 @@ public InMemoryIntegerValueGenerator(int propertyIndex) /// public virtual void Bump(object?[] row) { - Check.NotNull(row, nameof(row)); - var newValue = (long)Convert.ChangeType(row[_propertyIndex]!, typeof(long)); if (_current < newValue) diff --git a/src/EFCore.InMemory/ValueGeneration/Internal/InMemoryValueGeneratorSelector.cs b/src/EFCore.InMemory/ValueGeneration/Internal/InMemoryValueGeneratorSelector.cs index 68f511899b1..7f292da031a 100644 --- a/src/EFCore.InMemory/ValueGeneration/Internal/InMemoryValueGeneratorSelector.cs +++ b/src/EFCore.InMemory/ValueGeneration/Internal/InMemoryValueGeneratorSelector.cs @@ -5,7 +5,6 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.InMemory.Storage.Internal; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.EntityFrameworkCore.ValueGeneration; namespace Microsoft.EntityFrameworkCore.InMemory.ValueGeneration.Internal @@ -41,16 +40,11 @@ public InMemoryValueGeneratorSelector( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public override ValueGenerator Select(IProperty property, IEntityType entityType) - { - Check.NotNull(property, nameof(property)); - Check.NotNull(entityType, nameof(entityType)); - - return property.GetValueGeneratorFactory() == null + => property.GetValueGeneratorFactory() == null && property.ClrType.IsInteger() && property.ClrType.UnwrapNullableType() != typeof(char) ? GetOrCreate(property) : base.Select(property, entityType); - } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -60,8 +54,6 @@ public override ValueGenerator Select(IProperty property, IEntityType entityType /// private ValueGenerator GetOrCreate(IProperty property) { - Check.NotNull(property, nameof(property)); - var type = property.ClrType.UnwrapNullableType().UnwrapEnumType(); if (type == typeof(long))