diff --git a/src/EFCore.Relational/Design/AnnotationCodeGenerator.cs b/src/EFCore.Relational/Design/AnnotationCodeGenerator.cs index ea830e15f1f..f7e67e4bbe1 100644 --- a/src/EFCore.Relational/Design/AnnotationCodeGenerator.cs +++ b/src/EFCore.Relational/Design/AnnotationCodeGenerator.cs @@ -11,7 +11,6 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Internal; -using Microsoft.EntityFrameworkCore.Utilities; #pragma warning disable EF1001 // Accessing annotation names (internal) @@ -123,8 +122,6 @@ private static readonly MethodInfo _indexHasFilterNameMethodInfo /// Parameter object containing dependencies for this service. public AnnotationCodeGenerator(AnnotationCodeGeneratorDependencies dependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Dependencies = dependencies; } @@ -393,12 +390,7 @@ public virtual IReadOnlyList GenerateDataAnnotationAttrib /// if code must be generated. /// protected virtual bool IsHandledByConvention(IModel model, IAnnotation annotation) - { - Check.NotNull(model, nameof(model)); - Check.NotNull(annotation, nameof(annotation)); - - return false; - } + => false; /// /// Checks if the given is handled by convention when @@ -411,12 +403,7 @@ protected virtual bool IsHandledByConvention(IModel model, IAnnotation annotatio /// The . /// . protected virtual bool IsHandledByConvention(IEntityType entityType, IAnnotation annotation) - { - Check.NotNull(entityType, nameof(entityType)); - Check.NotNull(annotation, nameof(annotation)); - - return false; - } + => false; /// /// Checks if the given is handled by convention when @@ -429,12 +416,7 @@ protected virtual bool IsHandledByConvention(IEntityType entityType, IAnnotation /// The . /// . protected virtual bool IsHandledByConvention(IKey key, IAnnotation annotation) - { - Check.NotNull(key, nameof(key)); - Check.NotNull(annotation, nameof(annotation)); - - return false; - } + => false; /// /// Checks if the given is handled by convention when @@ -447,12 +429,7 @@ protected virtual bool IsHandledByConvention(IKey key, IAnnotation annotation) /// The . /// . protected virtual bool IsHandledByConvention(IProperty property, IAnnotation annotation) - { - Check.NotNull(property, nameof(property)); - Check.NotNull(annotation, nameof(annotation)); - - return false; - } + => false; /// /// Checks if the given is handled by convention when @@ -465,12 +442,7 @@ protected virtual bool IsHandledByConvention(IProperty property, IAnnotation ann /// The . /// . protected virtual bool IsHandledByConvention(IForeignKey foreignKey, IAnnotation annotation) - { - Check.NotNull(foreignKey, nameof(foreignKey)); - Check.NotNull(annotation, nameof(annotation)); - - return false; - } + => false; /// /// Checks if the given is handled by convention when @@ -483,12 +455,7 @@ protected virtual bool IsHandledByConvention(IForeignKey foreignKey, IAnnotation /// The . /// . protected virtual bool IsHandledByConvention(IIndex index, IAnnotation annotation) - { - Check.NotNull(index, nameof(index)); - Check.NotNull(annotation, nameof(annotation)); - - return false; - } + => false; /// /// Returns a fluent API call for the given , or @@ -501,12 +468,7 @@ protected virtual bool IsHandledByConvention(IIndex index, IAnnotation annotatio /// The . /// . protected virtual MethodCallCodeFragment? GenerateFluentApi(IModel model, IAnnotation annotation) - { - Check.NotNull(model, nameof(model)); - Check.NotNull(annotation, nameof(annotation)); - - return null; - } + => null; /// /// Returns a fluent API call for the given , or @@ -519,12 +481,7 @@ protected virtual bool IsHandledByConvention(IIndex index, IAnnotation annotatio /// The . /// . protected virtual MethodCallCodeFragment? GenerateFluentApi(IEntityType entityType, IAnnotation annotation) - { - Check.NotNull(entityType, nameof(entityType)); - Check.NotNull(annotation, nameof(annotation)); - - return null; - } + => null; /// /// Returns a fluent API call for the given , or @@ -537,12 +494,7 @@ protected virtual bool IsHandledByConvention(IIndex index, IAnnotation annotatio /// The . /// . protected virtual MethodCallCodeFragment? GenerateFluentApi(IKey key, IAnnotation annotation) - { - Check.NotNull(key, nameof(key)); - Check.NotNull(annotation, nameof(annotation)); - - return null; - } + => null; /// /// Returns a fluent API call for the given , or @@ -555,12 +507,7 @@ protected virtual bool IsHandledByConvention(IIndex index, IAnnotation annotatio /// The . /// . protected virtual MethodCallCodeFragment? GenerateFluentApi(IProperty property, IAnnotation annotation) - { - Check.NotNull(property, nameof(property)); - Check.NotNull(annotation, nameof(annotation)); - - return null; - } + => null; /// /// Returns a fluent API call for the given , or @@ -573,12 +520,7 @@ protected virtual bool IsHandledByConvention(IIndex index, IAnnotation annotatio /// The . /// . protected virtual MethodCallCodeFragment? GenerateFluentApi(IForeignKey foreignKey, IAnnotation annotation) - { - Check.NotNull(foreignKey, nameof(foreignKey)); - Check.NotNull(annotation, nameof(annotation)); - - return null; - } + => null; /// /// Returns a fluent API call for the given , or @@ -591,12 +533,7 @@ protected virtual bool IsHandledByConvention(IIndex index, IAnnotation annotatio /// The . /// . protected virtual MethodCallCodeFragment? GenerateFluentApi(INavigation navigation, IAnnotation annotation) - { - Check.NotNull(navigation, nameof(navigation)); - Check.NotNull(annotation, nameof(annotation)); - - return null; - } + => null; /// /// Returns a fluent API call for the given , or @@ -609,12 +546,7 @@ protected virtual bool IsHandledByConvention(IIndex index, IAnnotation annotatio /// The . /// . protected virtual MethodCallCodeFragment? GenerateFluentApi(ISkipNavigation navigation, IAnnotation annotation) - { - Check.NotNull(navigation, nameof(navigation)); - Check.NotNull(annotation, nameof(annotation)); - - return null; - } + => null; /// /// Returns a fluent API call for the given , or @@ -627,12 +559,7 @@ protected virtual bool IsHandledByConvention(IIndex index, IAnnotation annotatio /// The . /// . protected virtual MethodCallCodeFragment? GenerateFluentApi(IIndex index, IAnnotation annotation) - { - Check.NotNull(index, nameof(index)); - Check.NotNull(annotation, nameof(annotation)); - - return null; - } + => null; /// /// Returns a data annotation attribute code fragment for the given , @@ -645,12 +572,7 @@ protected virtual bool IsHandledByConvention(IIndex index, IAnnotation annotatio /// The . /// . protected virtual AttributeCodeFragment? GenerateDataAnnotation(IEntityType entityType, IAnnotation annotation) - { - Check.NotNull(entityType, nameof(entityType)); - Check.NotNull(annotation, nameof(annotation)); - - return null; - } + => null; /// /// Returns a data annotation attribute code fragment for the given , @@ -663,12 +585,7 @@ protected virtual bool IsHandledByConvention(IIndex index, IAnnotation annotatio /// The . /// . protected virtual AttributeCodeFragment? GenerateDataAnnotation(IProperty property, IAnnotation annotation) - { - Check.NotNull(property, nameof(property)); - Check.NotNull(annotation, nameof(annotation)); - - return null; - } + => null; private IEnumerable GenerateFluentApiCallsHelper( TAnnotatable annotatable, diff --git a/src/EFCore.Relational/Design/AnnotationCodeGeneratorDependencies.cs b/src/EFCore.Relational/Design/AnnotationCodeGeneratorDependencies.cs index e3b3e7cb1ed..cae5d915c47 100644 --- a/src/EFCore.Relational/Design/AnnotationCodeGeneratorDependencies.cs +++ b/src/EFCore.Relational/Design/AnnotationCodeGeneratorDependencies.cs @@ -3,7 +3,6 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Design { @@ -44,8 +43,6 @@ public sealed record AnnotationCodeGeneratorDependencies public AnnotationCodeGeneratorDependencies( IRelationalTypeMappingSource relationalTypeMappingSource) { - Check.NotNull(relationalTypeMappingSource, nameof(relationalTypeMappingSource)); - RelationalTypeMappingSource = relationalTypeMappingSource; } diff --git a/src/EFCore.Relational/Design/Internal/RelationalCSharpRuntimeAnnotationCodeGenerator.cs b/src/EFCore.Relational/Design/Internal/RelationalCSharpRuntimeAnnotationCodeGenerator.cs index d393701771e..0c35106ffab 100644 --- a/src/EFCore.Relational/Design/Internal/RelationalCSharpRuntimeAnnotationCodeGenerator.cs +++ b/src/EFCore.Relational/Design/Internal/RelationalCSharpRuntimeAnnotationCodeGenerator.cs @@ -29,8 +29,6 @@ public RelationalCSharpRuntimeAnnotationCodeGenerator( RelationalCSharpRuntimeAnnotationCodeGeneratorDependencies relationalDependencies) : base(dependencies) { - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - RelationalDependencies = relationalDependencies; } diff --git a/src/EFCore.Relational/Extensions/RelationalDatabaseFacadeExtensions.cs b/src/EFCore.Relational/Extensions/RelationalDatabaseFacadeExtensions.cs index deedc5e965e..82548552e96 100644 --- a/src/EFCore.Relational/Extensions/RelationalDatabaseFacadeExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalDatabaseFacadeExtensions.cs @@ -39,7 +39,7 @@ public static class RelationalDatabaseFacadeExtensions /// /// The for the context. public static void Migrate(this DatabaseFacade databaseFacade) - => Check.NotNull(databaseFacade, nameof(databaseFacade)).GetRelationalService().Migrate(); + => databaseFacade.GetRelationalService().Migrate(); /// /// Gets all the migrations that are defined in the configured migrations assembly. @@ -50,7 +50,7 @@ public static void Migrate(this DatabaseFacade databaseFacade) /// The for the context. /// The list of migrations. public static IEnumerable GetMigrations(this DatabaseFacade databaseFacade) - => Check.NotNull(databaseFacade, nameof(databaseFacade)).GetRelationalService().Migrations.Keys; + => databaseFacade.GetRelationalService().Migrations.Keys; /// /// Gets all migrations that have been applied to the target database. @@ -61,7 +61,7 @@ public static IEnumerable GetMigrations(this DatabaseFacade databaseFaca /// The for the context. /// The list of migrations. public static IEnumerable GetAppliedMigrations(this DatabaseFacade databaseFacade) - => Check.NotNull(databaseFacade, nameof(databaseFacade)).GetRelationalService() + => databaseFacade.GetRelationalService() .GetAppliedMigrations().Select(hr => hr.MigrationId); /// @@ -77,7 +77,7 @@ public static IEnumerable GetAppliedMigrations(this DatabaseFacade datab public static async Task> GetAppliedMigrationsAsync( this DatabaseFacade databaseFacade, CancellationToken cancellationToken = default) - => (await Check.NotNull(databaseFacade, nameof(databaseFacade)).GetRelationalService() + => (await databaseFacade.GetRelationalService() .GetAppliedMigrationsAsync(cancellationToken).ConfigureAwait(false)).Select(hr => hr.MigrationId); /// @@ -128,7 +128,7 @@ public static async Task> GetPendingMigrationsAsync( public static Task MigrateAsync( this DatabaseFacade databaseFacade, CancellationToken cancellationToken = default) - => Check.NotNull(databaseFacade, nameof(databaseFacade)).GetRelationalService() + => databaseFacade.GetRelationalService() .MigrateAsync(cancellationToken: cancellationToken); /// @@ -252,7 +252,6 @@ public static int ExecuteSqlRaw( string sql, IEnumerable parameters) { - Check.NotNull(databaseFacade, nameof(databaseFacade)); Check.NotNull(sql, nameof(sql)); Check.NotNull(parameters, nameof(parameters)); @@ -458,7 +457,6 @@ public static async Task ExecuteSqlRawAsync( IEnumerable parameters, CancellationToken cancellationToken = default) { - Check.NotNull(databaseFacade, nameof(databaseFacade)); Check.NotNull(sql, nameof(sql)); Check.NotNull(parameters, nameof(parameters)); @@ -828,7 +826,7 @@ public static string GenerateCreateScript(this DatabaseFacade databaseFacade) /// otherwise. /// public static bool IsRelational(this DatabaseFacade databaseFacade) - => ((IDatabaseFacadeDependenciesAccessor)Check.NotNull(databaseFacade, nameof(databaseFacade))) + => ((IDatabaseFacadeDependenciesAccessor)databaseFacade) .Context.GetService().Extensions.OfType().Any(); private static IRelationalDatabaseFacadeDependencies GetFacadeDependencies(DatabaseFacade databaseFacade) @@ -845,8 +843,6 @@ private static IRelationalDatabaseFacadeDependencies GetFacadeDependencies(Datab private static TService GetRelationalService(this IInfrastructure databaseFacade) { - Check.NotNull(databaseFacade, nameof(databaseFacade)); - var service = databaseFacade.Instance.GetService(); if (service == null) { @@ -857,6 +853,6 @@ private static TService GetRelationalService(this IInfrastructure ((IDatabaseFacadeDependenciesAccessor)Check.NotNull(databaseFacade, nameof(databaseFacade))).Dependencies.TransactionManager; + => ((IDatabaseFacadeDependenciesAccessor)databaseFacade).Dependencies.TransactionManager; } } diff --git a/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs b/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs index 6e7e9b2a29d..b2d81d357d7 100644 --- a/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs @@ -461,7 +461,6 @@ public static OwnedNavigationBuilder ToTable( string? schema, bool excludedFromMigrations) { - Check.NotNull(referenceOwnershipBuilder, nameof(referenceOwnershipBuilder)); Check.NullButNotEmpty(name, nameof(name)); Check.NullButNotEmpty(schema, nameof(schema)); @@ -799,7 +798,6 @@ public static EntityTypeBuilder ToView( string? name, string? schema) { - Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); Check.NullButNotEmpty(name, nameof(name)); Check.NullButNotEmpty(schema, nameof(schema)); @@ -873,7 +871,6 @@ public static OwnedNavigationBuilder ToView( string? name, string? schema) { - Check.NotNull(referenceOwnershipBuilder, nameof(referenceOwnershipBuilder)); Check.NullButNotEmpty(name, nameof(name)); Check.NullButNotEmpty(schema, nameof(schema)); @@ -1124,7 +1121,6 @@ public static EntityTypeBuilder ToFunction( this EntityTypeBuilder entityTypeBuilder, string? name) { - Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); Check.NullButNotEmpty(name, nameof(name)); ToFunction(name, entityTypeBuilder.Metadata); @@ -1145,8 +1141,6 @@ public static EntityTypeBuilder ToFunction( this EntityTypeBuilder entityTypeBuilder, MethodInfo? function) { - Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); - ToFunction(function, entityTypeBuilder.Metadata); return entityTypeBuilder; @@ -1167,7 +1161,6 @@ public static EntityTypeBuilder ToFunction( string name, Action configureFunction) { - Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); Check.NotNull(name, nameof(name)); Check.NotNull(configureFunction, nameof(configureFunction)); @@ -1191,7 +1184,6 @@ public static EntityTypeBuilder ToFunction( MethodInfo function, Action configureFunction) { - Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); Check.NotNull(function, nameof(function)); Check.NotNull(configureFunction, nameof(configureFunction)); @@ -1281,7 +1273,6 @@ public static OwnedNavigationBuilder ToFunction( this OwnedNavigationBuilder ownedNavigationBuilder, string? name) { - Check.NotNull(ownedNavigationBuilder, nameof(ownedNavigationBuilder)); Check.NullButNotEmpty(name, nameof(name)); ToFunction(name, ownedNavigationBuilder.OwnedEntityType); @@ -1302,8 +1293,6 @@ public static OwnedNavigationBuilder ToFunction( this OwnedNavigationBuilder ownedNavigationBuilder, MethodInfo? function) { - Check.NotNull(ownedNavigationBuilder, nameof(ownedNavigationBuilder)); - ToFunction(function, ownedNavigationBuilder.OwnedEntityType); return ownedNavigationBuilder; @@ -1324,7 +1313,6 @@ public static OwnedNavigationBuilder ToFunction( string name, Action configureFunction) { - Check.NotNull(ownedNavigationBuilder, nameof(ownedNavigationBuilder)); Check.NullButNotEmpty(name, nameof(name)); Check.NotNull(configureFunction, nameof(configureFunction)); @@ -1348,7 +1336,6 @@ public static OwnedNavigationBuilder ToFunction( MethodInfo function, Action configureFunction) { - Check.NotNull(ownedNavigationBuilder, nameof(ownedNavigationBuilder)); Check.NotNull(function, nameof(function)); Check.NotNull(configureFunction, nameof(configureFunction)); @@ -1599,8 +1586,6 @@ public static EntityTypeBuilder HasCheckConstraint( string name, string? sql) { - Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); - InternalCheckConstraintBuilder.HasCheckConstraint( (IConventionEntityType)entityTypeBuilder.Metadata, name, @@ -1690,8 +1675,6 @@ public static OwnedNavigationBuilder HasCheckConstraint( string name, string? sql) { - Check.NotNull(ownedNavigationBuilder, nameof(ownedNavigationBuilder)); - InternalCheckConstraintBuilder.HasCheckConstraint( (IConventionEntityType)ownedNavigationBuilder.OwnedEntityType, name, @@ -1790,7 +1773,7 @@ public static OwnedNavigationBuilder HasCheckCon string? sql, bool fromDataAnnotation = false) => InternalCheckConstraintBuilder.HasCheckConstraint( - Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)).Metadata, + entityTypeBuilder.Metadata, name, sql, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention) @@ -1832,7 +1815,7 @@ public static bool CanHaveCheckConstraint( string? sql, bool fromDataAnnotation = false) => InternalCheckConstraintBuilder.CanHaveCheckConstraint( - Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)).Metadata, + entityTypeBuilder.Metadata, name, sql, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); @@ -1850,8 +1833,6 @@ public static EntityTypeBuilder HasComment( this EntityTypeBuilder entityTypeBuilder, string? comment) { - Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); - entityTypeBuilder.Metadata.SetComment(comment); return entityTypeBuilder; } @@ -1890,8 +1871,6 @@ public static EntityTypeBuilder HasComment( string? comment, bool fromDataAnnotation = false) { - Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); - if (!entityTypeBuilder.CanSetComment(comment, fromDataAnnotation)) { return null; diff --git a/src/EFCore.Relational/Extensions/RelationalForeignKeyBuilderExtensions.cs b/src/EFCore.Relational/Extensions/RelationalForeignKeyBuilderExtensions.cs index 6405fd3806f..17bc3ea26ab 100644 --- a/src/EFCore.Relational/Extensions/RelationalForeignKeyBuilderExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalForeignKeyBuilderExtensions.cs @@ -29,7 +29,6 @@ public static ReferenceCollectionBuilder HasConstraintName( this ReferenceCollectionBuilder referenceCollectionBuilder, string? name) { - Check.NotNull(referenceCollectionBuilder, nameof(referenceCollectionBuilder)); Check.NullButNotEmpty(name, nameof(name)); referenceCollectionBuilder.Metadata.SetConstraintName(name); @@ -69,7 +68,6 @@ public static ReferenceReferenceBuilder HasConstraintName( this ReferenceReferenceBuilder referenceReferenceBuilder, string? name) { - Check.NotNull(referenceReferenceBuilder, nameof(referenceReferenceBuilder)); Check.NullButNotEmpty(name, nameof(name)); referenceReferenceBuilder.Metadata.SetConstraintName(name); @@ -177,7 +175,6 @@ public static bool CanSetConstraintName( this IConventionForeignKeyBuilder relationship, string? name, bool fromDataAnnotation = false) - => Check.NotNull(relationship, nameof(relationship)) - .CanSetAnnotation(RelationalAnnotationNames.Name, name, fromDataAnnotation); + => relationship.CanSetAnnotation(RelationalAnnotationNames.Name, name, fromDataAnnotation); } } diff --git a/src/EFCore.Relational/Extensions/RelationalForeignKeyExtensions.cs b/src/EFCore.Relational/Extensions/RelationalForeignKeyExtensions.cs index 9b258e3fc4c..2b00b4430d3 100644 --- a/src/EFCore.Relational/Extensions/RelationalForeignKeyExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalForeignKeyExtensions.cs @@ -210,8 +210,6 @@ public static IEnumerable GetMappedConstraints(this IFore this IReadOnlyForeignKey foreignKey, in StoreObjectIdentifier storeObject) { - Check.NotNull(foreignKey, nameof(foreignKey)); - var foreignKeyName = foreignKey.GetConstraintName( storeObject, StoreObjectIdentifier.Table(foreignKey.PrincipalEntityType.GetTableName()!, foreignKey.PrincipalEntityType.GetSchema())); diff --git a/src/EFCore.Relational/Extensions/RelationalIndexBuilderExtensions.cs b/src/EFCore.Relational/Extensions/RelationalIndexBuilderExtensions.cs index 9be65e0fcc7..16cdceda469 100644 --- a/src/EFCore.Relational/Extensions/RelationalIndexBuilderExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalIndexBuilderExtensions.cs @@ -170,7 +170,6 @@ public static bool CanSetName( /// A builder to further configure the index. public static IndexBuilder HasFilter(this IndexBuilder indexBuilder, string? sql) { - Check.NotNull(indexBuilder, nameof(indexBuilder)); Check.NullButNotEmpty(sql, nameof(sql)); indexBuilder.Metadata.SetFilter(sql); diff --git a/src/EFCore.Relational/Extensions/RelationalKeyBuilderExtensions.cs b/src/EFCore.Relational/Extensions/RelationalKeyBuilderExtensions.cs index 9e99edf7a62..becbfcf8faf 100644 --- a/src/EFCore.Relational/Extensions/RelationalKeyBuilderExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalKeyBuilderExtensions.cs @@ -27,7 +27,6 @@ public static class RelationalKeyBuilderExtensions /// The same builder instance so that multiple calls can be chained. public static KeyBuilder HasName(this KeyBuilder keyBuilder, string? name) { - Check.NotNull(keyBuilder, nameof(keyBuilder)); Check.NullButNotEmpty(name, nameof(name)); keyBuilder.Metadata.SetName(name); diff --git a/src/EFCore.Relational/Extensions/RelationalKeyExtensions.cs b/src/EFCore.Relational/Extensions/RelationalKeyExtensions.cs index bddee9d0b1a..a350e482ec4 100644 --- a/src/EFCore.Relational/Extensions/RelationalKeyExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalKeyExtensions.cs @@ -202,8 +202,6 @@ public static IEnumerable GetMappedConstraints(this IKey key) /// The key found, or if none was found. public static IReadOnlyKey? FindSharedObjectRootKey(this IReadOnlyKey key, in StoreObjectIdentifier storeObject) { - Check.NotNull(key, nameof(key)); - var keyName = key.GetName(storeObject); var rootKey = key; diff --git a/src/EFCore.Relational/Extensions/RelationalModelBuilderExtensions.cs b/src/EFCore.Relational/Extensions/RelationalModelBuilderExtensions.cs index 2264a29bcf1..9830eff0190 100644 --- a/src/EFCore.Relational/Extensions/RelationalModelBuilderExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalModelBuilderExtensions.cs @@ -37,7 +37,7 @@ public static SequenceBuilder HasSequence( string? schema = null) => new( HasSequence( - Check.NotNull(modelBuilder, nameof(modelBuilder)).Model, + modelBuilder.Model, name, schema, ConfigurationSource.Explicit)); @@ -99,7 +99,6 @@ public static SequenceBuilder HasSequence( string name, string? schema = null) { - Check.NotNull(modelBuilder, nameof(modelBuilder)); Check.NotNull(type, nameof(type)); var sequence = HasSequence(modelBuilder.Model, name, schema, ConfigurationSource.Explicit); @@ -168,8 +167,6 @@ public static SequenceBuilder HasSequence( string name, string? schema = null) { - Check.NotNull(modelBuilder, nameof(modelBuilder)); - var sequence = HasSequence(modelBuilder.Model, name, schema, ConfigurationSource.Explicit); sequence.Type = typeof(T); @@ -235,7 +232,7 @@ public static IConventionSequenceBuilder HasSequence( string? schema = null, bool fromDataAnnotation = false) => HasSequence( - (IMutableModel)Check.NotNull(modelBuilder, nameof(modelBuilder)).Metadata, + (IMutableModel)modelBuilder.Metadata, name, schema, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention).Builder; @@ -272,7 +269,6 @@ public static DbFunctionBuilder HasDbFunction( this ModelBuilder modelBuilder, MethodInfo methodInfo) { - Check.NotNull(modelBuilder, nameof(modelBuilder)); Check.NotNull(methodInfo, nameof(methodInfo)); var dbFunction = modelBuilder.Model.FindDbFunction(methodInfo); @@ -301,7 +297,6 @@ public static DbFunctionBuilder HasDbFunction( this ModelBuilder modelBuilder, Expression> expression) { - Check.NotNull(modelBuilder, nameof(modelBuilder)); Check.NotNull(expression, nameof(expression)); var methodInfo = (expression.Body as MethodCallExpression)?.Method; @@ -351,7 +346,6 @@ public static IConventionDbFunctionBuilder HasDbFunction( MethodInfo methodInfo, bool fromDataAnnotation = false) { - Check.NotNull(modelBuilder, nameof(modelBuilder)); Check.NotNull(methodInfo, nameof(methodInfo)); var dbFunction = modelBuilder.Metadata.FindDbFunction(methodInfo); @@ -385,7 +379,6 @@ public static IConventionDbFunctionBuilder HasDbFunction( Type returnType, bool fromDataAnnotation = false) { - Check.NotNull(modelBuilder, nameof(modelBuilder)); Check.NotEmpty(name, nameof(name)); var dbFunction = modelBuilder.Metadata.FindDbFunction(name); @@ -416,7 +409,6 @@ public static ModelBuilder HasDefaultSchema( this ModelBuilder modelBuilder, string? schema) { - Check.NotNull(modelBuilder, nameof(modelBuilder)); Check.NullButNotEmpty(schema, nameof(schema)); modelBuilder.Model.SetDefaultSchema(schema); @@ -468,7 +460,6 @@ public static bool CanSetDefaultSchema( string? schema, bool fromDataAnnotation = false) { - Check.NotNull(modelBuilder, nameof(modelBuilder)); Check.NullButNotEmpty(schema, nameof(schema)); return modelBuilder.CanSetAnnotation(RelationalAnnotationNames.DefaultSchema, schema, fromDataAnnotation); @@ -516,11 +507,7 @@ public static bool CanSetMaxIdentifierLength( this IConventionModelBuilder modelBuilder, int? length, bool fromDataAnnotation = false) - { - Check.NotNull(modelBuilder, nameof(modelBuilder)); - - return modelBuilder.CanSetAnnotation(RelationalAnnotationNames.MaxIdentifierLength, length, fromDataAnnotation); - } + => modelBuilder.CanSetAnnotation(RelationalAnnotationNames.MaxIdentifierLength, length, fromDataAnnotation); /// /// Configures the database collation, which will be used by all columns without an explicit collation. @@ -535,7 +522,6 @@ public static ModelBuilder UseCollation( this ModelBuilder modelBuilder, string? collation) { - Check.NotNull(modelBuilder, nameof(modelBuilder)); Check.NullButNotEmpty(collation, nameof(collation)); modelBuilder.Model.SetCollation(collation); @@ -586,7 +572,6 @@ public static bool CanSetCollation( string? collation, bool fromDataAnnotation = false) { - Check.NotNull(modelBuilder, nameof(modelBuilder)); Check.NullButNotEmpty(collation, nameof(collation)); return modelBuilder.CanSetAnnotation(RelationalAnnotationNames.Collation, collation, fromDataAnnotation); diff --git a/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs b/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs index 2dffadd6ccb..b1b6d256695 100644 --- a/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs @@ -27,7 +27,7 @@ public static class RelationalModelExtensions /// The model to get the default schema for. /// The default schema. public static string? GetDefaultSchema(this IReadOnlyModel model) - => (string?)Check.NotNull(model, nameof(model))[RelationalAnnotationNames.DefaultSchema]; + => (string?)model[RelationalAnnotationNames.DefaultSchema]; /// /// Sets the default schema. @@ -87,7 +87,7 @@ public static IRelationalModel GetRelationalModel(this IModel model) /// The model to get the maximum identifier length for. /// The maximum identifier length. public static int GetMaxIdentifierLength(this IReadOnlyModel model) - => (int?)Check.NotNull(model, nameof(model))[RelationalAnnotationNames.MaxIdentifierLength] ?? short.MaxValue; + => (int?)model[RelationalAnnotationNames.MaxIdentifierLength] ?? short.MaxValue; /// /// Sets the maximum length allowed for store identifiers. @@ -134,7 +134,7 @@ public static void SetMaxIdentifierLength(this IMutableModel model, int? length) string name, string? schema = null) => Sequence.FindSequence( - Check.NotNull(model, nameof(model)), Check.NotEmpty(name, nameof(name)), Check.NullButNotEmpty(schema, nameof(schema))); + model, Check.NotEmpty(name, nameof(name)), Check.NullButNotEmpty(schema, nameof(schema))); /// /// Finds a sequence with the given name. @@ -230,7 +230,7 @@ public static IMutableSequence AddSequence( this IMutableModel model, string name, string? schema = null) - => Sequence.RemoveSequence(Check.NotNull(model, nameof(model)), name, schema); + => Sequence.RemoveSequence(model, name, schema); /// /// Removes the with the given name. @@ -246,35 +246,35 @@ public static IMutableSequence AddSequence( this IConventionModel model, string name, string? schema = null) - => Sequence.RemoveSequence((IMutableModel)Check.NotNull(model, nameof(model)), name, schema); + => Sequence.RemoveSequence((IMutableModel)model, name, schema); /// /// Returns all sequences contained in the model. /// /// The model to get the sequences in. public static IEnumerable GetSequences(this IModel model) - => Sequence.GetSequences(Check.NotNull(model, nameof(model))); + => Sequence.GetSequences(model); /// /// Returns all sequences contained in the model. /// /// The model to get the sequences in. public static IEnumerable GetSequences(this IMutableModel model) - => Sequence.GetSequences(Check.NotNull(model, nameof(model))).Cast(); + => Sequence.GetSequences(model).Cast(); /// /// Returns all sequences contained in the model. /// /// The model to get the sequences in. public static IEnumerable GetSequences(this IConventionModel model) - => Sequence.GetSequences(Check.NotNull(model, nameof(model))).Cast(); + => Sequence.GetSequences(model).Cast(); /// /// Returns all sequences contained in the model. /// /// The model to get the sequences in. public static IEnumerable GetSequences(this IReadOnlyModel model) - => Sequence.GetSequences(Check.NotNull(model, nameof(model))); + => Sequence.GetSequences(model); /// /// Finds a function that is mapped to the method represented by the given . @@ -283,9 +283,7 @@ public static IEnumerable GetSequences(this IReadOnlyModel mo /// The for the method that is mapped to the function. /// The function or if the method is not mapped. public static IReadOnlyDbFunction? FindDbFunction(this IReadOnlyModel model, MethodInfo method) - => DbFunction.FindDbFunction( - Check.NotNull(model, nameof(model)), - Check.NotNull(method, nameof(method))); + => DbFunction.FindDbFunction(model, Check.NotNull(method, nameof(method))); /// /// Finds a function that is mapped to the method represented by the given . @@ -416,9 +414,7 @@ public static IConventionDbFunction AddDbFunction( /// The for the method that is mapped to the function. /// The removed function or if the method is not mapped. public static IMutableDbFunction? RemoveDbFunction(this IMutableModel model, MethodInfo method) - => DbFunction.RemoveDbFunction( - Check.NotNull(model, nameof(model)), - Check.NotNull(method, nameof(method))); + => DbFunction.RemoveDbFunction(model, Check.NotNull(method, nameof(method))); /// /// Removes the function that is mapped to the method represented by the given @@ -438,9 +434,7 @@ public static IConventionDbFunction AddDbFunction( /// The model name of the function. /// The removed function or if the method is not mapped. public static IMutableDbFunction? RemoveDbFunction(this IMutableModel model, string name) - => DbFunction.RemoveDbFunction( - Check.NotNull(model, nameof(model)), - Check.NotNull(name, nameof(name))); + => DbFunction.RemoveDbFunction(model, Check.NotNull(name, nameof(name))); /// /// Removes the function that is mapped to the method represented by the given @@ -457,28 +451,28 @@ public static IConventionDbFunction AddDbFunction( /// /// The model to get the functions in. public static IEnumerable GetDbFunctions(this IReadOnlyModel model) - => DbFunction.GetDbFunctions(Check.NotNull(model, nameof(model))); + => DbFunction.GetDbFunctions(model); /// /// Returns all functions contained in the model. /// /// The model to get the functions in. public static IEnumerable GetDbFunctions(this IMutableModel model) - => DbFunction.GetDbFunctions(Check.NotNull(model, nameof(model))).Cast(); + => DbFunction.GetDbFunctions(model).Cast(); /// /// Returns all functions contained in the model. /// /// The model to get the functions in. public static IEnumerable GetDbFunctions(this IConventionModel model) - => DbFunction.GetDbFunctions(Check.NotNull(model, nameof(model))).Cast(); + => DbFunction.GetDbFunctions(model).Cast(); /// /// Returns all functions contained in the model. /// /// The model to get the functions in. public static IEnumerable GetDbFunctions(this IModel model) - => DbFunction.GetDbFunctions(Check.NotNull(model, nameof(model))); + => DbFunction.GetDbFunctions(model); /// /// Returns the database collation. diff --git a/src/EFCore.Relational/Extensions/RelationalPropertiesConfigurationBuilderExtensions.cs b/src/EFCore.Relational/Extensions/RelationalPropertiesConfigurationBuilderExtensions.cs index 26f5afda313..96db76c02cc 100644 --- a/src/EFCore.Relational/Extensions/RelationalPropertiesConfigurationBuilderExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalPropertiesConfigurationBuilderExtensions.cs @@ -27,7 +27,6 @@ public static PropertiesConfigurationBuilder HaveColumnType( this PropertiesConfigurationBuilder propertyBuilder, string typeName) { - Check.NotNull(propertyBuilder, nameof(propertyBuilder)); Check.NotEmpty(typeName, nameof(typeName)); propertyBuilder.HaveAnnotation(RelationalAnnotationNames.ColumnType, typeName); @@ -64,8 +63,6 @@ public static PropertiesConfigurationBuilder AreFixedLength( this PropertiesConfigurationBuilder propertyBuilder, bool fixedLength = true) { - Check.NotNull(propertyBuilder, nameof(propertyBuilder)); - propertyBuilder.HaveAnnotation(RelationalAnnotationNames.IsFixedLength, fixedLength); return propertyBuilder; @@ -98,7 +95,6 @@ public static PropertiesConfigurationBuilder AreFixedLengthThe same builder instance so that multiple calls can be chained. public static PropertiesConfigurationBuilder UseCollation(this PropertiesConfigurationBuilder propertyBuilder, string collation) { - Check.NotNull(propertyBuilder, nameof(propertyBuilder)); Check.NotEmpty(collation, nameof(collation)); propertyBuilder.HaveAnnotation(RelationalAnnotationNames.Collation, collation); diff --git a/src/EFCore.Relational/Extensions/RelationalPropertyBuilderExtensions.cs b/src/EFCore.Relational/Extensions/RelationalPropertyBuilderExtensions.cs index 3cb7e825557..4af451aba39 100644 --- a/src/EFCore.Relational/Extensions/RelationalPropertyBuilderExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalPropertyBuilderExtensions.cs @@ -31,7 +31,6 @@ public static PropertyBuilder HasColumnName( this PropertyBuilder propertyBuilder, string? name) { - Check.NotNull(propertyBuilder, nameof(propertyBuilder)); Check.NullButNotEmpty(name, nameof(name)); propertyBuilder.Metadata.SetColumnName(name); @@ -158,8 +157,6 @@ public static bool CanSetColumnName( /// The same builder instance so that multiple calls can be chained. public static PropertyBuilder HasColumnOrder(this PropertyBuilder propertyBuilder, int? order) { - Check.NotNull(propertyBuilder, nameof(propertyBuilder)); - propertyBuilder.Metadata.SetColumnOrder(order); return propertyBuilder; @@ -220,7 +217,6 @@ public static PropertyBuilder HasColumnType( this PropertyBuilder propertyBuilder, string? typeName) { - Check.NotNull(propertyBuilder, nameof(propertyBuilder)); Check.NullButNotEmpty(typeName, nameof(typeName)); propertyBuilder.Metadata.SetColumnType(typeName); @@ -301,8 +297,6 @@ public static PropertyBuilder IsFixedLength( this PropertyBuilder propertyBuilder, bool fixedLength = true) { - Check.NotNull(propertyBuilder, nameof(propertyBuilder)); - propertyBuilder.Metadata.SetIsFixedLength(fixedLength); return propertyBuilder; @@ -384,8 +378,6 @@ public static bool CanSetIsFixedLength( /// The same builder instance so that multiple calls can be chained. public static PropertyBuilder HasDefaultValueSql(this PropertyBuilder propertyBuilder) { - Check.NotNull(propertyBuilder, nameof(propertyBuilder)); - propertyBuilder.Metadata.SetDefaultValueSql(string.Empty); return propertyBuilder; @@ -404,7 +396,6 @@ public static PropertyBuilder HasDefaultValueSql( this PropertyBuilder propertyBuilder, string? sql) { - Check.NotNull(propertyBuilder, nameof(propertyBuilder)); Check.NullButNotEmpty(sql, nameof(sql)); propertyBuilder.Metadata.SetDefaultValueSql(sql); @@ -511,8 +502,6 @@ public static bool CanSetDefaultValueSql( /// The same builder instance so that multiple calls can be chained. public static PropertyBuilder HasComputedColumnSql(this PropertyBuilder propertyBuilder) { - Check.NotNull(propertyBuilder, nameof(propertyBuilder)); - propertyBuilder.Metadata.SetComputedColumnSql(string.Empty); return propertyBuilder; @@ -551,7 +540,6 @@ public static PropertyBuilder HasComputedColumnSql( string? sql, bool? stored) { - Check.NotNull(propertyBuilder, nameof(propertyBuilder)); Check.NullButNotEmpty(sql, nameof(sql)); propertyBuilder.Metadata.SetComputedColumnSql(sql); @@ -737,8 +725,6 @@ public static bool CanSetIsStoredComputedColumn( /// The same builder instance so that multiple calls can be chained. public static PropertyBuilder HasDefaultValue(this PropertyBuilder propertyBuilder) { - Check.NotNull(propertyBuilder, nameof(propertyBuilder)); - propertyBuilder.Metadata.SetDefaultValue(DBNull.Value); return propertyBuilder; @@ -758,8 +744,6 @@ public static PropertyBuilder HasDefaultValue( this PropertyBuilder propertyBuilder, object? value) { - Check.NotNull(propertyBuilder, nameof(propertyBuilder)); - propertyBuilder.Metadata.SetDefaultValue(value); return propertyBuilder; @@ -861,8 +845,6 @@ public static PropertyBuilder HasComment( this PropertyBuilder propertyBuilder, string? comment) { - Check.NotNull(propertyBuilder, nameof(propertyBuilder)); - propertyBuilder.Metadata.SetComment(comment); return propertyBuilder; @@ -941,7 +923,6 @@ public static bool CanSetComment( /// The same builder instance so that multiple calls can be chained. public static PropertyBuilder UseCollation(this PropertyBuilder propertyBuilder, string? collation) { - Check.NotNull(propertyBuilder, nameof(propertyBuilder)); Check.NullButNotEmpty(collation, nameof(collation)); propertyBuilder.Metadata.SetCollation(collation); @@ -1007,10 +988,6 @@ public static bool CanSetCollation( this IConventionPropertyBuilder propertyBuilder, string? collation, bool fromDataAnnotation = false) - { - Check.NotNull(propertyBuilder, nameof(propertyBuilder)); - - return propertyBuilder.CanSetAnnotation(RelationalAnnotationNames.Collation, collation, fromDataAnnotation); - } + => propertyBuilder.CanSetAnnotation(RelationalAnnotationNames.Collation, collation, fromDataAnnotation); } } diff --git a/src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs b/src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs index 504f0689d08..1b270bd2023 100644 --- a/src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs @@ -50,8 +50,6 @@ public static string GetColumnBaseName(this IReadOnlyProperty property) /// The name of the column to which the property is mapped. public static string? GetColumnName(this IReadOnlyProperty property, in StoreObjectIdentifier storeObject) { - Check.NotNull(property, nameof(property)); - var overrides = RelationalPropertyOverrides.Find(property, storeObject); if (overrides?.ColumnNameOverriden == true) { @@ -358,12 +356,8 @@ public static void SetColumnOrder(this IMutableProperty property, int? order) /// be found. /// public static string? GetColumnType(this IReadOnlyProperty property) - { - Check.NotNull(property, nameof(property)); - - return (string?)(property.FindRelationalTypeMapping()?.StoreType + => (string?)(property.FindRelationalTypeMapping()?.StoreType ?? property.FindAnnotation(RelationalAnnotationNames.ColumnType)?.Value); - } /// /// Returns the database type of the column to which the property is mapped. @@ -907,8 +901,6 @@ public static void SetDefaultValue(this IMutableProperty property, object? value /// The maximum length, or if none is defined. public static int? GetMaxLength(this IReadOnlyProperty property, in StoreObjectIdentifier storeObject) { - Check.NotNull(property, nameof(property)); - var maxLength = property.GetMaxLength(); if (maxLength != null) { @@ -928,8 +920,6 @@ public static void SetDefaultValue(this IMutableProperty property, object? value /// The precision, or if none is defined. public static int? GetPrecision(this IReadOnlyProperty property, in StoreObjectIdentifier storeObject) { - Check.NotNull(property, nameof(property)); - var precision = property.GetPrecision(); if (precision != null) { @@ -949,8 +939,6 @@ public static void SetDefaultValue(this IMutableProperty property, object? value /// The scale, or if none is defined. public static int? GetScale(this IReadOnlyProperty property, in StoreObjectIdentifier storeObject) { - Check.NotNull(property, nameof(property)); - var scale = property.GetScale(); if (scale != null) { @@ -969,8 +957,6 @@ public static void SetDefaultValue(this IMutableProperty property, object? value /// The Unicode setting, or if none is defined. public static bool? IsUnicode(this IReadOnlyProperty property, in StoreObjectIdentifier storeObject) { - Check.NotNull(property, nameof(property)); - var unicode = property.IsUnicode(); if (unicode != null) { @@ -1361,8 +1347,6 @@ public static RelationalTypeMapping GetRelationalTypeMapping(this IReadOnlyPrope private static IReadOnlyProperty? FindSharedObjectRootProperty(IReadOnlyProperty property, in StoreObjectIdentifier storeObject) { - Check.NotNull(property, nameof(property)); - var column = property.GetColumnName(storeObject); if (column == null) diff --git a/src/EFCore.Relational/Extensions/RelationalQueryableExtensions.cs b/src/EFCore.Relational/Extensions/RelationalQueryableExtensions.cs index 8c8769722b4..311b443a0a5 100644 --- a/src/EFCore.Relational/Extensions/RelationalQueryableExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalQueryableExtensions.cs @@ -49,8 +49,6 @@ public static class RelationalQueryableExtensions /// The query string for debugging. public static DbCommand CreateDbCommand(this IQueryable source) { - Check.NotNull(source, nameof(source)); - if (source.Provider.Execute(source.Expression) is IRelationalQueryingEnumerable queryingEnumerable) { return queryingEnumerable.CreateDbCommand(); @@ -102,7 +100,6 @@ public static IQueryable FromSqlRaw( params object[] parameters) where TEntity : class { - Check.NotNull(source, nameof(source)); Check.NotEmpty(sql, nameof(sql)); Check.NotNull(parameters, nameof(parameters)); @@ -145,7 +142,6 @@ public static IQueryable FromSqlInterpolated( [NotParameterized] FormattableString sql) where TEntity : class { - Check.NotNull(source, nameof(source)); Check.NotNull(sql, nameof(sql)); Check.NotEmpty(sql.Format, nameof(source)); @@ -202,14 +198,10 @@ private static FromSqlQueryRootExpression GenerateFromSqlQueryRoot( public static IQueryable AsSingleQuery( this IQueryable source) where TEntity : class - { - Check.NotNull(source, nameof(source)); - - return source.Provider is EntityQueryProvider + => source.Provider is EntityQueryProvider ? source.Provider.CreateQuery( Expression.Call(AsSingleQueryMethodInfo.MakeGenericMethod(typeof(TEntity)), source.Expression)) : source; - } internal static readonly MethodInfo AsSingleQueryMethodInfo = typeof(RelationalQueryableExtensions).GetRequiredDeclaredMethod(nameof(AsSingleQuery)); @@ -238,14 +230,10 @@ internal static readonly MethodInfo AsSingleQueryMethodInfo public static IQueryable AsSplitQuery( this IQueryable source) where TEntity : class - { - Check.NotNull(source, nameof(source)); - - return source.Provider is EntityQueryProvider + => source.Provider is EntityQueryProvider ? source.Provider.CreateQuery( Expression.Call(AsSplitQueryMethodInfo.MakeGenericMethod(typeof(TEntity)), source.Expression)) : source; - } internal static readonly MethodInfo AsSplitQueryMethodInfo = typeof(RelationalQueryableExtensions).GetRequiredDeclaredMethod(nameof(AsSplitQuery)); diff --git a/src/EFCore.Relational/Extensions/RelationalTypeMappingConfigurationBuilderExtensions.cs b/src/EFCore.Relational/Extensions/RelationalTypeMappingConfigurationBuilderExtensions.cs index 38a0e95fa96..06e017a4039 100644 --- a/src/EFCore.Relational/Extensions/RelationalTypeMappingConfigurationBuilderExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalTypeMappingConfigurationBuilderExtensions.cs @@ -30,7 +30,6 @@ public static TypeMappingConfigurationBuilder HasColumnType( this TypeMappingConfigurationBuilder scalarBuilder, string typeName) { - Check.NotNull(scalarBuilder, nameof(scalarBuilder)); Check.NotEmpty(typeName, nameof(typeName)); scalarBuilder.HasAnnotation(RelationalAnnotationNames.ColumnType, typeName); @@ -67,8 +66,6 @@ public static TypeMappingConfigurationBuilder IsFixedLength( this TypeMappingConfigurationBuilder scalarBuilder, bool fixedLength = true) { - Check.NotNull(scalarBuilder, nameof(scalarBuilder)); - scalarBuilder.HasAnnotation(RelationalAnnotationNames.IsFixedLength, fixedLength); return scalarBuilder; diff --git a/src/EFCore.Relational/Infrastructure/RelationalDbContextOptionsBuilder.cs b/src/EFCore.Relational/Infrastructure/RelationalDbContextOptionsBuilder.cs index d071b6d9ac1..d3261e8b27c 100644 --- a/src/EFCore.Relational/Infrastructure/RelationalDbContextOptionsBuilder.cs +++ b/src/EFCore.Relational/Infrastructure/RelationalDbContextOptionsBuilder.cs @@ -31,8 +31,6 @@ public abstract class RelationalDbContextOptionsBuilder : /// The core options builder. protected RelationalDbContextOptionsBuilder(DbContextOptionsBuilder optionsBuilder) { - Check.NotNull(optionsBuilder, nameof(optionsBuilder)); - OptionsBuilder = optionsBuilder; } diff --git a/src/EFCore.Relational/Infrastructure/RelationalModelRuntimeInitializer.cs b/src/EFCore.Relational/Infrastructure/RelationalModelRuntimeInitializer.cs index e52de04073e..d5142f012ac 100644 --- a/src/EFCore.Relational/Infrastructure/RelationalModelRuntimeInitializer.cs +++ b/src/EFCore.Relational/Infrastructure/RelationalModelRuntimeInitializer.cs @@ -3,7 +3,6 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Metadata.Internal; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Infrastructure @@ -40,8 +39,6 @@ public RelationalModelRuntimeInitializer( RelationalModelRuntimeInitializerDependencies relationalDependencies) : base(dependencies) { - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - RelationalDependencies = relationalDependencies; } diff --git a/src/EFCore.Relational/Infrastructure/RelationalModelRuntimeInitializerDependencies.cs b/src/EFCore.Relational/Infrastructure/RelationalModelRuntimeInitializerDependencies.cs index 100128d34ab..15893aa2e05 100644 --- a/src/EFCore.Relational/Infrastructure/RelationalModelRuntimeInitializerDependencies.cs +++ b/src/EFCore.Relational/Infrastructure/RelationalModelRuntimeInitializerDependencies.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Infrastructure @@ -53,9 +52,6 @@ public RelationalModelRuntimeInitializerDependencies( RelationalModelDependencies relationalModelDependencies, IRelationalAnnotationProvider relationalAnnotationProvider) { - Check.NotNull(relationalModelDependencies, nameof(relationalModelDependencies)); - Check.NotNull(relationalAnnotationProvider, nameof(relationalAnnotationProvider)); - RelationalModelDependencies = relationalModelDependencies; RelationalAnnotationProvider = relationalAnnotationProvider; } diff --git a/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs b/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs index 3aa63deec5b..4771fdbf611 100644 --- a/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs +++ b/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs @@ -39,8 +39,6 @@ public RelationalModelValidator( RelationalModelValidatorDependencies relationalDependencies) : base(dependencies) { - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - RelationalDependencies = relationalDependencies; } @@ -215,8 +213,6 @@ protected virtual void ValidateBoolsWithDefaults( IModel model, IDiagnosticsLogger logger) { - Check.NotNull(model, nameof(model)); - foreach (var entityType in model.GetEntityTypes()) { foreach (var property in entityType.GetDeclaredProperties()) @@ -1430,8 +1426,6 @@ protected virtual void ValidateIndexProperties( IModel model, IDiagnosticsLogger logger) { - Check.NotNull(model, nameof(model)); - foreach (var entityType in model.GetEntityTypes()) { foreach (var index in entityType.GetDeclaredIndexes() diff --git a/src/EFCore.Relational/Infrastructure/RelationalModelValidatorDependencies.cs b/src/EFCore.Relational/Infrastructure/RelationalModelValidatorDependencies.cs index a98d99194c7..0c8cd7f873f 100644 --- a/src/EFCore.Relational/Infrastructure/RelationalModelValidatorDependencies.cs +++ b/src/EFCore.Relational/Infrastructure/RelationalModelValidatorDependencies.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Infrastructure @@ -52,8 +51,6 @@ public sealed record RelationalModelValidatorDependencies public RelationalModelValidatorDependencies( IRelationalTypeMappingSource typeMappingSource) { - Check.NotNull(typeMappingSource, nameof(typeMappingSource)); - TypeMappingSource = typeMappingSource; } diff --git a/src/EFCore.Relational/Infrastructure/RelationalOptionsExtension.cs b/src/EFCore.Relational/Infrastructure/RelationalOptionsExtension.cs index d0ac88311fb..0f3e319c8db 100644 --- a/src/EFCore.Relational/Infrastructure/RelationalOptionsExtension.cs +++ b/src/EFCore.Relational/Infrastructure/RelationalOptionsExtension.cs @@ -8,7 +8,6 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Infrastructure @@ -56,8 +55,6 @@ protected RelationalOptionsExtension() /// The instance that is being cloned. protected RelationalOptionsExtension(RelationalOptionsExtension copyFrom) { - Check.NotNull(copyFrom, nameof(copyFrom)); - _connectionString = copyFrom._connectionString; _connection = copyFrom._connection; _commandTimeout = copyFrom._commandTimeout; @@ -97,8 +94,6 @@ public virtual string? ConnectionString /// A new instance with the option changed. public virtual RelationalOptionsExtension WithConnectionString(string? connectionString) { - Check.NullButNotEmpty(connectionString, nameof(connectionString)); - var clone = Clone(); clone._connectionString = connectionString; @@ -350,8 +345,6 @@ public virtual RelationalOptionsExtension WithExecutionStrategyFactory( /// The extension. public static RelationalOptionsExtension Extract(IDbContextOptions options) { - Check.NotNull(options, nameof(options)); - var relationalOptionsExtensions = options.Extensions .OfType() diff --git a/src/EFCore.Relational/Metadata/Builders/CheckConstraintBuilder.cs b/src/EFCore.Relational/Metadata/Builders/CheckConstraintBuilder.cs index a1d756d6d17..1c36d22b3f6 100644 --- a/src/EFCore.Relational/Metadata/Builders/CheckConstraintBuilder.cs +++ b/src/EFCore.Relational/Metadata/Builders/CheckConstraintBuilder.cs @@ -5,7 +5,6 @@ using System.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Builders { @@ -26,8 +25,6 @@ public class CheckConstraintBuilder : IInfrastructureThe same builder instance so that multiple configuration calls can be chained. public virtual DbFunctionBuilderBase HasName(string name) { + Check.NullButNotEmpty(name, nameof(name)); + Builder.HasName(name, ConfigurationSource.Explicit); return this; diff --git a/src/EFCore.Relational/Metadata/Builders/DbFunctionParameterBuilder.cs b/src/EFCore.Relational/Metadata/Builders/DbFunctionParameterBuilder.cs index 83136f8d828..a365ea3f666 100644 --- a/src/EFCore.Relational/Metadata/Builders/DbFunctionParameterBuilder.cs +++ b/src/EFCore.Relational/Metadata/Builders/DbFunctionParameterBuilder.cs @@ -5,7 +5,6 @@ using System.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Builders { @@ -27,8 +26,6 @@ public class DbFunctionParameterBuilder : IInfrastructure /// The to configure. public SequenceBuilder(IMutableSequence sequence) { - Check.NotNull(sequence, nameof(sequence)); - Builder = ((Sequence)sequence).Builder; } diff --git a/src/EFCore.Relational/Metadata/Conventions/DbFunctionTypeMappingConvention.cs b/src/EFCore.Relational/Metadata/Conventions/DbFunctionTypeMappingConvention.cs index 165e51923b2..e16ce56f860 100644 --- a/src/EFCore.Relational/Metadata/Conventions/DbFunctionTypeMappingConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/DbFunctionTypeMappingConvention.cs @@ -5,7 +5,6 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { @@ -30,9 +29,6 @@ public DbFunctionTypeMappingConvention( ProviderConventionSetBuilderDependencies dependencies, RelationalConventionSetBuilderDependencies relationalDependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - Dependencies = dependencies; RelationalDependencies = relationalDependencies; @@ -54,9 +50,6 @@ public virtual void ProcessModelFinalizing( IConventionModelBuilder modelBuilder, IConventionContext context) { - Check.NotNull(modelBuilder, nameof(modelBuilder)); - Check.NotNull(context, nameof(context)); - foreach (var dbFunction in modelBuilder.Metadata.GetDbFunctions()) { // TODO: This check needs to be updated to skip over enumerable parameter of aggregate. diff --git a/src/EFCore.Relational/Metadata/Conventions/EntityTypeHierarchyMappingConvention.cs b/src/EFCore.Relational/Metadata/Conventions/EntityTypeHierarchyMappingConvention.cs index ce26f66e9e0..677b82c4cb7 100644 --- a/src/EFCore.Relational/Metadata/Conventions/EntityTypeHierarchyMappingConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/EntityTypeHierarchyMappingConvention.cs @@ -5,7 +5,6 @@ using System.Linq; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { @@ -27,9 +26,6 @@ public EntityTypeHierarchyMappingConvention( ProviderConventionSetBuilderDependencies dependencies, RelationalConventionSetBuilderDependencies relationalDependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - Dependencies = dependencies; RelationalDependencies = relationalDependencies; } diff --git a/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilder.cs b/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilder.cs index 16e868044dd..5503dafadc3 100644 --- a/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilder.cs +++ b/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilder.cs @@ -1,7 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure @@ -45,8 +44,6 @@ protected RelationalConventionSetBuilder( RelationalConventionSetBuilderDependencies relationalDependencies) : base(dependencies) { - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - RelationalDependencies = relationalDependencies; } diff --git a/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilderDependencies.cs b/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilderDependencies.cs index fff748dc861..a239c74c8c5 100644 --- a/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilderDependencies.cs +++ b/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilderDependencies.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure @@ -51,8 +50,6 @@ public sealed record RelationalConventionSetBuilderDependencies [EntityFrameworkInternal] public RelationalConventionSetBuilderDependencies(IRelationalAnnotationProvider relationalAnnotationProvider) { - Check.NotNull(relationalAnnotationProvider, nameof(relationalAnnotationProvider)); - #pragma warning disable CS0618 // Type or member is obsolete RelationalAnnotationProvider = relationalAnnotationProvider; #pragma warning restore CS0618 // Type or member is obsolete diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalColumnAttributeConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalColumnAttributeConvention.cs index 87a8230cd25..ff04ed3b91b 100644 --- a/src/EFCore.Relational/Metadata/Conventions/RelationalColumnAttributeConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/RelationalColumnAttributeConvention.cs @@ -5,7 +5,6 @@ using System.Reflection; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { @@ -27,8 +26,6 @@ public RelationalColumnAttributeConvention( RelationalConventionSetBuilderDependencies relationalDependencies) : base(dependencies) { - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - RelationalDependencies = relationalDependencies; } diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalColumnCommentAttributeConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalColumnCommentAttributeConvention.cs index 2ac3bce7882..266b75f8186 100644 --- a/src/EFCore.Relational/Metadata/Conventions/RelationalColumnCommentAttributeConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/RelationalColumnCommentAttributeConvention.cs @@ -4,7 +4,6 @@ using System.Reflection; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { @@ -26,8 +25,6 @@ public RelationalColumnCommentAttributeConvention( RelationalConventionSetBuilderDependencies relationalDependencies) : base(dependencies) { - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - RelationalDependencies = relationalDependencies; } diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalDbFunctionAttributeConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalDbFunctionAttributeConvention.cs index 615f573e43f..1c8c8dfb2c9 100644 --- a/src/EFCore.Relational/Metadata/Conventions/RelationalDbFunctionAttributeConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/RelationalDbFunctionAttributeConvention.cs @@ -5,7 +5,6 @@ using System.Reflection; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { @@ -28,9 +27,6 @@ public RelationalDbFunctionAttributeConvention( ProviderConventionSetBuilderDependencies dependencies, RelationalConventionSetBuilderDependencies relationalDependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - Dependencies = dependencies; RelationalDependencies = relationalDependencies; } diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalMaxIdentifierLengthConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalMaxIdentifierLengthConvention.cs index b8b210b8c8f..694a906b165 100644 --- a/src/EFCore.Relational/Metadata/Conventions/RelationalMaxIdentifierLengthConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/RelationalMaxIdentifierLengthConvention.cs @@ -3,7 +3,6 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { @@ -26,9 +25,6 @@ public RelationalMaxIdentifierLengthConvention( ProviderConventionSetBuilderDependencies dependencies, RelationalConventionSetBuilderDependencies relationalDependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - MaxIdentifierLength = maxIdentifierLength; Dependencies = dependencies; RelationalDependencies = relationalDependencies; diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalModelConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalModelConvention.cs index 8cc7db255d0..55f560474cd 100644 --- a/src/EFCore.Relational/Metadata/Conventions/RelationalModelConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/RelationalModelConvention.cs @@ -4,7 +4,6 @@ using System; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { @@ -26,9 +25,6 @@ public RelationalModelConvention( ProviderConventionSetBuilderDependencies dependencies, RelationalConventionSetBuilderDependencies relationalDependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - Dependencies = dependencies; RelationalDependencies = relationalDependencies; } diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalQueryFilterRewritingConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalQueryFilterRewritingConvention.cs index c14465a8ff1..3af54eeb54f 100644 --- a/src/EFCore.Relational/Metadata/Conventions/RelationalQueryFilterRewritingConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/RelationalQueryFilterRewritingConvention.cs @@ -7,7 +7,6 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.Internal; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { @@ -24,8 +23,6 @@ public RelationalQueryFilterRewritingConvention( RelationalConventionSetBuilderDependencies relationalDependencies) : base(dependencies) { - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - RelationalDependencies = relationalDependencies; DbSetAccessRewriter = new RelationalDbSetAccessRewritingExpressionVisitor(Dependencies.ContextType); } @@ -73,8 +70,6 @@ public RelationalDbSetAccessRewritingExpressionVisitor(Type contextType) /// protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression) { - Check.NotNull(methodCallExpression, nameof(methodCallExpression)); - var methodName = methodCallExpression.Method.Name; if (methodCallExpression.Method.DeclaringType == typeof(RelationalQueryableExtensions) && (methodName == nameof(RelationalQueryableExtensions.FromSqlRaw) diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalRuntimeModelConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalRuntimeModelConvention.cs index ab96517607c..7990e33c596 100644 --- a/src/EFCore.Relational/Metadata/Conventions/RelationalRuntimeModelConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/RelationalRuntimeModelConvention.cs @@ -7,7 +7,6 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; -using Microsoft.EntityFrameworkCore.Utilities; #nullable enable @@ -32,8 +31,6 @@ public RelationalRuntimeModelConvention( RelationalConventionSetBuilderDependencies relationalDependencies) : base(dependencies) { - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - RelationalDependencies = relationalDependencies; } diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalTableAttributeConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalTableAttributeConvention.cs index 0d349b32ded..8a773f9d928 100644 --- a/src/EFCore.Relational/Metadata/Conventions/RelationalTableAttributeConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/RelationalTableAttributeConvention.cs @@ -4,7 +4,6 @@ using System.ComponentModel.DataAnnotations.Schema; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { @@ -26,8 +25,6 @@ public RelationalTableAttributeConvention( RelationalConventionSetBuilderDependencies relationalDependencies) : base(dependencies) { - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - RelationalDependencies = relationalDependencies; } diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalTableCommentAttributeConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalTableCommentAttributeConvention.cs index f4ffc7e77b1..aba94bc585d 100644 --- a/src/EFCore.Relational/Metadata/Conventions/RelationalTableCommentAttributeConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/RelationalTableCommentAttributeConvention.cs @@ -3,7 +3,6 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { @@ -25,8 +24,6 @@ public RelationalTableCommentAttributeConvention( RelationalConventionSetBuilderDependencies relationalDependencies) : base(dependencies) { - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - RelationalDependencies = relationalDependencies; } diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalValueGenerationConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalValueGenerationConvention.cs index dce64308e7a..dc07d00826f 100644 --- a/src/EFCore.Relational/Metadata/Conventions/RelationalValueGenerationConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/RelationalValueGenerationConvention.cs @@ -4,7 +4,6 @@ using System.Linq; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { @@ -32,8 +31,6 @@ public RelationalValueGenerationConvention( RelationalConventionSetBuilderDependencies relationalDependencies) : base(dependencies) { - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - RelationalDependencies = relationalDependencies; } diff --git a/src/EFCore.Relational/Metadata/Conventions/SequenceUniquificationConvention.cs b/src/EFCore.Relational/Metadata/Conventions/SequenceUniquificationConvention.cs index cdb7f0293c0..d5c586a7175 100644 --- a/src/EFCore.Relational/Metadata/Conventions/SequenceUniquificationConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/SequenceUniquificationConvention.cs @@ -7,7 +7,6 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { @@ -30,8 +29,6 @@ public SequenceUniquificationConvention( ProviderConventionSetBuilderDependencies dependencies, RelationalConventionSetBuilderDependencies relationalDependencies) { - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - Dependencies = dependencies; RelationalDependencies = relationalDependencies; } diff --git a/src/EFCore.Relational/Metadata/Conventions/SharedTableConvention.cs b/src/EFCore.Relational/Metadata/Conventions/SharedTableConvention.cs index a0572043d3b..7ddb556d7ab 100644 --- a/src/EFCore.Relational/Metadata/Conventions/SharedTableConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/SharedTableConvention.cs @@ -9,7 +9,6 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { @@ -30,8 +29,6 @@ public SharedTableConvention( ProviderConventionSetBuilderDependencies dependencies, RelationalConventionSetBuilderDependencies relationalDependencies) { - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - Dependencies = dependencies; RelationalDependencies = relationalDependencies; } diff --git a/src/EFCore.Relational/Metadata/Conventions/StoreGenerationConvention.cs b/src/EFCore.Relational/Metadata/Conventions/StoreGenerationConvention.cs index 962da0f274b..a44290c5454 100644 --- a/src/EFCore.Relational/Metadata/Conventions/StoreGenerationConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/StoreGenerationConvention.cs @@ -5,7 +5,6 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { @@ -27,8 +26,6 @@ public StoreGenerationConvention( ProviderConventionSetBuilderDependencies dependencies, RelationalConventionSetBuilderDependencies relationalDependencies) { - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - Dependencies = dependencies; RelationalDependencies = relationalDependencies; } diff --git a/src/EFCore.Relational/Metadata/Conventions/TableNameFromDbSetConvention.cs b/src/EFCore.Relational/Metadata/Conventions/TableNameFromDbSetConvention.cs index 539b30bd093..91c54bc7786 100644 --- a/src/EFCore.Relational/Metadata/Conventions/TableNameFromDbSetConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/TableNameFromDbSetConvention.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { @@ -28,9 +27,6 @@ public TableNameFromDbSetConvention( ProviderConventionSetBuilderDependencies dependencies, RelationalConventionSetBuilderDependencies relationalDependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - _sets = new Dictionary(); List? ambiguousTypes = null; foreach (var set in dependencies.SetFinder.FindSets(dependencies.ContextType)) diff --git a/src/EFCore.Relational/Metadata/Conventions/TableSharingConcurrencyTokenConvention.cs b/src/EFCore.Relational/Metadata/Conventions/TableSharingConcurrencyTokenConvention.cs index 12e345a6c84..61f004463a0 100644 --- a/src/EFCore.Relational/Metadata/Conventions/TableSharingConcurrencyTokenConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/TableSharingConcurrencyTokenConvention.cs @@ -6,7 +6,6 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { @@ -33,8 +32,6 @@ public TableSharingConcurrencyTokenConvention( ProviderConventionSetBuilderDependencies dependencies, RelationalConventionSetBuilderDependencies relationalDependencies) { - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - Dependencies = dependencies; RelationalDependencies = relationalDependencies; } diff --git a/src/EFCore.Relational/Metadata/Conventions/TableValuedDbFunctionConvention.cs b/src/EFCore.Relational/Metadata/Conventions/TableValuedDbFunctionConvention.cs index c775a03d5db..95d673a84df 100644 --- a/src/EFCore.Relational/Metadata/Conventions/TableValuedDbFunctionConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/TableValuedDbFunctionConvention.cs @@ -7,7 +7,6 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { @@ -29,9 +28,6 @@ public TableValuedDbFunctionConvention( ProviderConventionSetBuilderDependencies dependencies, RelationalConventionSetBuilderDependencies relationalDependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - Dependencies = dependencies; RelationalDependencies = relationalDependencies; } diff --git a/src/EFCore.Relational/Metadata/Internal/CheckConstraint.cs b/src/EFCore.Relational/Metadata/Internal/CheckConstraint.cs index 8e0e855a88c..4466fcdcdea 100644 --- a/src/EFCore.Relational/Metadata/Internal/CheckConstraint.cs +++ b/src/EFCore.Relational/Metadata/Internal/CheckConstraint.cs @@ -8,7 +8,6 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Builders; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Internal { @@ -38,10 +37,6 @@ public CheckConstraint( string sql, ConfigurationSource configurationSource) { - Check.NotNull(entityType, nameof(entityType)); - Check.NotEmpty(name, nameof(name)); - Check.NotEmpty(sql, nameof(sql)); - EntityType = entityType; ModelName = name; Sql = sql; @@ -95,7 +90,6 @@ public CheckConstraint( /// public static IEnumerable GetDeclaredCheckConstraints(IReadOnlyEntityType entityType) { - Check.NotNull(entityType, nameof(entityType)); if (entityType is RuntimeEntityType) { throw new InvalidOperationException(CoreStrings.RuntimeModelMissingData); @@ -312,8 +306,6 @@ public virtual string Name /// public virtual string? SetName(string? name, ConfigurationSource configurationSource) { - Check.NullButNotEmpty(name, nameof(name)); - EnsureMutable(); _name = name; diff --git a/src/EFCore.Relational/Metadata/Internal/DbFunction.cs b/src/EFCore.Relational/Metadata/Internal/DbFunction.cs index ed2e3eeb2cf..c4c4e0b7657 100644 --- a/src/EFCore.Relational/Metadata/Internal/DbFunction.cs +++ b/src/EFCore.Relational/Metadata/Internal/DbFunction.cs @@ -14,7 +14,6 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Internal { @@ -94,8 +93,6 @@ public DbFunction( IMutableModel model, ConfigurationSource configurationSource) { - Check.NotEmpty(name, nameof(name)); - if (returnType == null || returnType == typeof(void)) { @@ -398,8 +395,6 @@ public virtual string Name /// public virtual string? SetName(string? name, ConfigurationSource configurationSource) { - Check.NullButNotEmpty(name, nameof(name)); - EnsureMutable(); _name = name; diff --git a/src/EFCore.Relational/Metadata/Internal/DbFunctionParameter.cs b/src/EFCore.Relational/Metadata/Internal/DbFunctionParameter.cs index 655e565f62c..3ceb8d3935c 100644 --- a/src/EFCore.Relational/Metadata/Internal/DbFunctionParameter.cs +++ b/src/EFCore.Relational/Metadata/Internal/DbFunctionParameter.cs @@ -8,7 +8,6 @@ using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Internal { @@ -44,10 +43,6 @@ public DbFunctionParameter( string name, Type clrType) { - Check.NotNull(function, nameof(function)); - Check.NotEmpty(name, nameof(name)); - Check.NotNull(clrType, nameof(clrType)); - Name = name; Function = function; ClrType = clrType; diff --git a/src/EFCore.Relational/Metadata/Internal/InternalCheckConstraintBuilder.cs b/src/EFCore.Relational/Metadata/Internal/InternalCheckConstraintBuilder.cs index fe50211f261..d70b992f5c6 100644 --- a/src/EFCore.Relational/Metadata/Internal/InternalCheckConstraintBuilder.cs +++ b/src/EFCore.Relational/Metadata/Internal/InternalCheckConstraintBuilder.cs @@ -5,7 +5,6 @@ using System.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Builders; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Internal { @@ -69,9 +68,6 @@ public virtual bool CanSetName(string? name, ConfigurationSource configurationSo string? sql, ConfigurationSource configurationSource) { - Check.NotEmpty(name, nameof(name)); - Check.NullButNotEmpty(sql, nameof(sql)); - List? checkConstraintsToBeDetached = null; var constraint = entityType.FindCheckConstraint(name); if (constraint != null) @@ -155,9 +151,6 @@ public static bool CanHaveCheckConstraint( string? sql, ConfigurationSource configurationSource) { - Check.NotEmpty(name, nameof(name)); - Check.NullButNotEmpty(sql, nameof(sql)); - var constraint = entityType.FindCheckConstraint(name); if (constraint != null) { diff --git a/src/EFCore.Relational/Metadata/Internal/Sequence.cs b/src/EFCore.Relational/Metadata/Internal/Sequence.cs index 7e48285e69b..52f75313e32 100644 --- a/src/EFCore.Relational/Metadata/Internal/Sequence.cs +++ b/src/EFCore.Relational/Metadata/Internal/Sequence.cs @@ -10,7 +10,6 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Builders; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Internal { @@ -99,9 +98,6 @@ public Sequence( IReadOnlyModel model, ConfigurationSource configurationSource) { - Check.NotEmpty(name, nameof(name)); - Check.NullButNotEmpty(schema, nameof(schema)); - Model = model; Name = name; _schema = schema; @@ -118,9 +114,6 @@ public Sequence( [Obsolete("Use the other constructor")] public Sequence(IReadOnlyModel model, string annotationName) { - Check.NotNull(model, nameof(model)); - Check.NotEmpty(annotationName, nameof(annotationName)); - Model = model; _configurationSource = ConfigurationSource.Explicit; @@ -200,10 +193,6 @@ public static Sequence AddSequence( Sequence sequence, string name) { - Check.NotNull(model, nameof(model)); - Check.NotNull(sequence, nameof(sequence)); - Check.NotEmpty(name, nameof(name)); - sequence.EnsureMutable(); var sequences = (SortedDictionary<(string, string?), ISequence>?)model[RelationalAnnotationNames.Sequences]; @@ -760,8 +749,6 @@ private sealed class SequenceData public static SequenceData Deserialize(string value) { - Check.NotEmpty(value, nameof(value)); - try { var data = new SequenceData(); diff --git a/src/EFCore.Relational/Metadata/RelationalAnnotationProvider.cs b/src/EFCore.Relational/Metadata/RelationalAnnotationProvider.cs index a5ab0d229e1..578208e8dbc 100644 --- a/src/EFCore.Relational/Metadata/RelationalAnnotationProvider.cs +++ b/src/EFCore.Relational/Metadata/RelationalAnnotationProvider.cs @@ -31,8 +31,6 @@ public class RelationalAnnotationProvider : IRelationalAnnotationProvider /// Parameter object containing dependencies for this service. public RelationalAnnotationProvider(RelationalAnnotationProviderDependencies dependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Dependencies = dependencies; } diff --git a/src/EFCore.Relational/Migrations/HistoryRepository.cs b/src/EFCore.Relational/Migrations/HistoryRepository.cs index 54b5c3d9f5d..a7359f09fbc 100644 --- a/src/EFCore.Relational/Migrations/HistoryRepository.cs +++ b/src/EFCore.Relational/Migrations/HistoryRepository.cs @@ -13,7 +13,6 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Migrations @@ -55,8 +54,6 @@ public abstract class HistoryRepository : IHistoryRepository /// Parameter object containing dependencies for this service. protected HistoryRepository(HistoryRepositoryDependencies dependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Dependencies = dependencies; var relationalOptions = RelationalOptionsExtension.Extract(dependencies.Options); @@ -297,8 +294,6 @@ protected virtual string GetAppliedMigrationsSql /// The generated SQL. public virtual string GetInsertScript(HistoryRow row) { - Check.NotNull(row, nameof(row)); - var stringTypeMapping = Dependencies.TypeMappingSource.GetMapping(typeof(string)); return new StringBuilder().Append("INSERT INTO ") @@ -324,8 +319,6 @@ public virtual string GetInsertScript(HistoryRow row) /// The generated SQL. public virtual string GetDeleteScript(string migrationId) { - Check.NotEmpty(migrationId, nameof(migrationId)); - var stringTypeMapping = Dependencies.TypeMappingSource.GetMapping(typeof(string)); return new StringBuilder().Append("DELETE FROM ") diff --git a/src/EFCore.Relational/Migrations/HistoryRepositoryDependencies.cs b/src/EFCore.Relational/Migrations/HistoryRepositoryDependencies.cs index c75517d1342..347f8ac8abd 100644 --- a/src/EFCore.Relational/Migrations/HistoryRepositoryDependencies.cs +++ b/src/EFCore.Relational/Migrations/HistoryRepositoryDependencies.cs @@ -6,7 +6,6 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Migrations @@ -70,21 +69,6 @@ public HistoryRepositoryDependencies( IDiagnosticsLogger modelLogger, IRelationalCommandDiagnosticsLogger commandLogger) { - Check.NotNull(databaseCreator, nameof(databaseCreator)); - Check.NotNull(rawSqlCommandBuilder, nameof(rawSqlCommandBuilder)); - Check.NotNull(connection, nameof(connection)); - Check.NotNull(options, nameof(options)); - Check.NotNull(modelDiffer, nameof(modelDiffer)); - Check.NotNull(migrationsSqlGenerator, nameof(migrationsSqlGenerator)); - Check.NotNull(sqlGenerationHelper, nameof(sqlGenerationHelper)); - Check.NotNull(conventionSetBuilder, nameof(conventionSetBuilder)); - Check.NotNull(modelDependencies, nameof(modelDependencies)); - Check.NotNull(typeMappingSource, nameof(typeMappingSource)); - Check.NotNull(currentContext, nameof(currentContext)); - Check.NotNull(modelRuntimeInitializer, nameof(modelRuntimeInitializer)); - Check.NotNull(modelLogger, nameof(modelLogger)); - Check.NotNull(commandLogger, nameof(commandLogger)); - DatabaseCreator = databaseCreator; RawSqlCommandBuilder = rawSqlCommandBuilder; Connection = connection; diff --git a/src/EFCore.Relational/Migrations/HistoryRow.cs b/src/EFCore.Relational/Migrations/HistoryRow.cs index 7a714571410..b48886710e7 100644 --- a/src/EFCore.Relational/Migrations/HistoryRow.cs +++ b/src/EFCore.Relational/Migrations/HistoryRow.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Reflection; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Migrations { @@ -25,9 +24,6 @@ public class HistoryRow /// public HistoryRow(string migrationId, string productVersion) { - Check.NotEmpty(migrationId, nameof(migrationId)); - Check.NotEmpty(productVersion, nameof(productVersion)); - MigrationId = migrationId; ProductVersion = productVersion; } diff --git a/src/EFCore.Relational/Migrations/Internal/MigrationCommandExecutor.cs b/src/EFCore.Relational/Migrations/Internal/MigrationCommandExecutor.cs index e91f0e33341..d4b79818f55 100644 --- a/src/EFCore.Relational/Migrations/Internal/MigrationCommandExecutor.cs +++ b/src/EFCore.Relational/Migrations/Internal/MigrationCommandExecutor.cs @@ -31,9 +31,6 @@ public virtual void ExecuteNonQuery( IEnumerable migrationCommands, IRelationalConnection connection) { - Check.NotNull(migrationCommands, nameof(migrationCommands)); - Check.NotNull(connection, nameof(connection)); - var userTransaction = connection.CurrentTransaction; if (userTransaction is not null && migrationCommands.Any(x => x.TransactionSuppressed)) { @@ -95,9 +92,6 @@ public virtual async Task ExecuteNonQueryAsync( IRelationalConnection connection, CancellationToken cancellationToken = default) { - Check.NotNull(migrationCommands, nameof(migrationCommands)); - Check.NotNull(connection, nameof(connection)); - var userTransaction = connection.CurrentTransaction; if (userTransaction is not null && migrationCommands.Any(x => x.TransactionSuppressed)) { diff --git a/src/EFCore.Relational/Migrations/Internal/MigrationsAssembly.cs b/src/EFCore.Relational/Migrations/Internal/MigrationsAssembly.cs index 24638ef8b82..9caaba0de2d 100644 --- a/src/EFCore.Relational/Migrations/Internal/MigrationsAssembly.cs +++ b/src/EFCore.Relational/Migrations/Internal/MigrationsAssembly.cs @@ -7,7 +7,6 @@ using System.Reflection; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Migrations.Internal { @@ -37,11 +36,6 @@ public MigrationsAssembly( IMigrationsIdGenerator idGenerator, IDiagnosticsLogger logger) { - Check.NotNull(currentContext, nameof(currentContext)); - Check.NotNull(options, nameof(options)); - Check.NotNull(idGenerator, nameof(idGenerator)); - Check.NotNull(logger, nameof(logger)); - _contextType = currentContext.Context.GetType(); var assemblyName = RelationalOptionsExtension.Extract(options)?.MigrationsAssembly; @@ -139,8 +133,6 @@ where t.IsSubclassOf(typeof(ModelSnapshot)) /// public virtual Migration CreateMigration(TypeInfo migrationClass, string activeProvider) { - Check.NotNull(activeProvider, nameof(activeProvider)); - var migration = (Migration)Activator.CreateInstance(migrationClass.AsType())!; migration.ActiveProvider = activeProvider; diff --git a/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs b/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs index 7ad3bebebcc..b78f456d4da 100644 --- a/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs +++ b/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs @@ -78,14 +78,6 @@ public MigrationsModelDiffer( IUpdateAdapterFactory updateAdapterFactory, CommandBatchPreparerDependencies commandBatchPreparerDependencies) { - Check.NotNull(typeMappingSource, nameof(typeMappingSource)); - Check.NotNull(migrationsAnnotations, nameof(migrationsAnnotations)); -#pragma warning disable EF1001 // Internal EF Core API usage. - Check.NotNull(changeDetector, nameof(changeDetector)); -#pragma warning restore EF1001 // Internal EF Core API usage. - Check.NotNull(updateAdapterFactory, nameof(updateAdapterFactory)); - Check.NotNull(commandBatchPreparerDependencies, nameof(commandBatchPreparerDependencies)); - TypeMappingSource = typeMappingSource; MigrationsAnnotations = migrationsAnnotations; ChangeDetector = changeDetector; @@ -166,8 +158,6 @@ protected virtual IReadOnlyList Sort( IEnumerable operations, DiffContext diffContext) { - Check.NotNull(operations, nameof(operations)); - var dropForeignKeyOperations = new List(); var dropOperations = new List(); var dropColumnOperations = new List(); @@ -1754,8 +1744,6 @@ protected virtual void TrackData( IRelationalModel? target, DiffContext diffContext) { - Check.NotNull(diffContext, nameof(diffContext)); - if (source == null || target == null) { diff --git a/src/EFCore.Relational/Migrations/Internal/Migrator.cs b/src/EFCore.Relational/Migrations/Internal/Migrator.cs index 76a2c63fe00..3b177b8880d 100644 --- a/src/EFCore.Relational/Migrations/Internal/Migrator.cs +++ b/src/EFCore.Relational/Migrations/Internal/Migrator.cs @@ -11,7 +11,6 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Migrations.Internal { @@ -58,20 +57,6 @@ public Migrator( IRelationalCommandDiagnosticsLogger commandLogger, IDatabaseProvider databaseProvider) { - Check.NotNull(migrationsAssembly, nameof(migrationsAssembly)); - Check.NotNull(historyRepository, nameof(historyRepository)); - Check.NotNull(databaseCreator, nameof(databaseCreator)); - Check.NotNull(migrationsSqlGenerator, nameof(migrationsSqlGenerator)); - Check.NotNull(rawSqlCommandBuilder, nameof(rawSqlCommandBuilder)); - Check.NotNull(migrationCommandExecutor, nameof(migrationCommandExecutor)); - Check.NotNull(connection, nameof(connection)); - Check.NotNull(sqlGenerationHelper, nameof(sqlGenerationHelper)); - Check.NotNull(currentContext, nameof(currentContext)); - Check.NotNull(modelRuntimeInitializer, nameof(modelRuntimeInitializer)); - Check.NotNull(logger, nameof(logger)); - Check.NotNull(commandLogger, nameof(commandLogger)); - Check.NotNull(databaseProvider, nameof(databaseProvider)); - _migrationsAssembly = migrationsAssembly; _historyRepository = historyRepository; _databaseCreator = (IRelationalDatabaseCreator)databaseCreator; @@ -453,8 +438,6 @@ protected virtual IReadOnlyList GenerateUpSql( Migration migration, MigrationsSqlGenerationOptions options = MigrationsSqlGenerationOptions.Default) { - Check.NotNull(migration, nameof(migration)); - var insertCommand = _rawSqlCommandBuilder.Build( _historyRepository.GetInsertScript(new HistoryRow(migration.GetId(), ProductInfo.GetVersion()))); @@ -475,8 +458,6 @@ protected virtual IReadOnlyList GenerateDownSql( Migration? previousMigration, MigrationsSqlGenerationOptions options = MigrationsSqlGenerationOptions.Default) { - Check.NotNull(migration, nameof(migration)); - var deleteCommand = _rawSqlCommandBuilder.Build( _historyRepository.GetDeleteScript(migration.GetId())); diff --git a/src/EFCore.Relational/Migrations/MigrationCommand.cs b/src/EFCore.Relational/Migrations/MigrationCommand.cs index e7ef72cfa04..a0f7303d2b1 100644 --- a/src/EFCore.Relational/Migrations/MigrationCommand.cs +++ b/src/EFCore.Relational/Migrations/MigrationCommand.cs @@ -7,7 +7,6 @@ using System.Threading.Tasks; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Migrations { @@ -35,8 +34,6 @@ public MigrationCommand( IRelationalCommandDiagnosticsLogger logger, bool transactionSuppressed = false) { - Check.NotNull(relationalCommand, nameof(relationalCommand)); - _relationalCommand = relationalCommand; _context = context; CommandLogger = logger; diff --git a/src/EFCore.Relational/Migrations/MigrationCommandListBuilder.cs b/src/EFCore.Relational/Migrations/MigrationCommandListBuilder.cs index 38c531aeb54..40ede2ca445 100644 --- a/src/EFCore.Relational/Migrations/MigrationCommandListBuilder.cs +++ b/src/EFCore.Relational/Migrations/MigrationCommandListBuilder.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Migrations { @@ -28,8 +27,6 @@ public class MigrationCommandListBuilder public MigrationCommandListBuilder( MigrationsSqlGeneratorDependencies dependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Dependencies = dependencies; _commandBuilder = dependencies.CommandBuilderFactory.Create(); } @@ -78,8 +75,6 @@ public virtual MigrationCommandListBuilder EndCommand(bool suppressTransaction = /// This builder so that additional calls can be chained. public virtual MigrationCommandListBuilder Append(string o) { - Check.NotNull(o, nameof(o)); - _commandBuilder.Append(o); return this; @@ -103,8 +98,6 @@ public virtual MigrationCommandListBuilder AppendLine() /// This builder so that additional calls can be chained. public virtual MigrationCommandListBuilder AppendLine(string value) { - Check.NotNull(value, nameof(value)); - _commandBuilder.AppendLine(value); return this; @@ -119,8 +112,6 @@ public virtual MigrationCommandListBuilder AppendLine(string value) /// This builder so that additional calls can be chained. public virtual MigrationCommandListBuilder AppendLines(string value) { - Check.NotNull(value, nameof(value)); - _commandBuilder.AppendLines(value); return this; diff --git a/src/EFCore.Relational/Migrations/MigrationsAnnotationProvider.cs b/src/EFCore.Relational/Migrations/MigrationsAnnotationProvider.cs index c944015ce4f..df412578665 100644 --- a/src/EFCore.Relational/Migrations/MigrationsAnnotationProvider.cs +++ b/src/EFCore.Relational/Migrations/MigrationsAnnotationProvider.cs @@ -5,7 +5,6 @@ using System.Linq; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Migrations @@ -32,8 +31,6 @@ public class MigrationsAnnotationProvider : IMigrationsAnnotationProvider /// Parameter object containing dependencies for this service. public MigrationsAnnotationProvider(MigrationsAnnotationProviderDependencies dependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Dependencies = dependencies; } diff --git a/src/EFCore.Relational/Migrations/MigrationsAssemblyExtensions.cs b/src/EFCore.Relational/Migrations/MigrationsAssemblyExtensions.cs index 7ffc00928f7..92d39ede6ff 100644 --- a/src/EFCore.Relational/Migrations/MigrationsAssemblyExtensions.cs +++ b/src/EFCore.Relational/Migrations/MigrationsAssemblyExtensions.cs @@ -33,7 +33,6 @@ public static class MigrationsAssemblyExtensions /// The identifier of the migration. public static string GetMigrationId(this IMigrationsAssembly assembly, string nameOrId) { - Check.NotNull(assembly, nameof(assembly)); Check.NotEmpty(nameOrId, nameof(nameOrId)); var id = assembly.FindMigrationId(nameOrId); diff --git a/src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs b/src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs index d5f42725144..fb74629e0d0 100644 --- a/src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs +++ b/src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs @@ -82,8 +82,6 @@ private static readonly /// Parameter object containing dependencies for this service. public MigrationsSqlGenerator(MigrationsSqlGeneratorDependencies dependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Dependencies = dependencies; if (dependencies.LoggingOptions.IsSensitiveDataLoggingEnabled) @@ -127,8 +125,6 @@ public virtual IReadOnlyList Generate( IModel? model = null, MigrationsSqlGenerationOptions options = MigrationsSqlGenerationOptions.Default) { - Check.NotNull(operations, nameof(operations)); - Options = options; var builder = new MigrationCommandListBuilder(Dependencies); @@ -165,9 +161,6 @@ protected virtual void Generate( IModel? model, MigrationCommandListBuilder builder) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - var operationType = operation.GetType(); if (!_generateActions.TryGetValue(operationType, out var generateAction)) { @@ -191,9 +184,6 @@ protected virtual void Generate( MigrationCommandListBuilder builder, bool terminate = true) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - if (operation[RelationalAnnotationNames.ColumnOrder] != null) { Dependencies.MigrationsLogger.ColumnOrderIgnoredWarning(operation); @@ -227,9 +217,6 @@ protected virtual void Generate( MigrationCommandListBuilder builder, bool terminate = true) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - builder .Append("ALTER TABLE ") .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Table, operation.Schema)) @@ -258,9 +245,6 @@ protected virtual void Generate( MigrationCommandListBuilder builder, bool terminate = true) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - builder .Append("ALTER TABLE ") .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Table, operation.Schema)) @@ -286,9 +270,6 @@ protected virtual void Generate( IModel? model, MigrationCommandListBuilder builder) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - builder .Append("ALTER TABLE ") .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Table, operation.Schema)) @@ -310,9 +291,6 @@ protected virtual void Generate( IModel? model, MigrationCommandListBuilder builder) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - builder .Append("ALTER TABLE ") .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Table, operation.Schema)) @@ -386,9 +364,6 @@ protected virtual void Generate( IModel? model, MigrationCommandListBuilder builder) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - builder .Append("ALTER SEQUENCE ") .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Name, operation.Schema)); @@ -450,9 +425,6 @@ protected virtual void Generate( MigrationCommandListBuilder builder, bool terminate = true) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - builder.Append("CREATE "); if (operation.IsUnique) @@ -509,9 +481,6 @@ protected virtual void Generate( IModel? model, MigrationCommandListBuilder builder) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - builder .Append("CREATE SEQUENCE ") .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Name, operation.Schema)); @@ -553,9 +522,6 @@ protected virtual void Generate( MigrationCommandListBuilder builder, bool terminate = true) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - builder .Append("CREATE TABLE ") .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Name, operation.Schema)) @@ -591,9 +557,6 @@ protected virtual void Generate( MigrationCommandListBuilder builder, bool terminate = true) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - builder .Append("ALTER TABLE ") .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Table, operation.Schema)) @@ -621,9 +584,6 @@ protected virtual void Generate( MigrationCommandListBuilder builder, bool terminate = true) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - builder .Append("ALTER TABLE ") .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Table, operation.Schema)) @@ -670,9 +630,6 @@ protected virtual void Generate( MigrationCommandListBuilder builder, bool terminate = true) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - builder .Append("ALTER TABLE ") .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Table, operation.Schema)) @@ -698,9 +655,6 @@ protected virtual void Generate( IModel? model, MigrationCommandListBuilder builder) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - builder .Append("DROP SCHEMA ") .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Name)) @@ -721,9 +675,6 @@ protected virtual void Generate( IModel? model, MigrationCommandListBuilder builder) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - builder .Append("DROP SEQUENCE ") .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Name, operation.Schema)) @@ -746,9 +697,6 @@ protected virtual void Generate( MigrationCommandListBuilder builder, bool terminate = true) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - builder .Append("DROP TABLE ") .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Name, operation.Schema)); @@ -772,9 +720,6 @@ protected virtual void Generate( IModel? model, MigrationCommandListBuilder builder) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - builder .Append("ALTER TABLE ") .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Table, operation.Schema)) @@ -797,9 +742,6 @@ protected virtual void Generate( IModel? model, MigrationCommandListBuilder builder) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - builder .Append("ALTER TABLE ") .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Table, operation.Schema)) @@ -856,9 +798,6 @@ protected virtual void Generate( IModel? model, MigrationCommandListBuilder builder) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - var longTypeMapping = Dependencies.TypeMappingSource.GetMapping(typeof(long)); builder @@ -883,9 +822,6 @@ protected virtual void Generate( IModel? model, MigrationCommandListBuilder builder) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - builder.AppendLine(operation.Sql); EndStatement(builder, operation.SuppressTransaction); @@ -905,9 +841,6 @@ protected virtual void Generate( MigrationCommandListBuilder builder, bool terminate = true) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - var sqlBuilder = new StringBuilder(); foreach (var modificationCommand in GenerateModificationCommands(operation, model)) { @@ -1001,9 +934,6 @@ protected virtual void Generate( IModel? model, MigrationCommandListBuilder builder) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - var sqlBuilder = new StringBuilder(); foreach (var modificationCommand in GenerateModificationCommands(operation, model)) { @@ -1093,9 +1023,6 @@ protected virtual void Generate( IModel? model, MigrationCommandListBuilder builder) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - var sqlBuilder = new StringBuilder(); foreach (var modificationCommand in GenerateModificationCommands(operation, model)) { @@ -1301,10 +1228,6 @@ protected virtual void SequenceOptions( IModel? model, MigrationCommandListBuilder builder) { - Check.NotEmpty(name, nameof(name)); - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - var intTypeMapping = Dependencies.TypeMappingSource.GetMapping(typeof(int)); var longTypeMapping = Dependencies.TypeMappingSource.GetMapping(typeof(long)); @@ -1348,9 +1271,6 @@ protected virtual void CreateTableColumns( IModel? model, MigrationCommandListBuilder builder) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - for (var i = 0; i < operation.Columns.Count; i++) { ColumnDefinition(operation.Columns[i], model, builder); @@ -1397,10 +1317,6 @@ protected virtual void ColumnDefinition( IModel? model, MigrationCommandListBuilder builder) { - Check.NotEmpty(name, nameof(name)); - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - if (operation.ComputedColumnSql != null) { ComputedColumnDefinition(schema, table, name, operation, model, builder); @@ -1460,10 +1376,6 @@ protected virtual void ComputedColumnDefinition( ColumnOperation operation, IModel? model) { - Check.NotEmpty(tableName, nameof(tableName)); - Check.NotEmpty(name, nameof(name)); - Check.NotNull(operation, nameof(operation)); - var keyOrIndex = false; var table = model?.GetRelationalModel().FindTable(tableName, schema); @@ -1511,8 +1423,6 @@ protected virtual void DefaultValue( string? columnType, MigrationCommandListBuilder builder) { - Check.NotNull(builder, nameof(builder)); - if (defaultValueSql != null) { builder @@ -1547,9 +1457,6 @@ protected virtual void CreateTableConstraints( IModel? model, MigrationCommandListBuilder builder) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - CreateTablePrimaryKeyConstraint(operation, model, builder); CreateTableUniqueConstraints(operation, model, builder); CreateTableCheckConstraints(operation, model, builder); @@ -1567,9 +1474,6 @@ protected virtual void CreateTableForeignKeys( IModel? model, MigrationCommandListBuilder builder) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - foreach (var foreignKey in operation.ForeignKeys) { builder.AppendLine(","); @@ -1588,9 +1492,6 @@ protected virtual void ForeignKeyConstraint( IModel? model, MigrationCommandListBuilder builder) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - if (operation.Name != null) { builder @@ -1637,9 +1538,6 @@ protected virtual void CreateTablePrimaryKeyConstraint( IModel? model, MigrationCommandListBuilder builder) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - if (operation.PrimaryKey != null) { builder.AppendLine(","); @@ -1658,9 +1556,6 @@ protected virtual void PrimaryKeyConstraint( IModel? model, MigrationCommandListBuilder builder) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - if (operation.Name != null) { builder @@ -1690,9 +1585,6 @@ protected virtual void CreateTableUniqueConstraints( IModel? model, MigrationCommandListBuilder builder) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - foreach (var uniqueConstraint in operation.UniqueConstraints) { builder.AppendLine(","); @@ -1711,9 +1603,6 @@ protected virtual void UniqueConstraint( IModel? model, MigrationCommandListBuilder builder) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - if (operation.Name != null) { builder @@ -1743,9 +1632,6 @@ protected virtual void CreateTableCheckConstraints( IModel? model, MigrationCommandListBuilder builder) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - foreach (var checkConstraint in operation.CheckConstraints) { builder.AppendLine(","); @@ -1764,9 +1650,6 @@ protected virtual void CheckConstraint( IModel? model, MigrationCommandListBuilder builder) { - Check.NotNull(operation, nameof(operation)); - Check.NotNull(builder, nameof(builder)); - if (operation.Name != null) { builder @@ -1825,8 +1708,6 @@ protected virtual void ForeignKeyAction( ReferentialAction referentialAction, MigrationCommandListBuilder builder) { - Check.NotNull(builder, nameof(builder)); - switch (referentialAction) { case ReferentialAction.Restrict: @@ -1861,7 +1742,7 @@ protected virtual void ForeignKeyAction( IModel? model, string? schema, string tableName) - => model?.GetRelationalModel().FindTable(Check.NotEmpty(tableName, nameof(tableName)), schema) + => model?.GetRelationalModel().FindTable(tableName, schema) ?.EntityTypeMappings.Select(m => m.EntityType); /// @@ -1883,7 +1764,7 @@ protected virtual void ForeignKeyAction( string? schema, string tableName, string columnName) - => model?.GetRelationalModel().FindTable(Check.NotEmpty(tableName, nameof(tableName)), schema) + => model?.GetRelationalModel().FindTable(tableName, schema) ?.Columns.FirstOrDefault(c => c.Name == columnName)?.PropertyMappings.First().Property; /// @@ -1896,11 +1777,7 @@ protected virtual void ForeignKeyAction( protected virtual void EndStatement( MigrationCommandListBuilder builder, bool suppressTransaction = false) - { - Check.NotNull(builder, nameof(builder)); - - builder.EndCommand(suppressTransaction); - } + => builder.EndCommand(suppressTransaction); /// /// Concatenates the given column names into a diff --git a/src/EFCore.Relational/Migrations/MigrationsSqlGeneratorDependencies.cs b/src/EFCore.Relational/Migrations/MigrationsSqlGeneratorDependencies.cs index a7fcdb1c2a9..31c268f7264 100644 --- a/src/EFCore.Relational/Migrations/MigrationsSqlGeneratorDependencies.cs +++ b/src/EFCore.Relational/Migrations/MigrationsSqlGeneratorDependencies.cs @@ -5,7 +5,6 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Update; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Migrations @@ -63,15 +62,6 @@ public MigrationsSqlGeneratorDependencies( IRelationalCommandDiagnosticsLogger logger, IDiagnosticsLogger migrationsLogger) { - Check.NotNull(commandBuilderFactory, nameof(commandBuilderFactory)); - Check.NotNull(updateSqlGenerator, nameof(updateSqlGenerator)); - Check.NotNull(sqlGenerationHelper, nameof(sqlGenerationHelper)); - Check.NotNull(typeMappingSource, nameof(typeMappingSource)); - Check.NotNull(currentContext, nameof(currentContext)); - Check.NotNull(loggingOptions, nameof(loggingOptions)); - Check.NotNull(logger, nameof(logger)); - Check.NotNull(migrationsLogger, nameof(migrationsLogger)); - CommandBuilderFactory = commandBuilderFactory; SqlGenerationHelper = sqlGenerationHelper; UpdateSqlGenerator = updateSqlGenerator; diff --git a/src/EFCore.Relational/Query/CollectionResultExpression.cs b/src/EFCore.Relational/Query/CollectionResultExpression.cs index b5360a89b48..ce18f63886c 100644 --- a/src/EFCore.Relational/Query/CollectionResultExpression.cs +++ b/src/EFCore.Relational/Query/CollectionResultExpression.cs @@ -5,7 +5,6 @@ using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query { @@ -63,8 +62,6 @@ public override ExpressionType NodeType /// protected override Expression VisitChildren(ExpressionVisitor visitor) { - Check.NotNull(visitor, nameof(visitor)); - var projectionBindingExpression = (ProjectionBindingExpression)visitor.Visit(ProjectionBindingExpression); return Update(projectionBindingExpression); @@ -77,13 +74,9 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// The property of the result. /// This expression if no children changed, or an expression with the updated children. public virtual CollectionResultExpression Update(ProjectionBindingExpression projectionBindingExpression) - { - Check.NotNull(projectionBindingExpression, nameof(projectionBindingExpression)); - - return projectionBindingExpression != ProjectionBindingExpression + => projectionBindingExpression != ProjectionBindingExpression ? new CollectionResultExpression(projectionBindingExpression, Navigation, ElementType) : this; - } /// public virtual void Print(ExpressionPrinter expressionPrinter) diff --git a/src/EFCore.Relational/Query/EntityProjectionExpression.cs b/src/EFCore.Relational/Query/EntityProjectionExpression.cs index 5d34792ec49..37789361c15 100644 --- a/src/EFCore.Relational/Query/EntityProjectionExpression.cs +++ b/src/EFCore.Relational/Query/EntityProjectionExpression.cs @@ -9,7 +9,6 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query { @@ -38,9 +37,6 @@ public EntityProjectionExpression( IReadOnlyDictionary propertyExpressionMap, SqlExpression? discriminatorExpression = null) { - Check.NotNull(entityType, nameof(entityType)); - Check.NotNull(propertyExpressionMap, nameof(propertyExpressionMap)); - EntityType = entityType; _propertyExpressionMap = propertyExpressionMap; DiscriminatorExpression = discriminatorExpression; @@ -67,8 +63,6 @@ public override Type Type /// protected override Expression VisitChildren(ExpressionVisitor visitor) { - Check.NotNull(visitor, nameof(visitor)); - var changed = false; var propertyExpressionMap = new Dictionary(); foreach (var expression in _propertyExpressionMap) @@ -110,8 +104,6 @@ public virtual EntityProjectionExpression MakeNullable() /// A new entity projection expression which has the derived type being projected. public virtual EntityProjectionExpression UpdateEntityType(IEntityType derivedType) { - Check.NotNull(derivedType, nameof(derivedType)); - if (!derivedType.GetAllBaseTypes().Contains(EntityType)) { throw new InvalidOperationException( @@ -151,8 +143,6 @@ public virtual EntityProjectionExpression UpdateEntityType(IEntityType derivedTy /// A column which is a SQL representation of the property. public virtual ColumnExpression BindProperty(IProperty property) { - Check.NotNull(property, nameof(property)); - if (!EntityType.IsAssignableFrom(property.DeclaringEntityType) && !property.DeclaringEntityType.IsAssignableFrom(EntityType)) { @@ -170,9 +160,6 @@ public virtual ColumnExpression BindProperty(IProperty property) /// An entity shaper expression for the target type. public virtual void AddNavigationBinding(INavigation navigation, EntityShaperExpression entityShaper) { - Check.NotNull(navigation, nameof(navigation)); - Check.NotNull(entityShaper, nameof(entityShaper)); - if (!EntityType.IsAssignableFrom(navigation.DeclaringEntityType) && !navigation.DeclaringEntityType.IsAssignableFrom(EntityType)) { @@ -191,8 +178,6 @@ public virtual void AddNavigationBinding(INavigation navigation, EntityShaperExp /// An entity shaper expression for the target entity type of the navigation. public virtual EntityShaperExpression? BindNavigation(INavigation navigation) { - Check.NotNull(navigation, nameof(navigation)); - if (!EntityType.IsAssignableFrom(navigation.DeclaringEntityType) && !navigation.DeclaringEntityType.IsAssignableFrom(EntityType)) { diff --git a/src/EFCore.Relational/Query/ExpressionExtensions.cs b/src/EFCore.Relational/Query/ExpressionExtensions.cs index b143784825c..e6ea4f37f9d 100644 --- a/src/EFCore.Relational/Query/ExpressionExtensions.cs +++ b/src/EFCore.Relational/Query/ExpressionExtensions.cs @@ -4,7 +4,6 @@ using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query { @@ -26,8 +25,6 @@ public static class ExpressionExtensions /// A relational type mapping inferred from the expressions. public static RelationalTypeMapping? InferTypeMapping(params SqlExpression[] expressions) { - Check.NotNull(expressions, nameof(expressions)); - for (var i = 0; i < expressions.Length; i++) { var sql = expressions[i]; diff --git a/src/EFCore.Relational/Query/Internal/BufferedDataReader.cs b/src/EFCore.Relational/Query/Internal/BufferedDataReader.cs index 54482c57ccf..a56c89f279c 100644 --- a/src/EFCore.Relational/Query/Internal/BufferedDataReader.cs +++ b/src/EFCore.Relational/Query/Internal/BufferedDataReader.cs @@ -551,7 +551,6 @@ public override string GetName(int ordinal) /// public override int GetOrdinal(string name) { - Check.NotNull(name, "name"); AssertReaderIsOpen(); return _currentResultSet.GetOrdinal(name); } diff --git a/src/EFCore.Relational/Query/Internal/ByteArraySequenceEqualTranslator.cs b/src/EFCore.Relational/Query/Internal/ByteArraySequenceEqualTranslator.cs index d5cc4308b1f..ca3c20e57e6 100644 --- a/src/EFCore.Relational/Query/Internal/ByteArraySequenceEqualTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/ByteArraySequenceEqualTranslator.cs @@ -5,7 +5,6 @@ using System.Reflection; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.Internal { @@ -42,10 +41,6 @@ public ByteArraySequenceEqualTranslator(ISqlExpressionFactory sqlExpressionFacto 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 47fdc2d0095..e5992c3e370 100644 --- a/src/EFCore.Relational/Query/Internal/CollateTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/CollateTranslator.cs @@ -6,7 +6,6 @@ using System.Reflection; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.Internal { @@ -32,17 +31,11 @@ private static readonly MethodInfo _methodInfo MethodInfo method, IReadOnlyList arguments, IDiagnosticsLogger logger) - { - Check.NotNull(method, nameof(method)); - Check.NotNull(arguments, nameof(arguments)); - Check.NotNull(logger, nameof(logger)); - - return method.IsGenericMethod + => method.IsGenericMethod && Equals(method.GetGenericMethodDefinition(), _methodInfo) && arguments[2] is SqlConstantExpression constantExpression && constantExpression.Value is string collation ? new CollateExpression(arguments[1], collation) : null; - } } } diff --git a/src/EFCore.Relational/Query/Internal/ComparisonTranslator.cs b/src/EFCore.Relational/Query/Internal/ComparisonTranslator.cs index 3a8de2cbbbc..c7b8e04d83a 100644 --- a/src/EFCore.Relational/Query/Internal/ComparisonTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/ComparisonTranslator.cs @@ -5,7 +5,6 @@ using System.Reflection; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.Internal { @@ -42,10 +41,6 @@ public ComparisonTranslator(ISqlExpressionFactory sqlExpressionFactory) IReadOnlyList arguments, IDiagnosticsLogger logger) { - Check.NotNull(method, nameof(method)); - Check.NotNull(arguments, nameof(arguments)); - Check.NotNull(logger, nameof(logger)); - if (method.ReturnType == typeof(int)) { SqlExpression? left = null; diff --git a/src/EFCore.Relational/Query/Internal/ContainsTranslator.cs b/src/EFCore.Relational/Query/Internal/ContainsTranslator.cs index 7281832e864..198e559a860 100644 --- a/src/EFCore.Relational/Query/Internal/ContainsTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/ContainsTranslator.cs @@ -6,7 +6,6 @@ using System.Reflection; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.Internal { @@ -43,10 +42,6 @@ public ContainsTranslator(ISqlExpressionFactory sqlExpressionFactory) 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) && ValidateValues(arguments[0])) diff --git a/src/EFCore.Relational/Query/Internal/EnumHasFlagTranslator.cs b/src/EFCore.Relational/Query/Internal/EnumHasFlagTranslator.cs index 4009d484e59..d09981ab9d1 100644 --- a/src/EFCore.Relational/Query/Internal/EnumHasFlagTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/EnumHasFlagTranslator.cs @@ -6,7 +6,6 @@ using System.Reflection; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.Internal { @@ -46,10 +45,6 @@ public EnumHasFlagTranslator(ISqlExpressionFactory sqlExpressionFactory) IReadOnlyList arguments, IDiagnosticsLogger logger) { - Check.NotNull(method, nameof(method)); - Check.NotNull(arguments, nameof(arguments)); - Check.NotNull(logger, nameof(logger)); - if (Equals(method, _methodInfo) && instance != null) { diff --git a/src/EFCore.Relational/Query/Internal/EqualsTranslator.cs b/src/EFCore.Relational/Query/Internal/EqualsTranslator.cs index 7f532d7cc66..de19cebebaa 100644 --- a/src/EFCore.Relational/Query/Internal/EqualsTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/EqualsTranslator.cs @@ -5,7 +5,6 @@ using System.Reflection; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.Internal { @@ -42,10 +41,6 @@ public EqualsTranslator(ISqlExpressionFactory sqlExpressionFactory) 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.Relational/Query/Internal/FromSqlParameterExpandingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/FromSqlParameterExpandingExpressionVisitor.cs index b8f64fad253..c19f8220a4a 100644 --- a/src/EFCore.Relational/Query/Internal/FromSqlParameterExpandingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/Internal/FromSqlParameterExpandingExpressionVisitor.cs @@ -45,8 +45,6 @@ private readonly IDictionary _visitedFromSqlExpre public FromSqlParameterExpandingExpressionVisitor( RelationalParameterBasedSqlProcessorDependencies dependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Dependencies = dependencies; _sqlExpressionFactory = dependencies.SqlExpressionFactory; @@ -73,9 +71,6 @@ public virtual SelectExpression Expand( IReadOnlyDictionary parameterValues, out bool canCache) { - Check.NotNull(selectExpression, nameof(selectExpression)); - Check.NotNull(parameterValues, nameof(parameterValues)); - _visitedFromSqlExpressions.Clear(); _parameterNameGenerator = _parameterNameGeneratorFactory.Create(); _parametersValues = parameterValues; diff --git a/src/EFCore.Relational/Query/Internal/FromSqlQueryRootExpression.cs b/src/EFCore.Relational/Query/Internal/FromSqlQueryRootExpression.cs index 0ece2729d16..a7551b57cdd 100644 --- a/src/EFCore.Relational/Query/Internal/FromSqlQueryRootExpression.cs +++ b/src/EFCore.Relational/Query/Internal/FromSqlQueryRootExpression.cs @@ -5,7 +5,6 @@ using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.Internal { @@ -30,9 +29,6 @@ public FromSqlQueryRootExpression( Expression argument) : base(queryProvider, entityType) { - Check.NotEmpty(sql, nameof(sql)); - Check.NotNull(argument, nameof(argument)); - Sql = sql; Argument = argument; } @@ -49,9 +45,6 @@ public FromSqlQueryRootExpression( Expression argument) : base(entityType) { - Check.NotEmpty(sql, nameof(sql)); - Check.NotNull(argument, nameof(argument)); - Sql = sql; Argument = argument; } @@ -116,8 +109,6 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// protected override void Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - base.Print(expressionPrinter); expressionPrinter.Append($".FromSql({Sql}, "); expressionPrinter.Visit(Argument); diff --git a/src/EFCore.Relational/Query/Internal/GetValueOrDefaultTranslator.cs b/src/EFCore.Relational/Query/Internal/GetValueOrDefaultTranslator.cs index f9ff22b36f2..80e71043f0c 100644 --- a/src/EFCore.Relational/Query/Internal/GetValueOrDefaultTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/GetValueOrDefaultTranslator.cs @@ -6,7 +6,6 @@ using System.Reflection; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.Internal { @@ -43,10 +42,6 @@ public GetValueOrDefaultTranslator(ISqlExpressionFactory sqlExpressionFactory) 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) && instance != null && method.ReturnType.IsNumeric()) diff --git a/src/EFCore.Relational/Query/Internal/LikeTranslator.cs b/src/EFCore.Relational/Query/Internal/LikeTranslator.cs index af648472ca4..4bb253cdd44 100644 --- a/src/EFCore.Relational/Query/Internal/LikeTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/LikeTranslator.cs @@ -6,7 +6,6 @@ using System.Reflection; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.Internal { @@ -51,10 +50,6 @@ public LikeTranslator(ISqlExpressionFactory sqlExpressionFactory) IReadOnlyList arguments, IDiagnosticsLogger logger) { - Check.NotNull(method, nameof(method)); - Check.NotNull(arguments, nameof(arguments)); - Check.NotNull(logger, nameof(logger)); - if (Equals(method, _methodInfo)) { return _sqlExpressionFactory.Like(arguments[1], arguments[2]); diff --git a/src/EFCore.Relational/Query/Internal/NullableMemberTranslator.cs b/src/EFCore.Relational/Query/Internal/NullableMemberTranslator.cs index 43d519a86d5..1773692efb6 100644 --- a/src/EFCore.Relational/Query/Internal/NullableMemberTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/NullableMemberTranslator.cs @@ -5,7 +5,6 @@ using System.Reflection; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.Internal { @@ -42,10 +41,6 @@ public NullableMemberTranslator(ISqlExpressionFactory sqlExpressionFactory) Type returnType, IDiagnosticsLogger logger) { - Check.NotNull(member, nameof(member)); - Check.NotNull(returnType, nameof(returnType)); - Check.NotNull(logger, nameof(logger)); - if (member.DeclaringType?.IsNullableValueType() == true && instance != null) { diff --git a/src/EFCore.Relational/Query/Internal/QuerySqlGeneratorFactory.cs b/src/EFCore.Relational/Query/Internal/QuerySqlGeneratorFactory.cs index b5b881d2407..7bde28d9883 100644 --- a/src/EFCore.Relational/Query/Internal/QuerySqlGeneratorFactory.cs +++ b/src/EFCore.Relational/Query/Internal/QuerySqlGeneratorFactory.cs @@ -1,8 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.EntityFrameworkCore.Utilities; - namespace Microsoft.EntityFrameworkCore.Query.Internal { /// @@ -21,8 +19,6 @@ public class QuerySqlGeneratorFactory : IQuerySqlGeneratorFactory /// public QuerySqlGeneratorFactory(QuerySqlGeneratorDependencies dependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Dependencies = dependencies; } diff --git a/src/EFCore.Relational/Query/Internal/RandomTranslator.cs b/src/EFCore.Relational/Query/Internal/RandomTranslator.cs index 9487c1a5af0..798a2b2b2cb 100644 --- a/src/EFCore.Relational/Query/Internal/RandomTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/RandomTranslator.cs @@ -6,7 +6,6 @@ using System.Reflection; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.Internal { @@ -46,10 +45,6 @@ public RandomTranslator(ISqlExpressionFactory sqlExpressionFactory) 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( "RAND", diff --git a/src/EFCore.Relational/Query/Internal/RelationalParameterBasedSqlProcessorFactory.cs b/src/EFCore.Relational/Query/Internal/RelationalParameterBasedSqlProcessorFactory.cs index 882f7ac4053..cf0d3820eac 100644 --- a/src/EFCore.Relational/Query/Internal/RelationalParameterBasedSqlProcessorFactory.cs +++ b/src/EFCore.Relational/Query/Internal/RelationalParameterBasedSqlProcessorFactory.cs @@ -1,8 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.EntityFrameworkCore.Utilities; - namespace Microsoft.EntityFrameworkCore.Query.Internal { /// @@ -22,8 +20,6 @@ public class RelationalParameterBasedSqlProcessorFactory : IRelationalParameterB public RelationalParameterBasedSqlProcessorFactory( RelationalParameterBasedSqlProcessorDependencies dependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Dependencies = dependencies; } diff --git a/src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs index b3071f67dc7..4510cf0b30d 100644 --- a/src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs @@ -277,8 +277,6 @@ protected override Expression VisitConditional(ConditionalExpression conditional /// protected override Expression VisitExtension(Expression extensionExpression) { - Check.NotNull(extensionExpression, nameof(extensionExpression)); - switch (extensionExpression) { case EntityShaperExpression entityShaperExpression: @@ -429,8 +427,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) { @@ -505,8 +501,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.Relational/Query/Internal/RelationalQueryCompilationContextFactory.cs b/src/EFCore.Relational/Query/Internal/RelationalQueryCompilationContextFactory.cs index 42f9c17a36e..3d3a74321f4 100644 --- a/src/EFCore.Relational/Query/Internal/RelationalQueryCompilationContextFactory.cs +++ b/src/EFCore.Relational/Query/Internal/RelationalQueryCompilationContextFactory.cs @@ -1,8 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.EntityFrameworkCore.Utilities; - namespace Microsoft.EntityFrameworkCore.Query.Internal { /// @@ -23,9 +21,6 @@ public RelationalQueryCompilationContextFactory( QueryCompilationContextDependencies dependencies, RelationalQueryCompilationContextDependencies relationalDependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - Dependencies = dependencies; RelationalDependencies = relationalDependencies; } diff --git a/src/EFCore.Relational/Query/Internal/RelationalQueryContextFactory.cs b/src/EFCore.Relational/Query/Internal/RelationalQueryContextFactory.cs index 84e3bcfbe21..d4360d817f3 100644 --- a/src/EFCore.Relational/Query/Internal/RelationalQueryContextFactory.cs +++ b/src/EFCore.Relational/Query/Internal/RelationalQueryContextFactory.cs @@ -1,7 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. - namespace Microsoft.EntityFrameworkCore.Query.Internal { /// diff --git a/src/EFCore.Relational/Query/Internal/RelationalQueryMetadataExtractingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/RelationalQueryMetadataExtractingExpressionVisitor.cs index 5e4d11f0b58..f04b16fdb54 100644 --- a/src/EFCore.Relational/Query/Internal/RelationalQueryMetadataExtractingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/Internal/RelationalQueryMetadataExtractingExpressionVisitor.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Linq.Expressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.Internal { @@ -25,8 +24,6 @@ public class RelationalQueryMetadataExtractingExpressionVisitor : ExpressionVisi public RelationalQueryMetadataExtractingExpressionVisitor( RelationalQueryCompilationContext relationalQueryCompilationContext) { - Check.NotNull(relationalQueryCompilationContext, nameof(relationalQueryCompilationContext)); - _relationalQueryCompilationContext = relationalQueryCompilationContext; } diff --git a/src/EFCore.Relational/Query/Internal/RelationalQueryTranslationPostprocessorFactory.cs b/src/EFCore.Relational/Query/Internal/RelationalQueryTranslationPostprocessorFactory.cs index 3bd7d81d853..d4ffeeb2b64 100644 --- a/src/EFCore.Relational/Query/Internal/RelationalQueryTranslationPostprocessorFactory.cs +++ b/src/EFCore.Relational/Query/Internal/RelationalQueryTranslationPostprocessorFactory.cs @@ -1,8 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.EntityFrameworkCore.Utilities; - namespace Microsoft.EntityFrameworkCore.Query.Internal { /// @@ -44,13 +42,9 @@ public RelationalQueryTranslationPostprocessorFactory( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual QueryTranslationPostprocessor Create(QueryCompilationContext queryCompilationContext) - { - Check.NotNull(queryCompilationContext, nameof(queryCompilationContext)); - - return new RelationalQueryTranslationPostprocessor( + => new RelationalQueryTranslationPostprocessor( Dependencies, RelationalDependencies, queryCompilationContext); - } } } diff --git a/src/EFCore.Relational/Query/Internal/RelationalQueryTranslationPreprocessorFactory.cs b/src/EFCore.Relational/Query/Internal/RelationalQueryTranslationPreprocessorFactory.cs index 305913b944d..004f09dd3c0 100644 --- a/src/EFCore.Relational/Query/Internal/RelationalQueryTranslationPreprocessorFactory.cs +++ b/src/EFCore.Relational/Query/Internal/RelationalQueryTranslationPreprocessorFactory.cs @@ -1,8 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.EntityFrameworkCore.Utilities; - namespace Microsoft.EntityFrameworkCore.Query.Internal { /// @@ -44,10 +42,6 @@ public RelationalQueryTranslationPreprocessorFactory( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual QueryTranslationPreprocessor Create(QueryCompilationContext queryCompilationContext) - { - Check.NotNull(queryCompilationContext, nameof(queryCompilationContext)); - - return new RelationalQueryTranslationPreprocessor(Dependencies, RelationalDependencies, queryCompilationContext); - } + => new RelationalQueryTranslationPreprocessor(Dependencies, RelationalDependencies, queryCompilationContext); } } diff --git a/src/EFCore.Relational/Query/Internal/RelationalQueryableMethodTranslatingExpressionVisitorFactory.cs b/src/EFCore.Relational/Query/Internal/RelationalQueryableMethodTranslatingExpressionVisitorFactory.cs index b3cbaed79f4..eac8a000ed7 100644 --- a/src/EFCore.Relational/Query/Internal/RelationalQueryableMethodTranslatingExpressionVisitorFactory.cs +++ b/src/EFCore.Relational/Query/Internal/RelationalQueryableMethodTranslatingExpressionVisitorFactory.cs @@ -1,8 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.EntityFrameworkCore.Utilities; - namespace Microsoft.EntityFrameworkCore.Query.Internal { /// @@ -44,13 +42,9 @@ public RelationalQueryableMethodTranslatingExpressionVisitorFactory( /// 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 RelationalQueryableMethodTranslatingExpressionVisitor( + => new RelationalQueryableMethodTranslatingExpressionVisitor( Dependencies, RelationalDependencies, queryCompilationContext); - } } } diff --git a/src/EFCore.Relational/Query/Internal/RelationalShapedQueryCompilingExpressionVisitorFactory.cs b/src/EFCore.Relational/Query/Internal/RelationalShapedQueryCompilingExpressionVisitorFactory.cs index 8fa613a4587..157eef8820c 100644 --- a/src/EFCore.Relational/Query/Internal/RelationalShapedQueryCompilingExpressionVisitorFactory.cs +++ b/src/EFCore.Relational/Query/Internal/RelationalShapedQueryCompilingExpressionVisitorFactory.cs @@ -1,8 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.EntityFrameworkCore.Utilities; - namespace Microsoft.EntityFrameworkCore.Query.Internal { /// @@ -23,9 +21,6 @@ public RelationalShapedQueryCompilingExpressionVisitorFactory( ShapedQueryCompilingExpressionVisitorDependencies dependencies, RelationalShapedQueryCompilingExpressionVisitorDependencies relationalDependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - Dependencies = dependencies; RelationalDependencies = relationalDependencies; } @@ -47,13 +42,9 @@ public RelationalShapedQueryCompilingExpressionVisitorFactory( /// 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 RelationalShapedQueryCompilingExpressionVisitor( + => new RelationalShapedQueryCompilingExpressionVisitor( Dependencies, RelationalDependencies, queryCompilationContext); - } } } diff --git a/src/EFCore.Relational/Query/Internal/RelationalValueConverterCompensatingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/RelationalValueConverterCompensatingExpressionVisitor.cs index 1c678acd697..230bf696f96 100644 --- a/src/EFCore.Relational/Query/Internal/RelationalValueConverterCompensatingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/Internal/RelationalValueConverterCompensatingExpressionVisitor.cs @@ -5,7 +5,6 @@ using System.Diagnostics.CodeAnalysis; using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.Internal { @@ -38,10 +37,7 @@ public RelationalValueConverterCompensatingExpressionVisitor( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// protected override Expression VisitExtension(Expression extensionExpression) - { - Check.NotNull(extensionExpression, nameof(extensionExpression)); - - return extensionExpression switch + => extensionExpression switch { ShapedQueryExpression shapedQueryExpression => VisitShapedQueryExpression(shapedQueryExpression), CaseExpression caseExpression => VisitCase(caseExpression), @@ -50,7 +46,6 @@ protected override Expression VisitExtension(Expression extensionExpression) LeftJoinExpression leftJoinExpression => VisitLeftJoin(leftJoinExpression), _ => base.VisitExtension(extensionExpression), }; - } private Expression VisitShapedQueryExpression(ShapedQueryExpression shapedQueryExpression) { diff --git a/src/EFCore.Relational/Query/Internal/SelectExpressionProjectionApplyingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/SelectExpressionProjectionApplyingExpressionVisitor.cs index 2ee66a3e82d..30b34bcc5e8 100644 --- a/src/EFCore.Relational/Query/Internal/SelectExpressionProjectionApplyingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/Internal/SelectExpressionProjectionApplyingExpressionVisitor.cs @@ -3,7 +3,6 @@ using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.Internal { @@ -35,16 +34,12 @@ public SelectExpressionProjectionApplyingExpressionVisitor(QuerySplittingBehavio /// doing so can result in application failures when updating to a new Entity Framework Core release. /// protected override Expression VisitExtension(Expression extensionExpression) - { - Check.NotNull(extensionExpression, nameof(extensionExpression)); - - return extensionExpression is ShapedQueryExpression shapedQueryExpression + => extensionExpression is ShapedQueryExpression shapedQueryExpression && shapedQueryExpression.QueryExpression is SelectExpression selectExpression ? shapedQueryExpression.Update( selectExpression, selectExpression.ApplyProjection( shapedQueryExpression.ShaperExpression, shapedQueryExpression.ResultCardinality, _querySplittingBehavior)) : base.VisitExtension(extensionExpression); - } } } diff --git a/src/EFCore.Relational/Query/Internal/SqlExpressionSimplifyingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/SqlExpressionSimplifyingExpressionVisitor.cs index a282417e87b..5ef8545c603 100644 --- a/src/EFCore.Relational/Query/Internal/SqlExpressionSimplifyingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/Internal/SqlExpressionSimplifyingExpressionVisitor.cs @@ -9,7 +9,6 @@ using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.Internal { @@ -44,8 +43,6 @@ public SqlExpressionSimplifyingExpressionVisitor(ISqlExpressionFactory sqlExpres /// protected override Expression VisitExtension(Expression extensionExpression) { - Check.NotNull(extensionExpression, nameof(extensionExpression)); - if (extensionExpression is ShapedQueryExpression shapedQueryExpression) { return shapedQueryExpression.Update(Visit(shapedQueryExpression.QueryExpression), shapedQueryExpression.ShaperExpression); diff --git a/src/EFCore.Relational/Query/Internal/StringMethodTranslator.cs b/src/EFCore.Relational/Query/Internal/StringMethodTranslator.cs index ed222a026bf..5cef2218411 100644 --- a/src/EFCore.Relational/Query/Internal/StringMethodTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/StringMethodTranslator.cs @@ -6,7 +6,6 @@ using System.Reflection; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.Internal { @@ -56,10 +55,6 @@ public StringMethodTranslator(ISqlExpressionFactory sqlExpressionFactory) IReadOnlyList arguments, IDiagnosticsLogger logger) { - Check.NotNull(method, nameof(method)); - Check.NotNull(arguments, nameof(arguments)); - Check.NotNull(logger, nameof(logger)); - if (Equals(method, _isNullOrEmptyMethodInfo)) { var argument = arguments[0]; diff --git a/src/EFCore.Relational/Query/Internal/TableValuedFunctionQueryRootExpression.cs b/src/EFCore.Relational/Query/Internal/TableValuedFunctionQueryRootExpression.cs index c066e1d726b..f05dac69e4e 100644 --- a/src/EFCore.Relational/Query/Internal/TableValuedFunctionQueryRootExpression.cs +++ b/src/EFCore.Relational/Query/Internal/TableValuedFunctionQueryRootExpression.cs @@ -7,7 +7,6 @@ using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.Internal { @@ -32,9 +31,6 @@ public TableValuedFunctionQueryRootExpression( IReadOnlyCollection arguments) : base(entityType) { - Check.NotNull(function, nameof(function)); - Check.NotNull(arguments, nameof(arguments)); - Function = function; Arguments = arguments; } @@ -97,8 +93,6 @@ public override QueryRootExpression UpdateEntityType(IEntityType entityType) /// protected override void Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - expressionPrinter.Append(Function.Name); expressionPrinter.Append("("); expressionPrinter.VisitCollection(Arguments); diff --git a/src/EFCore.Relational/Query/Internal/TableValuedFunctionToQueryRootConvertingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/TableValuedFunctionToQueryRootConvertingExpressionVisitor.cs index 74375bdf5e3..2cc33273580 100644 --- a/src/EFCore.Relational/Query/Internal/TableValuedFunctionToQueryRootConvertingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/Internal/TableValuedFunctionToQueryRootConvertingExpressionVisitor.cs @@ -5,7 +5,6 @@ using System.Linq; using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.Internal { @@ -27,8 +26,6 @@ public class TableValuedFunctionToQueryRootConvertingExpressionVisitor : Express /// public TableValuedFunctionToQueryRootConvertingExpressionVisitor(IModel model) { - Check.NotNull(model, nameof(model)); - _model = model; } diff --git a/src/EFCore.Relational/Query/QuerySqlGenerator.cs b/src/EFCore.Relational/Query/QuerySqlGenerator.cs index 2824c0337f0..d05ffa71cb3 100644 --- a/src/EFCore.Relational/Query/QuerySqlGenerator.cs +++ b/src/EFCore.Relational/Query/QuerySqlGenerator.cs @@ -9,7 +9,6 @@ using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage.Internal; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query { @@ -53,8 +52,6 @@ public class QuerySqlGenerator : SqlExpressionVisitor /// Parameter object containing dependencies for this class. public QuerySqlGenerator(QuerySqlGeneratorDependencies dependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Dependencies = dependencies; _relationalCommandBuilderFactory = dependencies.RelationalCommandBuilderFactory; @@ -74,8 +71,6 @@ public QuerySqlGenerator(QuerySqlGeneratorDependencies dependencies) /// A relational command with a SQL represented by the select expression. public virtual IRelationalCommand GetCommand(SelectExpression selectExpression) { - Check.NotNull(selectExpression, nameof(selectExpression)); - _relationalCommandBuilder = _relationalCommandBuilderFactory.Create(); GenerateTagsHeaderComment(selectExpression); @@ -109,8 +104,6 @@ protected virtual IRelationalCommandBuilder Sql /// A select expression to generate tags for. protected virtual void GenerateTagsHeaderComment(SelectExpression selectExpression) { - Check.NotNull(selectExpression, nameof(selectExpression)); - if (selectExpression.Tags.Count > 0) { foreach (var tag in selectExpression.Tags) @@ -125,8 +118,6 @@ protected virtual void GenerateTagsHeaderComment(SelectExpression selectExpressi /// protected override Expression VisitSqlFragment(SqlFragmentExpression sqlFragmentExpression) { - Check.NotNull(sqlFragmentExpression, nameof(sqlFragmentExpression)); - _relationalCommandBuilder.Append(sqlFragmentExpression.Sql); return sqlFragmentExpression; @@ -153,8 +144,6 @@ private bool IsNonComposedSetOperation(SelectExpression selectExpression) /// protected override Expression VisitSelect(SelectExpression selectExpression) { - Check.NotNull(selectExpression, nameof(selectExpression)); - if (IsNonComposedSetOperation(selectExpression)) { // Naked set operation @@ -247,8 +236,6 @@ protected virtual void GeneratePseudoFromClause() /// protected override Expression VisitProjection(ProjectionExpression projectionExpression) { - Check.NotNull(projectionExpression, nameof(projectionExpression)); - Visit(projectionExpression.Expression); if (projectionExpression.Alias != string.Empty @@ -265,8 +252,6 @@ protected override Expression VisitProjection(ProjectionExpression projectionExp /// protected override Expression VisitSqlFunction(SqlFunctionExpression sqlFunctionExpression) { - Check.NotNull(sqlFunctionExpression, nameof(sqlFunctionExpression)); - if (sqlFunctionExpression.IsBuiltIn) { if (sqlFunctionExpression.Instance != null) @@ -303,8 +288,6 @@ protected override Expression VisitSqlFunction(SqlFunctionExpression sqlFunction /// protected override Expression VisitTableValuedFunction(TableValuedFunctionExpression tableValuedFunctionExpression) { - Check.NotNull(tableValuedFunctionExpression, nameof(tableValuedFunctionExpression)); - if (!string.IsNullOrEmpty(tableValuedFunctionExpression.StoreFunction.Schema)) { _relationalCommandBuilder @@ -333,8 +316,6 @@ protected override Expression VisitTableValuedFunction(TableValuedFunctionExpres /// protected override Expression VisitColumn(ColumnExpression columnExpression) { - Check.NotNull(columnExpression, nameof(columnExpression)); - _relationalCommandBuilder .Append(_sqlGenerationHelper.DelimitIdentifier(columnExpression.TableAlias)) .Append(".") @@ -346,8 +327,6 @@ protected override Expression VisitColumn(ColumnExpression columnExpression) /// protected override Expression VisitTable(TableExpression tableExpression) { - Check.NotNull(tableExpression, nameof(tableExpression)); - _relationalCommandBuilder .Append(_sqlGenerationHelper.DelimitIdentifier(tableExpression.Name, tableExpression.Schema)) .Append(AliasSeparator) @@ -418,8 +397,6 @@ fromSqlExpression.Arguments is ConstantExpression constantExpression /// protected override Expression VisitFromSql(FromSqlExpression fromSqlExpression) { - Check.NotNull(fromSqlExpression, nameof(fromSqlExpression)); - _relationalCommandBuilder.AppendLine("("); CheckComposableSql(fromSqlExpression.Sql); @@ -507,8 +484,6 @@ protected virtual void CheckComposableSqlTrimmed(ReadOnlySpan sql) /// protected override Expression VisitSqlBinary(SqlBinaryExpression sqlBinaryExpression) { - Check.NotNull(sqlBinaryExpression, nameof(sqlBinaryExpression)); - var requiresBrackets = RequiresBrackets(sqlBinaryExpression.Left); if (requiresBrackets) @@ -553,8 +528,6 @@ private static bool RequiresBrackets(SqlExpression expression) /// protected override Expression VisitSqlConstant(SqlConstantExpression sqlConstantExpression) { - Check.NotNull(sqlConstantExpression, nameof(sqlConstantExpression)); - _relationalCommandBuilder .Append(sqlConstantExpression.TypeMapping!.GenerateSqlLiteral(sqlConstantExpression.Value)); @@ -564,8 +537,6 @@ protected override Expression VisitSqlConstant(SqlConstantExpression sqlConstant /// protected override Expression VisitSqlParameter(SqlParameterExpression sqlParameterExpression) { - Check.NotNull(sqlParameterExpression, nameof(sqlParameterExpression)); - var parameterNameInCommand = _sqlGenerationHelper.GenerateParameterName(sqlParameterExpression.Name); if (_relationalCommandBuilder.Parameters @@ -587,8 +558,6 @@ protected override Expression VisitSqlParameter(SqlParameterExpression sqlParame /// protected override Expression VisitOrdering(OrderingExpression orderingExpression) { - Check.NotNull(orderingExpression, nameof(orderingExpression)); - if (orderingExpression.Expression is SqlConstantExpression || orderingExpression.Expression is SqlParameterExpression) { @@ -610,8 +579,6 @@ protected override Expression VisitOrdering(OrderingExpression orderingExpressio /// protected override Expression VisitLike(LikeExpression likeExpression) { - Check.NotNull(likeExpression, nameof(likeExpression)); - Visit(likeExpression.Match); _relationalCommandBuilder.Append(" LIKE "); Visit(likeExpression.Pattern); @@ -628,8 +595,6 @@ protected override Expression VisitLike(LikeExpression likeExpression) /// protected override Expression VisitCollate(CollateExpression collateExpresion) { - Check.NotNull(collateExpresion, nameof(collateExpresion)); - Visit(collateExpresion.Operand); _relationalCommandBuilder @@ -642,8 +607,6 @@ protected override Expression VisitCollate(CollateExpression collateExpresion) /// protected override Expression VisitDistinct(DistinctExpression distinctExpression) { - Check.NotNull(distinctExpression, nameof(distinctExpression)); - _relationalCommandBuilder.Append("DISTINCT ("); Visit(distinctExpression.Operand); _relationalCommandBuilder.Append(")"); @@ -654,8 +617,6 @@ protected override Expression VisitDistinct(DistinctExpression distinctExpressio /// protected override Expression VisitCase(CaseExpression caseExpression) { - Check.NotNull(caseExpression, nameof(caseExpression)); - _relationalCommandBuilder.Append("CASE"); if (caseExpression.Operand != null) @@ -695,8 +656,6 @@ protected override Expression VisitCase(CaseExpression caseExpression) /// protected override Expression VisitSqlUnary(SqlUnaryExpression sqlUnaryExpression) { - Check.NotNull(sqlUnaryExpression, nameof(sqlUnaryExpression)); - switch (sqlUnaryExpression.OperatorType) { case ExpressionType.Convert: @@ -775,8 +734,6 @@ protected override Expression VisitSqlUnary(SqlUnaryExpression sqlUnaryExpressio /// protected override Expression VisitExists(ExistsExpression existsExpression) { - Check.NotNull(existsExpression, nameof(existsExpression)); - if (existsExpression.IsNegated) { _relationalCommandBuilder.Append("NOT "); @@ -797,8 +754,6 @@ protected override Expression VisitExists(ExistsExpression existsExpression) /// protected override Expression VisitIn(InExpression inExpression) { - Check.NotNull(inExpression, nameof(inExpression)); - if (inExpression.Values != null) { Visit(inExpression.Item); @@ -833,11 +788,7 @@ protected override Expression VisitIn(InExpression inExpression) /// A SQL binary operation. /// A string representation of the binary operator. protected virtual string GetOperator(SqlBinaryExpression binaryExpression) - { - Check.NotNull(binaryExpression, nameof(binaryExpression)); - - return _operatorMap[binaryExpression.OperatorType]; - } + => _operatorMap[binaryExpression.OperatorType]; /// /// Generates a TOP construct in the relational command @@ -845,7 +796,6 @@ protected virtual string GetOperator(SqlBinaryExpression binaryExpression) /// A select expression to use. protected virtual void GenerateTop(SelectExpression selectExpression) { - Check.NotNull(selectExpression, nameof(selectExpression)); } /// @@ -854,8 +804,6 @@ protected virtual void GenerateTop(SelectExpression selectExpression) /// A select expression to use. protected virtual void GenerateOrderings(SelectExpression selectExpression) { - Check.NotNull(selectExpression, nameof(selectExpression)); - if (selectExpression.Orderings.Any()) { var orderings = selectExpression.Orderings.ToList(); @@ -882,8 +830,6 @@ protected virtual void GenerateOrderings(SelectExpression selectExpression) /// A select expression to use. protected virtual void GenerateLimitOffset(SelectExpression selectExpression) { - Check.NotNull(selectExpression, nameof(selectExpression)); - if (selectExpression.Offset != null) { _relationalCommandBuilder.AppendLine() @@ -934,8 +880,6 @@ private void GenerateList( /// protected override Expression VisitCrossJoin(CrossJoinExpression crossJoinExpression) { - Check.NotNull(crossJoinExpression, nameof(crossJoinExpression)); - _relationalCommandBuilder.Append("CROSS JOIN "); Visit(crossJoinExpression.Table); @@ -945,8 +889,6 @@ protected override Expression VisitCrossJoin(CrossJoinExpression crossJoinExpres /// protected override Expression VisitCrossApply(CrossApplyExpression crossApplyExpression) { - Check.NotNull(crossApplyExpression, nameof(crossApplyExpression)); - _relationalCommandBuilder.Append("CROSS APPLY "); Visit(crossApplyExpression.Table); @@ -956,8 +898,6 @@ protected override Expression VisitCrossApply(CrossApplyExpression crossApplyExp /// protected override Expression VisitOuterApply(OuterApplyExpression outerApplyExpression) { - Check.NotNull(outerApplyExpression, nameof(outerApplyExpression)); - _relationalCommandBuilder.Append("OUTER APPLY "); Visit(outerApplyExpression.Table); @@ -967,8 +907,6 @@ protected override Expression VisitOuterApply(OuterApplyExpression outerApplyExp /// protected override Expression VisitInnerJoin(InnerJoinExpression innerJoinExpression) { - Check.NotNull(innerJoinExpression, nameof(innerJoinExpression)); - _relationalCommandBuilder.Append("INNER JOIN "); Visit(innerJoinExpression.Table); _relationalCommandBuilder.Append(" ON "); @@ -980,8 +918,6 @@ protected override Expression VisitInnerJoin(InnerJoinExpression innerJoinExpres /// protected override Expression VisitLeftJoin(LeftJoinExpression leftJoinExpression) { - Check.NotNull(leftJoinExpression, nameof(leftJoinExpression)); - _relationalCommandBuilder.Append("LEFT JOIN "); Visit(leftJoinExpression.Table); _relationalCommandBuilder.Append(" ON "); @@ -993,8 +929,6 @@ protected override Expression VisitLeftJoin(LeftJoinExpression leftJoinExpressio /// protected override Expression VisitScalarSubquery(ScalarSubqueryExpression scalarSubqueryExpression) { - Check.NotNull(scalarSubqueryExpression, nameof(scalarSubqueryExpression)); - _relationalCommandBuilder.AppendLine("("); using (_relationalCommandBuilder.Indent()) { @@ -1009,8 +943,6 @@ protected override Expression VisitScalarSubquery(ScalarSubqueryExpression scala /// protected override Expression VisitRowNumber(RowNumberExpression rowNumberExpression) { - Check.NotNull(rowNumberExpression, nameof(rowNumberExpression)); - _relationalCommandBuilder.Append("ROW_NUMBER() OVER("); if (rowNumberExpression.Partitions.Any()) { @@ -1032,8 +964,6 @@ protected override Expression VisitRowNumber(RowNumberExpression rowNumberExpres /// A set operation to print. protected virtual void GenerateSetOperation(SetOperationBase setOperation) { - Check.NotNull(setOperation, nameof(setOperation)); - GenerateSetOperationOperand(setOperation, setOperation.Source1); _relationalCommandBuilder .AppendLine() @@ -1058,9 +988,6 @@ static string GetSetOperation(SetOperationBase operation) /// A set operation operand to print. protected virtual void GenerateSetOperationOperand(SetOperationBase setOperation, SelectExpression operand) { - Check.NotNull(setOperation, nameof(setOperation)); - Check.NotNull(operand, nameof(operand)); - // INTERSECT has higher precedence over UNION and EXCEPT, but otherwise evaluation is left-to-right. // To preserve meaning, add parentheses whenever a set operation is nested within a different set operation. if (IsNonComposedSetOperation(operand) @@ -1097,8 +1024,6 @@ private void GenerateSetOperationHelper(SetOperationBase setOperation) /// protected override Expression VisitExcept(ExceptExpression exceptExpression) { - Check.NotNull(exceptExpression, nameof(exceptExpression)); - GenerateSetOperationHelper(exceptExpression); return exceptExpression; @@ -1107,8 +1032,6 @@ protected override Expression VisitExcept(ExceptExpression exceptExpression) /// protected override Expression VisitIntersect(IntersectExpression intersectExpression) { - Check.NotNull(intersectExpression, nameof(intersectExpression)); - GenerateSetOperationHelper(intersectExpression); return intersectExpression; @@ -1117,8 +1040,6 @@ protected override Expression VisitIntersect(IntersectExpression intersectExpres /// protected override Expression VisitUnion(UnionExpression unionExpression) { - Check.NotNull(unionExpression, nameof(unionExpression)); - GenerateSetOperationHelper(unionExpression); return unionExpression; diff --git a/src/EFCore.Relational/Query/QuerySqlGeneratorDependencies.cs b/src/EFCore.Relational/Query/QuerySqlGeneratorDependencies.cs index 4aae4a41836..3464be2132b 100644 --- a/src/EFCore.Relational/Query/QuerySqlGeneratorDependencies.cs +++ b/src/EFCore.Relational/Query/QuerySqlGeneratorDependencies.cs @@ -3,7 +3,6 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Query @@ -53,9 +52,6 @@ public QuerySqlGeneratorDependencies( IRelationalCommandBuilderFactory relationalCommandBuilderFactory, ISqlGenerationHelper sqlGenerationHelper) { - Check.NotNull(relationalCommandBuilderFactory, nameof(relationalCommandBuilderFactory)); - Check.NotNull(sqlGenerationHelper, nameof(sqlGenerationHelper)); - RelationalCommandBuilderFactory = relationalCommandBuilderFactory; SqlGenerationHelper = sqlGenerationHelper; } diff --git a/src/EFCore.Relational/Query/RelationalCollectionShaperExpression.cs b/src/EFCore.Relational/Query/RelationalCollectionShaperExpression.cs index f8b64f1dda3..6e89996cc97 100644 --- a/src/EFCore.Relational/Query/RelationalCollectionShaperExpression.cs +++ b/src/EFCore.Relational/Query/RelationalCollectionShaperExpression.cs @@ -6,7 +6,6 @@ using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.ChangeTracking; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query { @@ -45,12 +44,6 @@ public RelationalCollectionShaperExpression( INavigationBase? navigation, Type elementType) { - Check.NotNull(parentIdentifier, nameof(parentIdentifier)); - Check.NotNull(outerIdentifier, nameof(outerIdentifier)); - Check.NotNull(selfIdentifier, nameof(selfIdentifier)); - Check.NotNull(innerShaper, nameof(innerShaper)); - Check.NotNull(elementType, nameof(elementType)); - ParentIdentifier = parentIdentifier; OuterIdentifier = outerIdentifier; SelfIdentifier = selfIdentifier; @@ -118,8 +111,6 @@ public sealed override ExpressionType NodeType /// protected override Expression VisitChildren(ExpressionVisitor visitor) { - Check.NotNull(visitor, nameof(visitor)); - var parentIdentifier = visitor.Visit(ParentIdentifier); var outerIdentifier = visitor.Visit(OuterIdentifier); var selfIdentifier = visitor.Visit(SelfIdentifier); @@ -142,13 +133,7 @@ public virtual RelationalCollectionShaperExpression Update( Expression outerIdentifier, Expression selfIdentifier, Expression innerShaper) - { - Check.NotNull(parentIdentifier, nameof(parentIdentifier)); - Check.NotNull(outerIdentifier, nameof(outerIdentifier)); - Check.NotNull(selfIdentifier, nameof(selfIdentifier)); - Check.NotNull(innerShaper, nameof(innerShaper)); - - return parentIdentifier != ParentIdentifier + => parentIdentifier != ParentIdentifier || outerIdentifier != OuterIdentifier || selfIdentifier != SelfIdentifier || innerShaper != InnerShaper @@ -157,13 +142,10 @@ public virtual RelationalCollectionShaperExpression Update( ParentIdentifierValueComparers, OuterIdentifierValueComparers, SelfIdentifierValueComparers, innerShaper, Navigation, ElementType) : this; - } /// void IPrintableExpression.Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - expressionPrinter.AppendLine("RelationalCollectionShaper:"); using (expressionPrinter.Indent()) { diff --git a/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGenerator.cs b/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGenerator.cs index 359ca8f8143..e445204c626 100644 --- a/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGenerator.cs +++ b/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGenerator.cs @@ -5,7 +5,6 @@ using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Query @@ -38,8 +37,6 @@ public RelationalCompiledQueryCacheKeyGenerator( RelationalCompiledQueryCacheKeyGeneratorDependencies relationalDependencies) : base(dependencies) { - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - RelationalDependencies = relationalDependencies; } diff --git a/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGeneratorDependencies.cs b/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGeneratorDependencies.cs index 01b6e49256c..e8e965b5ebd 100644 --- a/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGeneratorDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGeneratorDependencies.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Query @@ -51,8 +50,6 @@ public sealed record RelationalCompiledQueryCacheKeyGeneratorDependencies [EntityFrameworkInternal] public RelationalCompiledQueryCacheKeyGeneratorDependencies(IDbContextOptions contextOptions) { - Check.NotNull(contextOptions, nameof(contextOptions)); - ContextOptions = contextOptions; } diff --git a/src/EFCore.Relational/Query/RelationalEntityShaperExpression.cs b/src/EFCore.Relational/Query/RelationalEntityShaperExpression.cs index 37a4774d1c0..aedac326052 100644 --- a/src/EFCore.Relational/Query/RelationalEntityShaperExpression.cs +++ b/src/EFCore.Relational/Query/RelationalEntityShaperExpression.cs @@ -9,7 +9,6 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query { @@ -58,8 +57,6 @@ protected RelationalEntityShaperExpression( /// protected override LambdaExpression GenerateMaterializationCondition(IEntityType entityType, bool nullable) { - Check.NotNull(entityType, nameof(EntityType)); - LambdaExpression baseCondition; if (entityType.FindDiscriminatorProperty() == null && entityType.GetDirectlyDerivedTypes().Any()) @@ -146,31 +143,21 @@ protected override LambdaExpression GenerateMaterializationCondition(IEntityType /// public override EntityShaperExpression WithEntityType(IEntityType entityType) - { - Check.NotNull(entityType, nameof(entityType)); - - return entityType != EntityType + => entityType != EntityType ? new RelationalEntityShaperExpression(entityType, ValueBufferExpression, IsNullable) : this; - } /// public override EntityShaperExpression MakeNullable(bool nullable = true) - { - return IsNullable != nullable + => IsNullable != nullable // Marking nullable requires recomputation of Discriminator condition ? new RelationalEntityShaperExpression(EntityType, ValueBufferExpression, true) : this; - } /// public override EntityShaperExpression Update(Expression valueBufferExpression) - { - Check.NotNull(valueBufferExpression, nameof(valueBufferExpression)); - - return valueBufferExpression != ValueBufferExpression + => valueBufferExpression != ValueBufferExpression ? new RelationalEntityShaperExpression(EntityType, valueBufferExpression, IsNullable, MaterializationCondition) : this; - } } } diff --git a/src/EFCore.Relational/Query/RelationalEvaluatableExpressionFilter.cs b/src/EFCore.Relational/Query/RelationalEvaluatableExpressionFilter.cs index 5005dcb62b0..0b45bb7c08a 100644 --- a/src/EFCore.Relational/Query/RelationalEvaluatableExpressionFilter.cs +++ b/src/EFCore.Relational/Query/RelationalEvaluatableExpressionFilter.cs @@ -3,7 +3,6 @@ using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Query @@ -34,8 +33,6 @@ public RelationalEvaluatableExpressionFilter( RelationalEvaluatableExpressionFilterDependencies relationalDependencies) : base(dependencies) { - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - RelationalDependencies = relationalDependencies; } @@ -52,9 +49,6 @@ public RelationalEvaluatableExpressionFilter( /// if the expression can be evaluated; otherwise. public override bool IsEvaluatableExpression(Expression expression, IModel model) { - Check.NotNull(expression, nameof(expression)); - Check.NotNull(model, nameof(model)); - if (expression is MethodCallExpression methodCallExpression) { var method = methodCallExpression.Method; diff --git a/src/EFCore.Relational/Query/RelationalMemberTranslatorProvider.cs b/src/EFCore.Relational/Query/RelationalMemberTranslatorProvider.cs index b168dde5cde..996ce93c562 100644 --- a/src/EFCore.Relational/Query/RelationalMemberTranslatorProvider.cs +++ b/src/EFCore.Relational/Query/RelationalMemberTranslatorProvider.cs @@ -9,7 +9,6 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.Internal; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Query @@ -35,8 +34,6 @@ public class RelationalMemberTranslatorProvider : IMemberTranslatorProvider /// Parameter object containing dependencies for this class. public RelationalMemberTranslatorProvider(RelationalMemberTranslatorProviderDependencies dependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Dependencies = dependencies; _plugins.AddRange(dependencies.Plugins.SelectMany(p => p.Translators)); @@ -56,24 +53,14 @@ public RelationalMemberTranslatorProvider(RelationalMemberTranslatorProviderDepe 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) + => _plugins.Concat(_translators) .Select(t => t.Translate(instance, member, returnType, logger)).FirstOrDefault(t => t != null); - } /// /// Adds additional translators which will take priority over existing registered translators. /// /// Translators to add. protected virtual void AddTranslators(IEnumerable translators) - { - Check.NotNull(translators, nameof(translators)); - - _translators.InsertRange(0, translators); - } + => _translators.InsertRange(0, translators); } } diff --git a/src/EFCore.Relational/Query/RelationalMemberTranslatorProviderDependencies.cs b/src/EFCore.Relational/Query/RelationalMemberTranslatorProviderDependencies.cs index 47774e806ba..1e636dc060e 100644 --- a/src/EFCore.Relational/Query/RelationalMemberTranslatorProviderDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalMemberTranslatorProviderDependencies.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Query @@ -54,9 +53,6 @@ public RelationalMemberTranslatorProviderDependencies( ISqlExpressionFactory sqlExpressionFactory, IEnumerable plugins) { - Check.NotNull(sqlExpressionFactory, nameof(sqlExpressionFactory)); - Check.NotNull(plugins, nameof(plugins)); - SqlExpressionFactory = sqlExpressionFactory; Plugins = plugins; } diff --git a/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProvider.cs b/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProvider.cs index 336e0cb9b24..5f14ee773a3 100644 --- a/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProvider.cs +++ b/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProvider.cs @@ -10,7 +10,6 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Query.Internal; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Query @@ -37,8 +36,6 @@ public class RelationalMethodCallTranslatorProvider : IMethodCallTranslatorProvi /// Parameter object containing dependencies for this class. public RelationalMethodCallTranslatorProvider(RelationalMethodCallTranslatorProviderDependencies dependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Dependencies = dependencies; _plugins.AddRange(dependencies.Plugins.SelectMany(p => p.Translators)); @@ -75,11 +72,6 @@ public RelationalMethodCallTranslatorProvider(RelationalMethodCallTranslatorProv 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) { @@ -117,10 +109,6 @@ public RelationalMethodCallTranslatorProvider(RelationalMethodCallTranslatorProv /// /// Translators to add. protected virtual void AddTranslators(IEnumerable translators) - { - Check.NotNull(translators, nameof(translators)); - - _translators.InsertRange(0, translators); - } + => _translators.InsertRange(0, translators); } } diff --git a/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProviderDependencies.cs b/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProviderDependencies.cs index 6e1f2d7bc25..5f91cf45a38 100644 --- a/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProviderDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProviderDependencies.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Query @@ -56,10 +55,6 @@ public RelationalMethodCallTranslatorProviderDependencies( IEnumerable plugins, IRelationalTypeMappingSource typeMappingSource) { - Check.NotNull(sqlExpressionFactory, nameof(sqlExpressionFactory)); - Check.NotNull(plugins, nameof(plugins)); - Check.NotNull(typeMappingSource, nameof(typeMappingSource)); - SqlExpressionFactory = sqlExpressionFactory; Plugins = plugins; RelationalTypeMappingSource = typeMappingSource; diff --git a/src/EFCore.Relational/Query/RelationalParameterBasedSqlProcessor.cs b/src/EFCore.Relational/Query/RelationalParameterBasedSqlProcessor.cs index c512b52d605..648419bac09 100644 --- a/src/EFCore.Relational/Query/RelationalParameterBasedSqlProcessor.cs +++ b/src/EFCore.Relational/Query/RelationalParameterBasedSqlProcessor.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Query.Internal; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query { @@ -28,8 +27,6 @@ public RelationalParameterBasedSqlProcessor( RelationalParameterBasedSqlProcessorDependencies dependencies, bool useRelationalNulls) { - Check.NotNull(dependencies, nameof(dependencies)); - Dependencies = dependencies; UseRelationalNulls = useRelationalNulls; } @@ -56,9 +53,6 @@ public virtual SelectExpression Optimize( IReadOnlyDictionary parametersValues, out bool canCache) { - Check.NotNull(selectExpression, nameof(selectExpression)); - Check.NotNull(parametersValues, nameof(parametersValues)); - canCache = true; selectExpression = ProcessSqlNullability(selectExpression, parametersValues, out var sqlNullablityCanCache); canCache &= sqlNullablityCanCache; @@ -81,12 +75,7 @@ protected virtual SelectExpression ProcessSqlNullability( SelectExpression selectExpression, IReadOnlyDictionary parametersValues, out bool canCache) - { - Check.NotNull(selectExpression, nameof(selectExpression)); - Check.NotNull(parametersValues, nameof(parametersValues)); - - return new SqlNullabilityProcessor(Dependencies, UseRelationalNulls).Process(selectExpression, parametersValues, out canCache); - } + => new SqlNullabilityProcessor(Dependencies, UseRelationalNulls).Process(selectExpression, parametersValues, out canCache); /// /// Expands the parameters to inside the for given parameter values. @@ -99,11 +88,6 @@ protected virtual SelectExpression ExpandFromSqlParameter( SelectExpression selectExpression, IReadOnlyDictionary parametersValues, out bool canCache) - { - Check.NotNull(selectExpression, nameof(selectExpression)); - Check.NotNull(parametersValues, nameof(parametersValues)); - - return new FromSqlParameterExpandingExpressionVisitor(Dependencies).Expand(selectExpression, parametersValues, out canCache); - } + => new FromSqlParameterExpandingExpressionVisitor(Dependencies).Expand(selectExpression, parametersValues, out canCache); } } diff --git a/src/EFCore.Relational/Query/RelationalParameterBasedSqlProcessorDependencies.cs b/src/EFCore.Relational/Query/RelationalParameterBasedSqlProcessorDependencies.cs index dc0862a45c9..c32b26d8819 100644 --- a/src/EFCore.Relational/Query/RelationalParameterBasedSqlProcessorDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalParameterBasedSqlProcessorDependencies.cs @@ -4,7 +4,6 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Query.Internal; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Query @@ -56,10 +55,6 @@ public RelationalParameterBasedSqlProcessorDependencies( IRelationalTypeMappingSource typeMappingSource, IParameterNameGeneratorFactory parameterNameGeneratorFactory) { - Check.NotNull(sqlExpressionFactory, nameof(sqlExpressionFactory)); - Check.NotNull(typeMappingSource, nameof(typeMappingSource)); - Check.NotNull(parameterNameGeneratorFactory, nameof(parameterNameGeneratorFactory)); - SqlExpressionFactory = sqlExpressionFactory; TypeMappingSource = typeMappingSource; ParameterNameGeneratorFactory = parameterNameGeneratorFactory; diff --git a/src/EFCore.Relational/Query/RelationalQueryCompilationContext.cs b/src/EFCore.Relational/Query/RelationalQueryCompilationContext.cs index f5b0563c17d..c90f60285e2 100644 --- a/src/EFCore.Relational/Query/RelationalQueryCompilationContext.cs +++ b/src/EFCore.Relational/Query/RelationalQueryCompilationContext.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query { @@ -29,8 +28,6 @@ public RelationalQueryCompilationContext( bool async) : base(dependencies, async) { - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - RelationalDependencies = relationalDependencies; QuerySplittingBehavior = RelationalOptionsExtension.Extract(ContextOptions).QuerySplittingBehavior; } diff --git a/src/EFCore.Relational/Query/RelationalQueryContext.cs b/src/EFCore.Relational/Query/RelationalQueryContext.cs index d33aeb65a45..2f39245954c 100644 --- a/src/EFCore.Relational/Query/RelationalQueryContext.cs +++ b/src/EFCore.Relational/Query/RelationalQueryContext.cs @@ -4,7 +4,6 @@ using System.Data.Common; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query { @@ -35,8 +34,6 @@ public RelationalQueryContext( RelationalQueryContextDependencies relationalDependencies) : base(dependencies) { - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - RelationalDependencies = relationalDependencies; } diff --git a/src/EFCore.Relational/Query/RelationalQueryContextDependencies.cs b/src/EFCore.Relational/Query/RelationalQueryContextDependencies.cs index 83260b365d2..3b3eb2d9606 100644 --- a/src/EFCore.Relational/Query/RelationalQueryContextDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalQueryContextDependencies.cs @@ -4,7 +4,6 @@ using System.Data.Common; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Query @@ -55,9 +54,6 @@ public RelationalQueryContextDependencies( IRelationalConnection relationalConnection, IRelationalQueryStringFactory relationalQueryStringFactory) { - Check.NotNull(relationalConnection, nameof(relationalConnection)); - Check.NotNull(relationalQueryStringFactory, nameof(relationalQueryStringFactory)); - RelationalConnection = relationalConnection; RelationalQueryStringFactory = relationalQueryStringFactory; } diff --git a/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessor.cs b/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessor.cs index d8e62b26e34..7da4178db95 100644 --- a/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessor.cs +++ b/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessor.cs @@ -9,7 +9,6 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Query.Internal; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query { @@ -30,9 +29,6 @@ public RelationalQueryTranslationPostprocessor( QueryCompilationContext queryCompilationContext) : base(dependencies, queryCompilationContext) { - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - Check.NotNull(queryCompilationContext, nameof(queryCompilationContext)); - RelationalDependencies = relationalDependencies; _useRelationalNulls = RelationalOptionsExtension.Extract(queryCompilationContext.ContextOptions).UseRelationalNulls; } diff --git a/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessorDependencies.cs b/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessorDependencies.cs index 7980350f644..3993aea5f12 100644 --- a/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessorDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessorDependencies.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Query @@ -53,7 +52,6 @@ public RelationalQueryTranslationPostprocessorDependencies( ISqlExpressionFactory sqlExpressionFactory) { SqlExpressionFactory = sqlExpressionFactory; - Check.NotNull(sqlExpressionFactory, nameof(sqlExpressionFactory)); } /// diff --git a/src/EFCore.Relational/Query/RelationalQueryTranslationPreprocessor.cs b/src/EFCore.Relational/Query/RelationalQueryTranslationPreprocessor.cs index 6f1545c8127..eb780ccf64f 100644 --- a/src/EFCore.Relational/Query/RelationalQueryTranslationPreprocessor.cs +++ b/src/EFCore.Relational/Query/RelationalQueryTranslationPreprocessor.cs @@ -3,7 +3,6 @@ using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Query.Internal; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query { @@ -24,8 +23,6 @@ public RelationalQueryTranslationPreprocessor( QueryCompilationContext queryCompilationContext) : base(dependencies, queryCompilationContext) { - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - RelationalDependencies = relationalDependencies; _relationalQueryCompilationContext = (RelationalQueryCompilationContext)queryCompilationContext; } diff --git a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs index 15f37061080..5e510191eb1 100644 --- a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs @@ -40,10 +40,6 @@ public RelationalQueryableMethodTranslatingExpressionVisitor( QueryCompilationContext queryCompilationContext) : base(dependencies, queryCompilationContext, subquery: false) { - Check.NotNull(dependencies, nameof(dependencies)); - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - Check.NotNull(queryCompilationContext, nameof(queryCompilationContext)); - RelationalDependencies = relationalDependencies; var sqlExpressionFactory = relationalDependencies.SqlExpressionFactory; @@ -172,11 +168,7 @@ protected override QueryableMethodTranslatingExpressionVisitor CreateSubqueryVis /// protected override ShapedQueryExpression CreateShapedQueryExpression(IEntityType entityType) - { - Check.NotNull(entityType, nameof(entityType)); - - return CreateShapedQueryExpression(entityType, _sqlExpressionFactory.Select(entityType)); - } + => CreateShapedQueryExpression(entityType, _sqlExpressionFactory.Select(entityType)); private static ShapedQueryExpression CreateShapedQueryExpression(IEntityType entityType, SelectExpression selectExpression) => new( @@ -192,9 +184,6 @@ private static ShapedQueryExpression CreateShapedQueryExpression(IEntityType ent /// protected override ShapedQueryExpression? TranslateAll(ShapedQueryExpression source, LambdaExpression predicate) { - Check.NotNull(source, nameof(source)); - Check.NotNull(predicate, nameof(predicate)); - var translation = TranslateLambdaExpression(source, predicate); if (translation == null) { @@ -255,31 +244,18 @@ private static ShapedQueryExpression CreateShapedQueryExpression(IEntityType ent ShapedQueryExpression source, LambdaExpression? selector, Type resultType) - { - Check.NotNull(source, nameof(source)); - Check.NotNull(resultType, nameof(resultType)); - - return TranslateAggregateWithSelector( + => TranslateAggregateWithSelector( source, selector, e => _sqlTranslator.TranslateAverage(e), throwWhenEmpty: true, resultType); - } /// 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; - } /// protected override ShapedQueryExpression? TranslateConcat(ShapedQueryExpression source1, ShapedQueryExpression source2) { - Check.NotNull(source1, nameof(source1)); - Check.NotNull(source2, nameof(source2)); - ((SelectExpression)source1.QueryExpression).ApplyUnion((SelectExpression)source2.QueryExpression, distinct: false); return source1.UpdateShaperExpression( @@ -289,9 +265,6 @@ private static ShapedQueryExpression CreateShapedQueryExpression(IEntityType ent /// protected override ShapedQueryExpression? TranslateContains(ShapedQueryExpression source, Expression item) { - Check.NotNull(source, nameof(source)); - Check.NotNull(item, nameof(item)); - var selectExpression = (SelectExpression)source.QueryExpression; var translation = TranslateExpression(item); if (translation == null) @@ -328,17 +301,11 @@ private static ShapedQueryExpression CreateShapedQueryExpression(IEntityType ent /// protected override ShapedQueryExpression? TranslateCount(ShapedQueryExpression source, LambdaExpression? predicate) - { - Check.NotNull(source, nameof(source)); - - return TranslateAggregateWithPredicate(source, predicate, e => _sqlTranslator.TranslateCount(e), typeof(int)); - } + => TranslateAggregateWithPredicate(source, predicate, e => _sqlTranslator.TranslateCount(e), typeof(int)); /// protected override ShapedQueryExpression? TranslateDefaultIfEmpty(ShapedQueryExpression source, Expression? defaultValue) { - Check.NotNull(source, nameof(source)); - if (defaultValue == null) { ((SelectExpression)source.QueryExpression).ApplyDefaultIfEmpty(_sqlExpressionFactory); @@ -351,8 +318,6 @@ private static ShapedQueryExpression CreateShapedQueryExpression(IEntityType ent /// protected override ShapedQueryExpression? TranslateDistinct(ShapedQueryExpression source) { - Check.NotNull(source, nameof(source)); - var selectExpression = (SelectExpression)source.QueryExpression; if (selectExpression.Orderings.Count > 0 && selectExpression.Limit == null @@ -370,19 +335,11 @@ private static ShapedQueryExpression CreateShapedQueryExpression(IEntityType ent ShapedQueryExpression source, Expression index, bool returnDefault) - { - Check.NotNull(source, nameof(source)); - Check.NotNull(index, nameof(index)); - - return null; - } + => null; /// protected override ShapedQueryExpression? TranslateExcept(ShapedQueryExpression source1, ShapedQueryExpression source2) { - Check.NotNull(source1, nameof(source1)); - Check.NotNull(source2, nameof(source2)); - ((SelectExpression)source1.QueryExpression).ApplyExcept((SelectExpression)source2.QueryExpression, distinct: true); // Since except has result from source1, we don't need to change shaper @@ -396,9 +353,6 @@ private static ShapedQueryExpression CreateShapedQueryExpression(IEntityType ent Type returnType, bool returnDefault) { - Check.NotNull(source, nameof(source)); - Check.NotNull(returnType, nameof(returnType)); - if (predicate != null) { var translatedSource = TranslateWhere(source, predicate); @@ -431,9 +385,6 @@ private static ShapedQueryExpression CreateShapedQueryExpression(IEntityType ent LambdaExpression? elementSelector, LambdaExpression? resultSelector) { - Check.NotNull(source, nameof(source)); - Check.NotNull(keySelector, nameof(keySelector)); - var selectExpression = (SelectExpression)source.QueryExpression; // This has it's own set of condition since it is different scenario from below. // Aggregate operators need pushdown for skip/limit/offset covered by selectExpression.PrepareForAggregate. @@ -544,22 +495,11 @@ private static ShapedQueryExpression CreateShapedQueryExpression(IEntityType ent 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; /// protected override ShapedQueryExpression? TranslateIntersect(ShapedQueryExpression source1, ShapedQueryExpression source2) { - Check.NotNull(source1, nameof(source1)); - Check.NotNull(source2, nameof(source2)); - ((SelectExpression)source1.QueryExpression).ApplyIntersect((SelectExpression)source2.QueryExpression, distinct: true); // For intersect since result comes from both sides, if one of them is non-nullable then both are non-nullable @@ -575,12 +515,6 @@ private static ShapedQueryExpression CreateShapedQueryExpression(IEntityType ent 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 joinPredicate = CreateJoinPredicate(outer, outerKeySelector, inner, innerKeySelector); if (joinPredicate != null) { @@ -602,12 +536,6 @@ private static ShapedQueryExpression CreateShapedQueryExpression(IEntityType ent 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 joinPredicate = CreateJoinPredicate(outer, outerKeySelector, inner, innerKeySelector); if (joinPredicate != null) { @@ -667,9 +595,6 @@ private SqlExpression CreateJoinPredicate(Expression outerKey, Expression innerK Type returnType, bool returnDefault) { - Check.NotNull(source, nameof(source)); - Check.NotNull(returnType, nameof(returnType)); - var selectExpression = (SelectExpression)source.QueryExpression; if (selectExpression.Orderings.Count == 0) { @@ -698,36 +623,19 @@ private SqlExpression CreateJoinPredicate(Expression outerKey, Expression innerK /// protected override ShapedQueryExpression? TranslateLongCount(ShapedQueryExpression source, LambdaExpression? predicate) - { - Check.NotNull(source, nameof(source)); - - return TranslateAggregateWithPredicate(source, predicate, e => _sqlTranslator.TranslateLongCount(e), typeof(long)); - } + => TranslateAggregateWithPredicate(source, predicate, e => _sqlTranslator.TranslateLongCount(e), typeof(long)); /// protected override ShapedQueryExpression? TranslateMax(ShapedQueryExpression source, LambdaExpression? selector, Type resultType) - { - Check.NotNull(source, nameof(source)); - Check.NotNull(resultType, nameof(resultType)); - - return TranslateAggregateWithSelector(source, selector, e => _sqlTranslator.TranslateMax(e), throwWhenEmpty: true, resultType); - } + => TranslateAggregateWithSelector(source, selector, e => _sqlTranslator.TranslateMax(e), throwWhenEmpty: true, resultType); /// protected override ShapedQueryExpression? TranslateMin(ShapedQueryExpression source, LambdaExpression? selector, Type resultType) - { - Check.NotNull(source, nameof(source)); - Check.NotNull(resultType, nameof(resultType)); - - return TranslateAggregateWithSelector(source, selector, e => _sqlTranslator.TranslateMin(e), throwWhenEmpty: true, resultType); - } + => TranslateAggregateWithSelector(source, selector, e => _sqlTranslator.TranslateMin(e), throwWhenEmpty: true, resultType); /// 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; @@ -784,9 +692,6 @@ private SqlExpression CreateJoinPredicate(Expression outerKey, Expression innerK LambdaExpression keySelector, bool ascending) { - Check.NotNull(source, nameof(source)); - Check.NotNull(keySelector, nameof(keySelector)); - var translation = TranslateLambdaExpression(source, keySelector); if (translation == null) { @@ -801,8 +706,6 @@ private SqlExpression CreateJoinPredicate(Expression outerKey, Expression innerK /// protected override ShapedQueryExpression? TranslateReverse(ShapedQueryExpression source) { - Check.NotNull(source, nameof(source)); - var selectExpression = (SelectExpression)source.QueryExpression; if (selectExpression.Orderings.Count == 0) { @@ -818,9 +721,6 @@ private SqlExpression CreateJoinPredicate(Expression outerKey, Expression innerK /// 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; @@ -843,10 +743,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 (newCollectionSelector, correlated, defaultIfEmpty) = new CorrelationFindingExpressionVisitor().IsCorrelated(collectionSelector); if (correlated) @@ -909,8 +805,6 @@ private sealed class CorrelationFindingExpressionVisitor : ExpressionVisitor protected override Expression VisitParameter(ParameterExpression parameterExpression) { - Check.NotNull(parameterExpression, nameof(parameterExpression)); - if (parameterExpression == _outerParameter) { _correlated = true; @@ -921,8 +815,6 @@ protected override Expression VisitParameter(ParameterExpression parameterExpres protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression) { - Check.NotNull(methodCallExpression, nameof(methodCallExpression)); - if (methodCallExpression.Method.IsGenericMethod && methodCallExpression.Method.GetGenericMethodDefinition() == QueryableMethods.DefaultIfEmptyWithoutArgument) { @@ -937,9 +829,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); @@ -954,9 +843,6 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp Type returnType, bool returnDefault) { - Check.NotNull(source, nameof(source)); - Check.NotNull(returnType, nameof(returnType)); - if (predicate != null) { var translatedSource = TranslateWhere(source, predicate); @@ -979,9 +865,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 selectExpression = (SelectExpression)source.QueryExpression; var translation = TranslateExpression(count); if (translation == null) @@ -1001,28 +884,15 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp /// protected override ShapedQueryExpression? TranslateSkipWhile(ShapedQueryExpression source, LambdaExpression predicate) - { - Check.NotNull(source, nameof(source)); - Check.NotNull(predicate, nameof(predicate)); - - return null; - } + => null; /// protected override ShapedQueryExpression? TranslateSum(ShapedQueryExpression source, LambdaExpression? selector, Type resultType) - { - Check.NotNull(source, nameof(source)); - Check.NotNull(resultType, nameof(resultType)); - - return TranslateAggregateWithSelector(source, selector, e => _sqlTranslator.TranslateSum(e), throwWhenEmpty: false, resultType); - } + => TranslateAggregateWithSelector(source, selector, e => _sqlTranslator.TranslateSum(e), throwWhenEmpty: false, resultType); /// protected override ShapedQueryExpression? TranslateTake(ShapedQueryExpression source, Expression count) { - Check.NotNull(source, nameof(source)); - Check.NotNull(count, nameof(count)); - var selectExpression = (SelectExpression)source.QueryExpression; var translation = TranslateExpression(count); if (translation == null) @@ -1042,12 +912,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp /// protected override ShapedQueryExpression? TranslateTakeWhile(ShapedQueryExpression source, LambdaExpression predicate) - { - Check.NotNull(source, nameof(source)); - Check.NotNull(predicate, nameof(predicate)); - - return null; - } + => null; /// protected override ShapedQueryExpression? TranslateThenBy( @@ -1055,9 +920,6 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp LambdaExpression keySelector, bool ascending) { - Check.NotNull(source, nameof(source)); - Check.NotNull(keySelector, nameof(keySelector)); - var translation = TranslateLambdaExpression(source, keySelector); if (translation == null) { @@ -1072,9 +934,6 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp /// protected override ShapedQueryExpression? TranslateUnion(ShapedQueryExpression source1, ShapedQueryExpression source2) { - Check.NotNull(source1, nameof(source1)); - Check.NotNull(source2, nameof(source2)); - ((SelectExpression)source1.QueryExpression).ApplyUnion((SelectExpression)source2.QueryExpression, distinct: true); return source1.UpdateShaperExpression( @@ -1084,9 +943,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 translation = TranslateLambdaExpression(source, predicate); if (translation == null) { @@ -1153,8 +1009,6 @@ public Expression Expand(SelectExpression selectExpression, Expression lambdaBod protected override Expression VisitMember(MemberExpression memberExpression) { - Check.NotNull(memberExpression, nameof(memberExpression)); - var innerExpression = Visit(memberExpression.Expression); return TryExpand(innerExpression, MemberIdentity.Create(memberExpression.Member)) @@ -1163,8 +1017,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); @@ -1185,14 +1037,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.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitorDependencies.cs b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitorDependencies.cs index 8508bda61d9..807527d1cb0 100644 --- a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitorDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitorDependencies.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Query @@ -53,9 +52,6 @@ public RelationalQueryableMethodTranslatingExpressionVisitorDependencies( IRelationalSqlTranslatingExpressionVisitorFactory relationalSqlTranslatingExpressionVisitorFactory, ISqlExpressionFactory sqlExpressionFactory) { - Check.NotNull(relationalSqlTranslatingExpressionVisitorFactory, nameof(relationalSqlTranslatingExpressionVisitorFactory)); - Check.NotNull(sqlExpressionFactory, nameof(sqlExpressionFactory)); - RelationalSqlTranslatingExpressionVisitorFactory = relationalSqlTranslatingExpressionVisitorFactory; SqlExpressionFactory = sqlExpressionFactory; } diff --git a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs index 824a39c0def..24a5218d41f 100644 --- a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs @@ -364,8 +364,6 @@ public LambdaExpression ProcessShaper( 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)) @@ -396,8 +394,6 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression) protected override Expression VisitExtension(Expression extensionExpression) { - Check.NotNull(extensionExpression, nameof(extensionExpression)); - switch (extensionExpression) { case RelationalEntityShaperExpression entityShaperExpression: @@ -879,8 +875,6 @@ protected override Expression VisitExtension(Expression extensionExpression) protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression) { - Check.NotNull(methodCallExpression, nameof(methodCallExpression)); - if (methodCallExpression.Method.IsGenericMethod && methodCallExpression.Method.GetGenericMethodDefinition() == Infrastructure.ExpressionExtensions.ValueBufferTryReadValueMethod) diff --git a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.cs index 2952a2dc544..5bc1f75ca61 100644 --- a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.cs @@ -11,7 +11,6 @@ using Microsoft.EntityFrameworkCore.Query.Internal; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query { @@ -36,8 +35,6 @@ public RelationalShapedQueryCompilingExpressionVisitor( QueryCompilationContext queryCompilationContext) : base(dependencies, queryCompilationContext) { - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - RelationalDependencies = relationalDependencies; _contextType = queryCompilationContext.ContextType; @@ -55,8 +52,6 @@ public RelationalShapedQueryCompilingExpressionVisitor( /// protected override Expression VisitShapedQuery(ShapedQueryExpression shapedQueryExpression) { - Check.NotNull(shapedQueryExpression, nameof(shapedQueryExpression)); - var selectExpression = (SelectExpression)shapedQueryExpression.QueryExpression; VerifyNoClientConstant(shapedQueryExpression.ShaperExpression); diff --git a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitorDependencies.cs b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitorDependencies.cs index ab33f264eeb..041761db67a 100644 --- a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitorDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitorDependencies.cs @@ -1,10 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Query @@ -55,9 +52,6 @@ public RelationalShapedQueryCompilingExpressionVisitorDependencies( IQuerySqlGeneratorFactory querySqlGeneratorFactory, IRelationalParameterBasedSqlProcessorFactory relationalParameterBasedSqlProcessorFactory) { - Check.NotNull(querySqlGeneratorFactory, nameof(querySqlGeneratorFactory)); - Check.NotNull(relationalParameterBasedSqlProcessorFactory, nameof(relationalParameterBasedSqlProcessorFactory)); - QuerySqlGeneratorFactory = querySqlGeneratorFactory; RelationalParameterBasedSqlProcessorFactory = relationalParameterBasedSqlProcessorFactory; } diff --git a/src/EFCore.Relational/Query/RelationalSplitCollectionShaperExpression.cs b/src/EFCore.Relational/Query/RelationalSplitCollectionShaperExpression.cs index c02f9aa3613..a732e2aab19 100644 --- a/src/EFCore.Relational/Query/RelationalSplitCollectionShaperExpression.cs +++ b/src/EFCore.Relational/Query/RelationalSplitCollectionShaperExpression.cs @@ -7,7 +7,6 @@ using Microsoft.EntityFrameworkCore.ChangeTracking; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query { @@ -42,12 +41,6 @@ public RelationalSplitCollectionShaperExpression( INavigationBase? navigation, Type elementType) { - Check.NotNull(parentIdentifier, nameof(parentIdentifier)); - Check.NotNull(childIdentifier, nameof(childIdentifier)); - Check.NotEmpty(identifierValueComparers, nameof(identifierValueComparers)); - Check.NotNull(innerShaper, nameof(innerShaper)); - Check.NotNull(elementType, nameof(elementType)); - ParentIdentifier = parentIdentifier; ChildIdentifier = childIdentifier; IdentifierValueComparers = identifierValueComparers; @@ -103,8 +96,6 @@ public sealed override ExpressionType NodeType /// protected override Expression VisitChildren(ExpressionVisitor visitor) { - Check.NotNull(visitor, nameof(visitor)); - var parentIdentifier = visitor.Visit(ParentIdentifier); var childIdentifier = visitor.Visit(ChildIdentifier); var selectExpression = (SelectExpression)visitor.Visit(SelectExpression); @@ -127,26 +118,17 @@ public virtual RelationalSplitCollectionShaperExpression Update( Expression childIdentifier, SelectExpression selectExpression, Expression innerShaper) - { - Check.NotNull(parentIdentifier, nameof(parentIdentifier)); - Check.NotNull(childIdentifier, nameof(childIdentifier)); - Check.NotNull(selectExpression, nameof(selectExpression)); - Check.NotNull(innerShaper, nameof(innerShaper)); - - return parentIdentifier != ParentIdentifier + => parentIdentifier != ParentIdentifier || childIdentifier != ChildIdentifier || selectExpression != SelectExpression || innerShaper != InnerShaper ? new RelationalSplitCollectionShaperExpression( parentIdentifier, childIdentifier, IdentifierValueComparers, selectExpression, innerShaper, Navigation, ElementType) : this; - } /// void IPrintableExpression.Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - expressionPrinter.AppendLine("RelationalCollectionShaper:"); using (expressionPrinter.Indent()) { diff --git a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs index be5a7eb3d7d..a7791dfe999 100644 --- a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs @@ -63,10 +63,6 @@ public RelationalSqlTranslatingExpressionVisitor( QueryCompilationContext queryCompilationContext, QueryableMethodTranslatingExpressionVisitor queryableMethodTranslatingExpressionVisitor) { - Check.NotNull(dependencies, nameof(dependencies)); - Check.NotNull(queryCompilationContext, nameof(queryCompilationContext)); - Check.NotNull(queryableMethodTranslatingExpressionVisitor, nameof(queryableMethodTranslatingExpressionVisitor)); - Dependencies = dependencies; _sqlExpressionFactory = dependencies.SqlExpressionFactory; _queryCompilationContext = queryCompilationContext; @@ -86,8 +82,6 @@ public RelationalSqlTranslatingExpressionVisitor( /// Detailed information about error encountered during translation. protected virtual void AddTranslationErrorDetails(string details) { - Check.NotNull(details, nameof(details)); - if (TranslationErrorDetails == null) { TranslationErrorDetails = details; @@ -110,8 +104,6 @@ protected virtual void AddTranslationErrorDetails(string details) /// A SQL translation of the given expression. public virtual SqlExpression? Translate(Expression expression) { - Check.NotNull(expression, nameof(expression)); - TranslationErrorDetails = null; return TranslateInternal(expression); @@ -153,8 +145,6 @@ protected virtual void AddTranslationErrorDetails(string details) /// A SQL translation of Average over the given expression. public virtual SqlExpression? TranslateAverage(SqlExpression sqlExpression) { - Check.NotNull(sqlExpression, nameof(sqlExpression)); - var inputType = sqlExpression.Type; if (inputType == typeof(int) || inputType == typeof(long)) @@ -192,17 +182,13 @@ protected virtual void AddTranslationErrorDetails(string details) /// An expression to translate Count over. /// A SQL translation of Count over the given expression. public virtual SqlExpression? TranslateCount(SqlExpression sqlExpression) - { - Check.NotNull(sqlExpression, nameof(sqlExpression)); - - return _sqlExpressionFactory.ApplyDefaultTypeMapping( + => _sqlExpressionFactory.ApplyDefaultTypeMapping( _sqlExpressionFactory.Function( "COUNT", new[] { sqlExpression }, nullable: false, argumentsPropagateNullability: new[] { false }, typeof(int))); - } /// /// Translates LongCount over an expression to an equivalent SQL representation. @@ -210,17 +196,13 @@ protected virtual void AddTranslationErrorDetails(string details) /// An expression to translate LongCount over. /// A SQL translation of LongCount over the given expression. public virtual SqlExpression? TranslateLongCount(SqlExpression sqlExpression) - { - Check.NotNull(sqlExpression, nameof(sqlExpression)); - - return _sqlExpressionFactory.ApplyDefaultTypeMapping( + => _sqlExpressionFactory.ApplyDefaultTypeMapping( _sqlExpressionFactory.Function( "COUNT", new[] { sqlExpression }, nullable: false, argumentsPropagateNullability: new[] { false }, typeof(long))); - } /// /// Translates Max over an expression to an equivalent SQL representation. @@ -228,10 +210,7 @@ protected virtual void AddTranslationErrorDetails(string details) /// An expression to translate Max over. /// A SQL translation of Max over the given expression. public virtual SqlExpression? TranslateMax(SqlExpression sqlExpression) - { - Check.NotNull(sqlExpression, nameof(sqlExpression)); - - return sqlExpression != null + => sqlExpression != null ? _sqlExpressionFactory.Function( "MAX", new[] { sqlExpression }, @@ -240,7 +219,6 @@ protected virtual void AddTranslationErrorDetails(string details) sqlExpression.Type, sqlExpression.TypeMapping) : null; - } /// /// Translates Min over an expression to an equivalent SQL representation. @@ -248,10 +226,7 @@ protected virtual void AddTranslationErrorDetails(string details) /// An expression to translate Min over. /// A SQL translation of Min over the given expression. public virtual SqlExpression? TranslateMin(SqlExpression sqlExpression) - { - Check.NotNull(sqlExpression, nameof(sqlExpression)); - - return sqlExpression != null + => sqlExpression != null ? _sqlExpressionFactory.Function( "MIN", new[] { sqlExpression }, @@ -260,7 +235,6 @@ protected virtual void AddTranslationErrorDetails(string details) sqlExpression.Type, sqlExpression.TypeMapping) : null; - } /// /// Translates Sum over an expression to an equivalent SQL representation. @@ -269,8 +243,6 @@ protected virtual void AddTranslationErrorDetails(string details) /// A SQL translation of Sum over the given expression. public virtual SqlExpression? TranslateSum(SqlExpression sqlExpression) { - Check.NotNull(sqlExpression, nameof(sqlExpression)); - var inputType = sqlExpression.Type; return inputType == typeof(float) @@ -295,8 +267,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) @@ -378,8 +348,6 @@ static bool TryUnwrapConvertToObject(Expression expression, out Expression? oper /// 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); @@ -393,13 +361,11 @@ protected override Expression VisitConditional(ConditionalExpression conditional /// protected override Expression VisitConstant(ConstantExpression constantExpression) - => new SqlConstantExpression(Check.NotNull(constantExpression, nameof(constantExpression)), null); + => new SqlConstantExpression(constantExpression, null); /// protected override Expression VisitExtension(Expression extensionExpression) { - Check.NotNull(extensionExpression, nameof(extensionExpression)); - switch (extensionExpression) { case EntityProjectionExpression _: @@ -508,8 +474,6 @@ protected override Expression VisitListInit(ListInitExpression listInitExpressio /// protected override Expression VisitMember(MemberExpression memberExpression) { - Check.NotNull(memberExpression, nameof(memberExpression)); - var innerExpression = Visit(memberExpression.Expression); return TryBindMember(innerExpression, MemberIdentity.Create(memberExpression.Member)) @@ -522,13 +486,11 @@ protected override Expression VisitMember(MemberExpression memberExpression) /// protected override Expression VisitMemberInit(MemberInitExpression memberInitExpression) - => GetConstantOrNotTranslated(Check.NotNull(memberInitExpression, nameof(memberInitExpression))); + => GetConstantOrNotTranslated(memberInitExpression); /// protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression) { - Check.NotNull(methodCallExpression, nameof(methodCallExpression)); - // EF.Property case if (methodCallExpression.TryGetEFPropertyArguments(out var source, out var propertyName)) { @@ -711,7 +673,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp /// protected override Expression VisitNew(NewExpression newExpression) - => GetConstantOrNotTranslated(Check.NotNull(newExpression, nameof(newExpression))); + => GetConstantOrNotTranslated(newExpression); /// protected override Expression VisitNewArray(NewArrayExpression newArrayExpression) @@ -720,14 +682,12 @@ protected override Expression VisitNewArray(NewArrayExpression newArrayExpressio /// protected override Expression VisitParameter(ParameterExpression parameterExpression) => parameterExpression.Name?.StartsWith(QueryCompilationContext.QueryParameterPrefix, StringComparison.Ordinal) == true - ? new SqlParameterExpression(Check.NotNull(parameterExpression, nameof(parameterExpression)), null) + ? new SqlParameterExpression(parameterExpression, null) : throw new InvalidOperationException(CoreStrings.TranslationFailed(parameterExpression.Print())); /// protected override Expression VisitTypeBinary(TypeBinaryExpression typeBinaryExpression) { - Check.NotNull(typeBinaryExpression, nameof(typeBinaryExpression)); - var innerExpression = Visit(typeBinaryExpression.Expression); if (typeBinaryExpression.NodeType == ExpressionType.TypeIs @@ -836,8 +796,6 @@ static bool HasSiblings(IEntityType entityType) /// protected override Expression VisitUnary(UnaryExpression unaryExpression) { - Check.NotNull(unaryExpression, nameof(unaryExpression)); - var operand = Visit(unaryExpression.Operand); if (operand is EntityReferenceExpression entityReferenceExpression @@ -1454,8 +1412,6 @@ private sealed class SqlTypeMappingVerifyingExpressionVisitor : ExpressionVisito { protected override Expression VisitExtension(Expression extensionExpression) { - Check.NotNull(extensionExpression, nameof(extensionExpression)); - if (extensionExpression is SqlExpression sqlExpression && !(extensionExpression is SqlFragmentExpression)) { diff --git a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitorDependencies.cs b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitorDependencies.cs index 5e061589d0a..1c8a0290db9 100644 --- a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitorDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitorDependencies.cs @@ -4,7 +4,6 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Query @@ -58,12 +57,6 @@ public RelationalSqlTranslatingExpressionVisitorDependencies( IMemberTranslatorProvider memberTranslatorProvider, IMethodCallTranslatorProvider methodCallTranslatorProvider) { - Check.NotNull(sqlExpressionFactory, nameof(sqlExpressionFactory)); - Check.NotNull(model, nameof(model)); - Check.NotNull(typeMappingSource, nameof(typeMappingSource)); - Check.NotNull(memberTranslatorProvider, nameof(memberTranslatorProvider)); - Check.NotNull(methodCallTranslatorProvider, nameof(methodCallTranslatorProvider)); - SqlExpressionFactory = sqlExpressionFactory; Model = model; #pragma warning disable CS0618 // Type or member is obsolete diff --git a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitorFactory.cs b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitorFactory.cs index 617c753abef..0cfc7e60e5a 100644 --- a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitorFactory.cs +++ b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitorFactory.cs @@ -1,7 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Query @@ -41,14 +40,9 @@ public RelationalSqlTranslatingExpressionVisitorFactory( public virtual RelationalSqlTranslatingExpressionVisitor Create( QueryCompilationContext queryCompilationContext, QueryableMethodTranslatingExpressionVisitor queryableMethodTranslatingExpressionVisitor) - { - Check.NotNull(queryCompilationContext, nameof(queryCompilationContext)); - Check.NotNull(queryableMethodTranslatingExpressionVisitor, nameof(queryableMethodTranslatingExpressionVisitor)); - - return new RelationalSqlTranslatingExpressionVisitor( + => new RelationalSqlTranslatingExpressionVisitor( Dependencies, queryCompilationContext, queryableMethodTranslatingExpressionVisitor); - } } } diff --git a/src/EFCore.Relational/Query/SqlExpressionFactory.cs b/src/EFCore.Relational/Query/SqlExpressionFactory.cs index 3c718a6df21..0b20589584e 100644 --- a/src/EFCore.Relational/Query/SqlExpressionFactory.cs +++ b/src/EFCore.Relational/Query/SqlExpressionFactory.cs @@ -12,7 +12,6 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query { @@ -27,8 +26,6 @@ public class SqlExpressionFactory : ISqlExpressionFactory /// Parameter object containing dependencies for this class. public SqlExpressionFactory(SqlExpressionFactoryDependencies dependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Dependencies = dependencies; _boolTypeMapping = dependencies.TypeMappingSource.FindMapping(typeof(bool), dependencies.Model)!; } @@ -265,9 +262,6 @@ private SqlExpression ApplyTypeMappingOnIn(InExpression inExpression) SqlExpression right, RelationalTypeMapping? typeMapping) { - Check.NotNull(left, nameof(left)); - Check.NotNull(right, nameof(right)); - if (!SqlBinaryExpression.IsValidOperator(operatorType)) { return null; @@ -294,145 +288,67 @@ private SqlExpression ApplyTypeMappingOnIn(InExpression inExpression) /// public virtual SqlBinaryExpression Equal(SqlExpression left, SqlExpression right) - { - Check.NotNull(left, nameof(left)); - Check.NotNull(right, nameof(right)); - - return MakeBinary(ExpressionType.Equal, left, right, null)!; - } + => MakeBinary(ExpressionType.Equal, left, right, null)!; /// public virtual SqlBinaryExpression NotEqual(SqlExpression left, SqlExpression right) - { - Check.NotNull(left, nameof(left)); - Check.NotNull(right, nameof(right)); - - return MakeBinary(ExpressionType.NotEqual, left, right, null)!; - } + => MakeBinary(ExpressionType.NotEqual, left, right, null)!; /// public virtual SqlBinaryExpression GreaterThan(SqlExpression left, SqlExpression right) - { - Check.NotNull(left, nameof(left)); - Check.NotNull(right, nameof(right)); - - return MakeBinary(ExpressionType.GreaterThan, left, right, null)!; - } + => MakeBinary(ExpressionType.GreaterThan, left, right, null)!; /// public virtual SqlBinaryExpression GreaterThanOrEqual(SqlExpression left, SqlExpression right) - { - Check.NotNull(left, nameof(left)); - Check.NotNull(right, nameof(right)); - - return MakeBinary(ExpressionType.GreaterThanOrEqual, left, right, null)!; - } + => MakeBinary(ExpressionType.GreaterThanOrEqual, left, right, null)!; /// public virtual SqlBinaryExpression LessThan(SqlExpression left, SqlExpression right) - { - Check.NotNull(left, nameof(left)); - Check.NotNull(right, nameof(right)); - - return MakeBinary(ExpressionType.LessThan, left, right, null)!; - } + => MakeBinary(ExpressionType.LessThan, left, right, null)!; /// public virtual SqlBinaryExpression LessThanOrEqual(SqlExpression left, SqlExpression right) - { - Check.NotNull(left, nameof(left)); - Check.NotNull(right, nameof(right)); - - return MakeBinary(ExpressionType.LessThanOrEqual, left, right, null)!; - } + => MakeBinary(ExpressionType.LessThanOrEqual, left, right, null)!; /// public virtual SqlBinaryExpression AndAlso(SqlExpression left, SqlExpression right) - { - Check.NotNull(left, nameof(left)); - Check.NotNull(right, nameof(right)); - - return MakeBinary(ExpressionType.AndAlso, left, right, null)!; - } + => MakeBinary(ExpressionType.AndAlso, left, right, null)!; /// public virtual SqlBinaryExpression OrElse(SqlExpression left, SqlExpression right) - { - Check.NotNull(left, nameof(left)); - Check.NotNull(right, nameof(right)); - - return MakeBinary(ExpressionType.OrElse, left, right, null)!; - } + => MakeBinary(ExpressionType.OrElse, left, right, null)!; /// public virtual SqlBinaryExpression Add(SqlExpression left, SqlExpression right, RelationalTypeMapping? typeMapping = null) - { - Check.NotNull(left, nameof(left)); - Check.NotNull(right, nameof(right)); - - return MakeBinary(ExpressionType.Add, left, right, typeMapping)!; - } + => MakeBinary(ExpressionType.Add, left, right, typeMapping)!; /// public virtual SqlBinaryExpression Subtract(SqlExpression left, SqlExpression right, RelationalTypeMapping? typeMapping = null) - { - Check.NotNull(left, nameof(left)); - Check.NotNull(right, nameof(right)); - - return MakeBinary(ExpressionType.Subtract, left, right, typeMapping)!; - } + => MakeBinary(ExpressionType.Subtract, left, right, typeMapping)!; /// public virtual SqlBinaryExpression Multiply(SqlExpression left, SqlExpression right, RelationalTypeMapping? typeMapping = null) - { - Check.NotNull(left, nameof(left)); - Check.NotNull(right, nameof(right)); - - return MakeBinary(ExpressionType.Multiply, left, right, typeMapping)!; - } + => MakeBinary(ExpressionType.Multiply, left, right, typeMapping)!; /// public virtual SqlBinaryExpression Divide(SqlExpression left, SqlExpression right, RelationalTypeMapping? typeMapping = null) - { - Check.NotNull(left, nameof(left)); - Check.NotNull(right, nameof(right)); - - return MakeBinary(ExpressionType.Divide, left, right, typeMapping)!; - } + => MakeBinary(ExpressionType.Divide, left, right, typeMapping)!; /// public virtual SqlBinaryExpression Modulo(SqlExpression left, SqlExpression right, RelationalTypeMapping? typeMapping = null) - { - Check.NotNull(left, nameof(left)); - Check.NotNull(right, nameof(right)); - - return MakeBinary(ExpressionType.Modulo, left, right, typeMapping)!; - } + => MakeBinary(ExpressionType.Modulo, left, right, typeMapping)!; /// public virtual SqlBinaryExpression And(SqlExpression left, SqlExpression right, RelationalTypeMapping? typeMapping = null) - { - Check.NotNull(left, nameof(left)); - Check.NotNull(right, nameof(right)); - - return MakeBinary(ExpressionType.And, left, right, typeMapping)!; - } + => MakeBinary(ExpressionType.And, left, right, typeMapping)!; /// public virtual SqlBinaryExpression Or(SqlExpression left, SqlExpression right, RelationalTypeMapping? typeMapping = null) - { - Check.NotNull(left, nameof(left)); - Check.NotNull(right, nameof(right)); - - return MakeBinary(ExpressionType.Or, left, right, typeMapping)!; - } + => MakeBinary(ExpressionType.Or, left, right, typeMapping)!; /// public virtual SqlFunctionExpression Coalesce(SqlExpression left, SqlExpression right, RelationalTypeMapping? typeMapping = null) { - Check.NotNull(left, nameof(left)); - Check.NotNull(right, nameof(right)); - var resultType = right.Type; var inferredTypeMapping = typeMapping ?? ExpressionExtensions.InferTypeMapping(left, right) @@ -459,64 +375,34 @@ public virtual SqlFunctionExpression Coalesce(SqlExpression left, SqlExpression SqlExpression operand, Type type, RelationalTypeMapping? typeMapping = null) - { - Check.NotNull(operatorType, nameof(operand)); - Check.NotNull(operand, nameof(operand)); - Check.NotNull(type, nameof(type)); - - return !SqlUnaryExpression.IsValidOperator(operatorType) + => !SqlUnaryExpression.IsValidOperator(operatorType) ? null : (SqlUnaryExpression)ApplyTypeMapping(new SqlUnaryExpression(operatorType, operand, type, null), typeMapping); - } /// public virtual SqlUnaryExpression IsNull(SqlExpression operand) - { - Check.NotNull(operand, nameof(operand)); - - return MakeUnary(ExpressionType.Equal, operand, typeof(bool))!; - } + => MakeUnary(ExpressionType.Equal, operand, typeof(bool))!; /// public virtual SqlUnaryExpression IsNotNull(SqlExpression operand) - { - Check.NotNull(operand, nameof(operand)); - - return MakeUnary(ExpressionType.NotEqual, operand, typeof(bool))!; - } + => MakeUnary(ExpressionType.NotEqual, operand, typeof(bool))!; /// public virtual SqlUnaryExpression Convert(SqlExpression operand, Type type, RelationalTypeMapping? typeMapping = null) - { - Check.NotNull(operand, nameof(operand)); - Check.NotNull(type, nameof(type)); - - return MakeUnary(ExpressionType.Convert, operand, type.UnwrapNullableType(), typeMapping)!; - } + => MakeUnary(ExpressionType.Convert, operand, type.UnwrapNullableType(), typeMapping)!; /// public virtual SqlUnaryExpression Not(SqlExpression operand) - { - Check.NotNull(operand, nameof(operand)); - - return MakeUnary(ExpressionType.Not, operand, operand.Type, operand.TypeMapping)!; - } + => MakeUnary(ExpressionType.Not, operand, operand.Type, operand.TypeMapping)!; /// public virtual SqlUnaryExpression Negate(SqlExpression operand) - { - Check.NotNull(operand, nameof(operand)); - - return MakeUnary(ExpressionType.Negate, operand, operand.Type, operand.TypeMapping)!; - } + => MakeUnary(ExpressionType.Negate, operand, operand.Type, operand.TypeMapping)!; /// public virtual CaseExpression Case(SqlExpression? operand, IReadOnlyList whenClauses, SqlExpression? elseResult) { - Check.NotNull(operand, nameof(operand)); - Check.NotNull(whenClauses, nameof(whenClauses)); - - var operandTypeMapping = operand.TypeMapping + var operandTypeMapping = operand!.TypeMapping ?? whenClauses.Select(wc => wc.Test.TypeMapping).FirstOrDefault(t => t != null) // Since we never look at type of Operand/Test after this place, // we need to find actual typeMapping based on non-object type. @@ -545,8 +431,6 @@ public virtual CaseExpression Case(SqlExpression? operand, IReadOnlyList public virtual CaseExpression Case(IReadOnlyList whenClauses, SqlExpression? elseResult) { - Check.NotNull(whenClauses, nameof(whenClauses)); - var resultTypeMapping = elseResult?.TypeMapping ?? whenClauses.Select(wc => wc.Result.TypeMapping).FirstOrDefault(t => t != null); @@ -573,11 +457,6 @@ public virtual SqlFunctionExpression Function( Type returnType, RelationalTypeMapping? typeMapping = null) { - Check.NotEmpty(name, nameof(name)); - Check.NotNull(arguments, nameof(arguments)); - Check.NotNull(argumentsPropagateNullability, nameof(argumentsPropagateNullability)); - Check.NotNull(returnType, nameof(returnType)); - var typeMappedArguments = new List(); foreach (var argument in arguments) @@ -598,12 +477,6 @@ public virtual SqlFunctionExpression Function( Type returnType, RelationalTypeMapping? typeMapping = null) { - Check.NullButNotEmpty(schema, nameof(schema)); - Check.NotEmpty(name, nameof(name)); - Check.NotNull(arguments, nameof(arguments)); - Check.NotNull(argumentsPropagateNullability, nameof(argumentsPropagateNullability)); - Check.NotNull(returnType, nameof(returnType)); - var typeMappedArguments = new List(); foreach (var argument in arguments) { @@ -625,12 +498,6 @@ public virtual SqlFunctionExpression Function( Type returnType, RelationalTypeMapping? typeMapping = null) { - Check.NotNull(instance, nameof(instance)); - Check.NotEmpty(name, nameof(name)); - Check.NotNull(arguments, nameof(arguments)); - Check.NotNull(argumentsPropagateNullability, nameof(argumentsPropagateNullability)); - Check.NotNull(returnType, nameof(returnType)); - instance = ApplyDefaultTypeMapping(instance); var typeMappedArguments = new List(); foreach (var argument in arguments) @@ -649,12 +516,7 @@ public virtual SqlFunctionExpression NiladicFunction( bool nullable, Type returnType, RelationalTypeMapping? typeMapping = null) - { - Check.NotEmpty(name, nameof(name)); - Check.NotNull(returnType, nameof(returnType)); - - return new SqlFunctionExpression(name, nullable, returnType, typeMapping); - } + => new SqlFunctionExpression(name, nullable, returnType, typeMapping); /// public virtual SqlFunctionExpression NiladicFunction( @@ -663,13 +525,7 @@ public virtual SqlFunctionExpression NiladicFunction( bool nullable, Type returnType, RelationalTypeMapping? typeMapping = null) - { - Check.NotEmpty(schema, nameof(schema)); - Check.NotEmpty(name, nameof(name)); - Check.NotNull(returnType, nameof(returnType)); - - return new SqlFunctionExpression(schema, name, nullable, returnType, typeMapping); - } + => new SqlFunctionExpression(schema, name, nullable, returnType, typeMapping); /// public virtual SqlFunctionExpression NiladicFunction( @@ -679,29 +535,16 @@ public virtual SqlFunctionExpression NiladicFunction( bool instancePropagatesNullability, Type returnType, RelationalTypeMapping? typeMapping = null) - { - Check.NotNull(instance, nameof(instance)); - Check.NotEmpty(name, nameof(name)); - Check.NotNull(returnType, nameof(returnType)); - - return new SqlFunctionExpression( + => new SqlFunctionExpression( ApplyDefaultTypeMapping(instance), name, nullable, instancePropagatesNullability, returnType, typeMapping); - } /// public virtual ExistsExpression Exists(SelectExpression subquery, bool negated) - { - Check.NotNull(subquery, nameof(subquery)); - - return new ExistsExpression(subquery, negated, _boolTypeMapping); - } + => new ExistsExpression(subquery, negated, _boolTypeMapping); /// public virtual InExpression In(SqlExpression item, SqlExpression values, bool negated) { - Check.NotNull(item, nameof(item)); - Check.NotNull(values, nameof(values)); - var typeMapping = item.TypeMapping ?? Dependencies.TypeMappingSource.FindMapping(item.Type, Dependencies.Model); item = ApplyTypeMapping(item, typeMapping); @@ -713,9 +556,6 @@ public virtual InExpression In(SqlExpression item, SqlExpression values, bool ne /// public virtual InExpression In(SqlExpression item, SelectExpression subquery, bool negated) { - Check.NotNull(item, nameof(item)); - Check.NotNull(subquery, nameof(subquery)); - var sqlExpression = subquery.Projection.Single().Expression; var typeMapping = sqlExpression.TypeMapping; @@ -725,20 +565,11 @@ public virtual InExpression In(SqlExpression item, SelectExpression subquery, bo /// public virtual LikeExpression Like(SqlExpression match, SqlExpression pattern, SqlExpression? escapeChar = null) - { - Check.NotNull(match, nameof(match)); - Check.NotNull(pattern, nameof(pattern)); - - return (LikeExpression)ApplyDefaultTypeMapping(new LikeExpression(match, pattern, escapeChar, null)); - } + => (LikeExpression)ApplyDefaultTypeMapping(new LikeExpression(match, pattern, escapeChar, null)); /// public virtual SqlFragmentExpression Fragment(string sql) - { - Check.NotNull(sql, nameof(sql)); - - return new SqlFragmentExpression(sql); - } + => new SqlFragmentExpression(sql); /// public virtual SqlConstantExpression Constant(object? value, RelationalTypeMapping? typeMapping = null) @@ -751,8 +582,6 @@ public virtual SelectExpression Select(SqlExpression? projection) /// public virtual SelectExpression Select(IEntityType entityType) { - Check.NotNull(entityType, nameof(entityType)); - var selectExpression = new SelectExpression(entityType, this); AddConditions(selectExpression, entityType); @@ -762,9 +591,6 @@ public virtual SelectExpression Select(IEntityType entityType) /// public virtual SelectExpression Select(IEntityType entityType, TableExpressionBase tableExpressionBase) { - Check.NotNull(entityType, nameof(entityType)); - Check.NotNull(tableExpressionBase, nameof(tableExpressionBase)); - var selectExpression = new SelectExpression(entityType, tableExpressionBase); AddConditions(selectExpression, entityType); diff --git a/src/EFCore.Relational/Query/SqlExpressionFactoryDependencies.cs b/src/EFCore.Relational/Query/SqlExpressionFactoryDependencies.cs index 2ef0460a236..9141a093636 100644 --- a/src/EFCore.Relational/Query/SqlExpressionFactoryDependencies.cs +++ b/src/EFCore.Relational/Query/SqlExpressionFactoryDependencies.cs @@ -4,7 +4,6 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Query @@ -53,9 +52,6 @@ public sealed record SqlExpressionFactoryDependencies [EntityFrameworkInternal] public SqlExpressionFactoryDependencies(IModel model, IRelationalTypeMappingSource typeMappingSource) { - Check.NotNull(model, nameof(model)); - Check.NotNull(typeMappingSource, nameof(typeMappingSource)); - Model = model; TypeMappingSource = typeMappingSource; } diff --git a/src/EFCore.Relational/Query/SqlExpressionVisitor.cs b/src/EFCore.Relational/Query/SqlExpressionVisitor.cs index 0e8d3702aa5..d1055f4e83d 100644 --- a/src/EFCore.Relational/Query/SqlExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/SqlExpressionVisitor.cs @@ -3,7 +3,6 @@ using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query { @@ -21,8 +20,6 @@ public abstract class SqlExpressionVisitor : ExpressionVisitor /// protected override Expression VisitExtension(Expression extensionExpression) { - Check.NotNull(extensionExpression, nameof(extensionExpression)); - switch (extensionExpression) { case ShapedQueryExpression shapedQueryExpression: diff --git a/src/EFCore.Relational/Query/SqlExpressions/CaseExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/CaseExpression.cs index 529944d6066..49ca652a74f 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/CaseExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/CaseExpression.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -32,10 +31,8 @@ public CaseExpression( SqlExpression operand, IReadOnlyList whenClauses, SqlExpression? elseResult = null) - : base(Check.NotEmpty(whenClauses, nameof(whenClauses))[0].Result.Type, whenClauses[0].Result.TypeMapping) + : base(whenClauses[0].Result.Type, whenClauses[0].Result.TypeMapping) { - Check.NotNull(operand, nameof(operand)); - Operand = operand; _whenClauses.AddRange(whenClauses); ElseResult = elseResult; @@ -49,7 +46,7 @@ public CaseExpression( public CaseExpression( IReadOnlyList whenClauses, SqlExpression? elseResult = null) - : base(Check.NotEmpty(whenClauses, nameof(whenClauses))[0].Result.Type, whenClauses[0].Result.TypeMapping) + : base(whenClauses[0].Result.Type, whenClauses[0].Result.TypeMapping) { _whenClauses.AddRange(whenClauses); ElseResult = elseResult; @@ -74,8 +71,6 @@ public virtual IReadOnlyList WhenClauses /// protected override Expression VisitChildren(ExpressionVisitor visitor) { - Check.NotNull(visitor, nameof(visitor)); - var operand = (SqlExpression?)visitor.Visit(Operand); var changed = operand != Operand; var whenClauses = new List(); @@ -127,8 +122,6 @@ public virtual CaseExpression Update( /// protected override void Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - expressionPrinter.Append("CASE"); if (Operand != null) { diff --git a/src/EFCore.Relational/Query/SqlExpressions/CaseWhenClause.cs b/src/EFCore.Relational/Query/SqlExpressions/CaseWhenClause.cs index bc4c01ebe8d..70acc6217ea 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/CaseWhenClause.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/CaseWhenClause.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -24,9 +23,6 @@ public class CaseWhenClause /// A value to return if test succeeds. public CaseWhenClause(SqlExpression test, SqlExpression result) { - Check.NotNull(test, nameof(test)); - Check.NotNull(result, nameof(result)); - Test = test; Result = result; } diff --git a/src/EFCore.Relational/Query/SqlExpressions/CollateExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/CollateExpression.cs index 37dd2fc65e3..84868465e0c 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/CollateExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/CollateExpression.cs @@ -3,7 +3,6 @@ using System; using System.Linq.Expressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -26,9 +25,6 @@ public class CollateExpression : SqlExpression public CollateExpression(SqlExpression operand, string collation) : base(operand.Type, operand.TypeMapping) { - Check.NotNull(operand, nameof(operand)); - Check.NotEmpty(collation, nameof(collation)); - Operand = operand; Collation = collation; } @@ -45,11 +41,7 @@ public CollateExpression(SqlExpression operand, string collation) /// protected override Expression VisitChildren(ExpressionVisitor visitor) - { - Check.NotNull(visitor, nameof(visitor)); - - return Update((SqlExpression)visitor.Visit(Operand)); - } + => Update((SqlExpression)visitor.Visit(Operand)); /// /// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will @@ -58,19 +50,13 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// The property of the result. /// This expression if no children changed, or an expression with the updated children. public virtual CollateExpression Update(SqlExpression operand) - { - Check.NotNull(operand, nameof(operand)); - - return operand != Operand + => operand != Operand ? new CollateExpression(operand, Collation) : this; - } /// protected override void Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - expressionPrinter.Visit(Operand); expressionPrinter .Append(" COLLATE ") diff --git a/src/EFCore.Relational/Query/SqlExpressions/ColumnExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/ColumnExpression.cs index 2c203fb7b2c..ce853aab527 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/ColumnExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/ColumnExpression.cs @@ -4,7 +4,6 @@ using System; using System.Diagnostics; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -59,8 +58,6 @@ protected ColumnExpression(Type type, RelationalTypeMapping? typeMapping) /// protected override void Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - expressionPrinter.Append(TableAlias).Append("."); expressionPrinter.Append(Name); } diff --git a/src/EFCore.Relational/Query/SqlExpressions/CrossApplyExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/CrossApplyExpression.cs index 8f01d755345..640bf89441e 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/CrossApplyExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/CrossApplyExpression.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Linq.Expressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -28,11 +27,7 @@ public CrossApplyExpression(TableExpressionBase table) /// protected override Expression VisitChildren(ExpressionVisitor visitor) - { - Check.NotNull(visitor, nameof(visitor)); - - return Update((TableExpressionBase)visitor.Visit(Table)); - } + => Update((TableExpressionBase)visitor.Visit(Table)); /// /// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will @@ -41,19 +36,13 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// The property of the result. /// This expression if no children changed, or an expression with the updated children. public virtual CrossApplyExpression Update(TableExpressionBase table) - { - Check.NotNull(table, nameof(table)); - - return table != Table + => table != Table ? new CrossApplyExpression(table) : this; - } /// protected override void Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - expressionPrinter.Append("CROSS APPLY "); expressionPrinter.Visit(Table); } diff --git a/src/EFCore.Relational/Query/SqlExpressions/CrossJoinExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/CrossJoinExpression.cs index ef3959596d6..3422536ce51 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/CrossJoinExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/CrossJoinExpression.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Linq.Expressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -28,11 +27,7 @@ public CrossJoinExpression(TableExpressionBase table) /// protected override Expression VisitChildren(ExpressionVisitor visitor) - { - Check.NotNull(visitor, nameof(visitor)); - - return Update((TableExpressionBase)visitor.Visit(Table)); - } + => Update((TableExpressionBase)visitor.Visit(Table)); /// /// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will @@ -41,19 +36,13 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// The property of the result. /// This expression if no children changed, or an expression with the updated children. public virtual CrossJoinExpression Update(TableExpressionBase table) - { - Check.NotNull(table, nameof(table)); - - return table != Table + => table != Table ? new CrossJoinExpression(table) : this; - } /// protected override void Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - expressionPrinter.Append("CROSS JOIN "); expressionPrinter.Visit(Table); } diff --git a/src/EFCore.Relational/Query/SqlExpressions/DistinctExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/DistinctExpression.cs index 16ffd7a802e..38565df210f 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/DistinctExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/DistinctExpression.cs @@ -3,7 +3,6 @@ using System; using System.Linq.Expressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -25,8 +24,6 @@ public class DistinctExpression : SqlExpression public DistinctExpression(SqlExpression operand) : base(operand.Type, operand.TypeMapping) { - Check.NotNull(operand, nameof(operand)); - Operand = operand; } @@ -37,11 +34,7 @@ public DistinctExpression(SqlExpression operand) /// protected override Expression VisitChildren(ExpressionVisitor visitor) - { - Check.NotNull(visitor, nameof(visitor)); - - return Update((SqlExpression)visitor.Visit(Operand)); - } + => Update((SqlExpression)visitor.Visit(Operand)); /// /// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will @@ -50,19 +43,13 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// The property of the result. /// This expression if no children changed, or an expression with the updated children. public virtual DistinctExpression Update(SqlExpression operand) - { - Check.NotNull(operand, nameof(operand)); - - return operand != Operand + => operand != Operand ? new DistinctExpression(operand) : this; - } /// protected override void Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - expressionPrinter.Append("(DISTINCT "); expressionPrinter.Visit(Operand); expressionPrinter.Append(")"); diff --git a/src/EFCore.Relational/Query/SqlExpressions/ExceptExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/ExceptExpression.cs index 6efe26ae532..0f9dcc2e658 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/ExceptExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/ExceptExpression.cs @@ -3,7 +3,6 @@ using System; using System.Linq.Expressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -37,8 +36,6 @@ public ExceptExpression( /// protected override Expression VisitChildren(ExpressionVisitor visitor) { - Check.NotNull(visitor, nameof(visitor)); - var source1 = (SelectExpression)visitor.Visit(Source1); var source2 = (SelectExpression)visitor.Visit(Source2); @@ -53,20 +50,13 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// The property of the result. /// This expression if no children changed, or an expression with the updated children. public virtual ExceptExpression Update(SelectExpression source1, SelectExpression source2) - { - Check.NotNull(source1, nameof(source1)); - Check.NotNull(source2, nameof(source2)); - - return source1 != Source1 || source2 != Source2 + => source1 != Source1 || source2 != Source2 ? new ExceptExpression(Alias, source1, source2, IsDistinct) : this; - } /// protected override void Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - expressionPrinter.Append("("); using (expressionPrinter.Indent()) { diff --git a/src/EFCore.Relational/Query/SqlExpressions/ExistsExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/ExistsExpression.cs index cf5b19fc626..e4851dc298c 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/ExistsExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/ExistsExpression.cs @@ -4,7 +4,6 @@ using System; using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -31,8 +30,6 @@ public ExistsExpression( RelationalTypeMapping? typeMapping) : base(typeof(bool), typeMapping) { - Check.NotNull(subquery, nameof(subquery)); - Subquery = subquery; IsNegated = negated; } @@ -49,11 +46,7 @@ public ExistsExpression( /// protected override Expression VisitChildren(ExpressionVisitor visitor) - { - Check.NotNull(visitor, nameof(visitor)); - - return Update((SelectExpression)visitor.Visit(Subquery)); - } + => Update((SelectExpression)visitor.Visit(Subquery)); /// /// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will @@ -62,19 +55,13 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// The property of the result. /// This expression if no children changed, or an expression with the updated children. public virtual ExistsExpression Update(SelectExpression subquery) - { - Check.NotNull(subquery, nameof(subquery)); - - return subquery != Subquery + => subquery != Subquery ? new ExistsExpression(subquery, IsNegated, TypeMapping) : this; - } /// protected override void Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - if (IsNegated) { expressionPrinter.Append("NOT "); diff --git a/src/EFCore.Relational/Query/SqlExpressions/FromSqlExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/FromSqlExpression.cs index 08041a86a54..b764f238000 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/FromSqlExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/FromSqlExpression.cs @@ -4,7 +4,6 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Linq.Expressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -28,9 +27,6 @@ public class FromSqlExpression : TableExpressionBase, IClonableTableExpressionBa public FromSqlExpression(string alias, string sql, Expression arguments) : base(alias) { - Check.NotEmpty(sql, nameof(sql)); - Check.NotNull(arguments, nameof(arguments)); - Sql = sql; Arguments = arguments; } @@ -62,21 +58,13 @@ public override string? Alias /// The property of the result. /// This expression if no children changed, or an expression with the updated children. public virtual FromSqlExpression Update(Expression arguments) - { - Check.NotNull(arguments, nameof(arguments)); - - return arguments != Arguments + => arguments != Arguments ? new FromSqlExpression(Alias, Sql, arguments) : this; - } /// protected override Expression VisitChildren(ExpressionVisitor visitor) - { - Check.NotNull(visitor, nameof(visitor)); - - return this; - } + => this; /// public virtual TableExpressionBase Clone() @@ -84,11 +72,7 @@ public virtual TableExpressionBase Clone() /// protected override void Print(ExpressionPrinter expressionPrinter) - { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - - expressionPrinter.Append(Sql); - } + => expressionPrinter.Append(Sql); /// public override bool Equals(object? obj) diff --git a/src/EFCore.Relational/Query/SqlExpressions/InExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/InExpression.cs index 3bab1c48d1c..fc10f230027 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/InExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/InExpression.cs @@ -6,7 +6,6 @@ using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -33,7 +32,7 @@ public InExpression( SelectExpression subquery, bool negated, RelationalTypeMapping typeMapping) - : this(Check.NotNull(item, nameof(item)), null, Check.NotNull(subquery, nameof(subquery)), negated, typeMapping) + : this(item, null, subquery, negated, typeMapping) { } @@ -49,7 +48,7 @@ public InExpression( SqlExpression values, bool negated, RelationalTypeMapping typeMapping) - : this(Check.NotNull(item, nameof(item)), Check.NotNull(values, nameof(values)), null, negated, typeMapping) + : this(item, values, null, negated, typeMapping) { } @@ -90,8 +89,6 @@ private InExpression( /// protected override Expression VisitChildren(ExpressionVisitor visitor) { - Check.NotNull(visitor, nameof(visitor)); - var item = (SqlExpression)visitor.Visit(Item); var subquery = (SelectExpression?)visitor.Visit(Subquery); var values = (SqlExpression?)visitor.Visit(Values); @@ -119,8 +116,6 @@ public virtual InExpression Update( SqlExpression? values, SelectExpression? subquery) { - Check.NotNull(item, nameof(item)); - if (values != null && subquery != null) { @@ -135,8 +130,6 @@ public virtual InExpression Update( /// protected override void Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - expressionPrinter.Visit(Item); expressionPrinter.Append(IsNegated ? " NOT IN " : " IN "); expressionPrinter.Append("("); diff --git a/src/EFCore.Relational/Query/SqlExpressions/InnerJoinExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/InnerJoinExpression.cs index d248fbe49bb..7f1a73dccd0 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/InnerJoinExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/InnerJoinExpression.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Linq.Expressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -30,8 +29,6 @@ public InnerJoinExpression(TableExpressionBase table, SqlExpression joinPredicat /// protected override Expression VisitChildren(ExpressionVisitor visitor) { - Check.NotNull(visitor, nameof(visitor)); - var table = (TableExpressionBase)visitor.Visit(Table); var joinPredicate = (SqlExpression)visitor.Visit(JoinPredicate); @@ -46,20 +43,13 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// The property of the result. /// This expression if no children changed, or an expression with the updated children. public virtual InnerJoinExpression Update(TableExpressionBase table, SqlExpression joinPredicate) - { - Check.NotNull(table, nameof(table)); - Check.NotNull(joinPredicate, nameof(joinPredicate)); - - return table != Table || joinPredicate != JoinPredicate + => table != Table || joinPredicate != JoinPredicate ? new InnerJoinExpression(table, joinPredicate) : this; - } /// protected override void Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - expressionPrinter.Append("INNER JOIN "); expressionPrinter.Visit(Table); expressionPrinter.Append(" ON "); diff --git a/src/EFCore.Relational/Query/SqlExpressions/IntersectExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/IntersectExpression.cs index 012d8cc875b..626186f7f79 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/IntersectExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/IntersectExpression.cs @@ -3,7 +3,6 @@ using System; using System.Linq.Expressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -37,8 +36,6 @@ public IntersectExpression( /// protected override Expression VisitChildren(ExpressionVisitor visitor) { - Check.NotNull(visitor, nameof(visitor)); - var source1 = (SelectExpression)visitor.Visit(Source1); var source2 = (SelectExpression)visitor.Visit(Source2); @@ -53,20 +50,13 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// The property of the result. /// This expression if no children changed, or an expression with the updated children. public virtual IntersectExpression Update(SelectExpression source1, SelectExpression source2) - { - Check.NotNull(source1, nameof(source1)); - Check.NotNull(source2, nameof(source2)); - - return source1 != Source1 || source2 != Source2 + => source1 != Source1 || source2 != Source2 ? new IntersectExpression(Alias, source1, source2, IsDistinct) : this; - } /// protected override void Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - expressionPrinter.Append("("); using (expressionPrinter.Indent()) { diff --git a/src/EFCore.Relational/Query/SqlExpressions/JoinExpressionBase.cs b/src/EFCore.Relational/Query/SqlExpressions/JoinExpressionBase.cs index 9aa12c54ab1..07062294345 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/JoinExpressionBase.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/JoinExpressionBase.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -24,8 +23,6 @@ public abstract class JoinExpressionBase : TableExpressionBase protected JoinExpressionBase(TableExpressionBase table) : base(null) { - Check.NotNull(table, nameof(table)); - Table = table; } diff --git a/src/EFCore.Relational/Query/SqlExpressions/LeftJoinExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/LeftJoinExpression.cs index fd545ad5052..e8532abd634 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/LeftJoinExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/LeftJoinExpression.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Linq.Expressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -30,8 +29,6 @@ public LeftJoinExpression(TableExpressionBase table, SqlExpression joinPredicate /// protected override Expression VisitChildren(ExpressionVisitor visitor) { - Check.NotNull(visitor, nameof(visitor)); - var table = (TableExpressionBase)visitor.Visit(Table); var joinPredicate = (SqlExpression)visitor.Visit(JoinPredicate); @@ -46,20 +43,13 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// The property of the result. /// This expression if no children changed, or an expression with the updated children. public virtual LeftJoinExpression Update(TableExpressionBase table, SqlExpression joinPredicate) - { - Check.NotNull(table, nameof(table)); - Check.NotNull(joinPredicate, nameof(joinPredicate)); - - return table != Table || joinPredicate != JoinPredicate + => table != Table || joinPredicate != JoinPredicate ? new LeftJoinExpression(table, joinPredicate) : this; - } /// protected override void Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - expressionPrinter.Append("LEFT JOIN "); expressionPrinter.Visit(Table); expressionPrinter.Append(" ON "); diff --git a/src/EFCore.Relational/Query/SqlExpressions/LikeExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/LikeExpression.cs index 160acc39c95..c3ef21c7818 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/LikeExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/LikeExpression.cs @@ -4,7 +4,6 @@ using System; using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -33,9 +32,6 @@ public LikeExpression( RelationalTypeMapping? typeMapping) : base(typeof(bool), typeMapping) { - Check.NotNull(match, nameof(match)); - Check.NotNull(pattern, nameof(pattern)); - Match = match; Pattern = pattern; EscapeChar = escapeChar; @@ -59,8 +55,6 @@ public LikeExpression( /// protected override Expression VisitChildren(ExpressionVisitor visitor) { - Check.NotNull(visitor, nameof(visitor)); - var match = (SqlExpression)visitor.Visit(Match); var pattern = (SqlExpression)visitor.Visit(Pattern); var escapeChar = (SqlExpression?)visitor.Visit(EscapeChar); @@ -80,20 +74,13 @@ public virtual LikeExpression Update( SqlExpression match, SqlExpression pattern, SqlExpression? escapeChar) - { - Check.NotNull(match, nameof(match)); - Check.NotNull(pattern, nameof(pattern)); - - return match != Match || pattern != Pattern || escapeChar != EscapeChar + => match != Match || pattern != Pattern || escapeChar != EscapeChar ? new LikeExpression(match, pattern, escapeChar, TypeMapping) : this; - } /// protected override void Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - expressionPrinter.Visit(Match); expressionPrinter.Append(" LIKE "); expressionPrinter.Visit(Pattern); diff --git a/src/EFCore.Relational/Query/SqlExpressions/OrderingExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/OrderingExpression.cs index cc497c0057b..2e11e6023f4 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/OrderingExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/OrderingExpression.cs @@ -3,7 +3,6 @@ using System; using System.Linq.Expressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -25,8 +24,6 @@ public class OrderingExpression : Expression, IPrintableExpression /// A value indicating if the ordering is ascending. public OrderingExpression(SqlExpression expression, bool ascending) { - Check.NotNull(expression, nameof(expression)); - Expression = expression; IsAscending = ascending; } @@ -51,11 +48,7 @@ public override Type Type /// protected override Expression VisitChildren(ExpressionVisitor visitor) - { - Check.NotNull(visitor, nameof(visitor)); - - return Update((SqlExpression)visitor.Visit(Expression)); - } + => Update((SqlExpression)visitor.Visit(Expression)); /// /// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will @@ -64,19 +57,13 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// The property of the result. /// This expression if no children changed, or an expression with the updated children. public virtual OrderingExpression Update(SqlExpression expression) - { - Check.NotNull(expression, nameof(expression)); - - return expression != Expression + => expression != Expression ? new OrderingExpression(expression, IsAscending) : this; - } /// void IPrintableExpression.Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - expressionPrinter.Visit(Expression); expressionPrinter.Append(IsAscending ? " ASC" : " DESC"); diff --git a/src/EFCore.Relational/Query/SqlExpressions/OuterApplyExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/OuterApplyExpression.cs index 7e708aa63c0..05dd6270c02 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/OuterApplyExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/OuterApplyExpression.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Linq.Expressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -28,11 +27,7 @@ public OuterApplyExpression(TableExpressionBase table) /// protected override Expression VisitChildren(ExpressionVisitor visitor) - { - Check.NotNull(visitor, nameof(visitor)); - - return Update((TableExpressionBase)visitor.Visit(Table)); - } + => Update((TableExpressionBase)visitor.Visit(Table)); /// /// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will @@ -41,19 +36,13 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// The property of the result. /// This expression if no children changed, or an expression with the updated children. public virtual OuterApplyExpression Update(TableExpressionBase table) - { - Check.NotNull(table, nameof(table)); - - return table != Table + => table != Table ? new OuterApplyExpression(table) : this; - } /// protected override void Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - expressionPrinter.Append("OUTER APPLY "); expressionPrinter.Visit(Table); } diff --git a/src/EFCore.Relational/Query/SqlExpressions/PredicateJoinExpressionBase.cs b/src/EFCore.Relational/Query/SqlExpressions/PredicateJoinExpressionBase.cs index 8a854fc927f..c3dee36d38b 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/PredicateJoinExpressionBase.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/PredicateJoinExpressionBase.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -25,8 +24,6 @@ public abstract class PredicateJoinExpressionBase : JoinExpressionBase protected PredicateJoinExpressionBase(TableExpressionBase table, SqlExpression joinPredicate) : base(table) { - Check.NotNull(joinPredicate, nameof(joinPredicate)); - JoinPredicate = joinPredicate; } diff --git a/src/EFCore.Relational/Query/SqlExpressions/ProjectionExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/ProjectionExpression.cs index f336a524777..41bbf75aaa1 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/ProjectionExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/ProjectionExpression.cs @@ -3,7 +3,6 @@ using System; using System.Linq.Expressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -19,9 +18,6 @@ public sealed class ProjectionExpression : Expression, IPrintableExpression { internal ProjectionExpression(SqlExpression expression, string alias) { - Check.NotNull(expression, nameof(expression)); - Check.NotNull(alias, nameof(alias)); - Expression = expression; Alias = alias; } @@ -46,11 +42,7 @@ public override ExpressionType NodeType /// protected override Expression VisitChildren(ExpressionVisitor visitor) - { - Check.NotNull(visitor, nameof(visitor)); - - return Update((SqlExpression)visitor.Visit(Expression)); - } + => Update((SqlExpression)visitor.Visit(Expression)); /// /// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will @@ -59,19 +51,13 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// The property of the result. /// This expression if no children changed, or an expression with the updated children. public ProjectionExpression Update(SqlExpression expression) - { - Check.NotNull(expression, nameof(expression)); - - return expression != Expression + => expression != Expression ? new ProjectionExpression(expression, Alias) : this; - } /// void IPrintableExpression.Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - expressionPrinter.Visit(Expression); if (Alias != string.Empty && !(Expression is ColumnExpression column diff --git a/src/EFCore.Relational/Query/SqlExpressions/RowNumberExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/RowNumberExpression.cs index 9afc2b5f39b..0bb1c94199e 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/RowNumberExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/RowNumberExpression.cs @@ -6,7 +6,6 @@ using System.Linq; using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -33,8 +32,6 @@ public RowNumberExpression( RelationalTypeMapping? typeMapping) : base(typeof(long), typeMapping) { - Check.NotEmpty(orderings, nameof(orderings)); - Partitions = partitions ?? Array.Empty(); Orderings = orderings; } @@ -52,8 +49,6 @@ public RowNumberExpression( /// protected override Expression VisitChildren(ExpressionVisitor visitor) { - Check.NotNull(visitor, nameof(visitor)); - var changed = false; var partitions = new List(); foreach (var partition in Partitions) @@ -86,21 +81,15 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) public virtual RowNumberExpression Update( IReadOnlyList? partitions, IReadOnlyList orderings) - { - Check.NotNull(orderings, nameof(orderings)); - - return ((Partitions == null && partitions == null) + => ((Partitions == null && partitions == null) || (Partitions != null && partitions != null && Partitions.SequenceEqual(partitions))) && Orderings.SequenceEqual(orderings) ? this : new RowNumberExpression(partitions, orderings, TypeMapping); - } /// protected override void Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - expressionPrinter.Append("ROW_NUMBER() OVER("); if (Partitions.Any()) { diff --git a/src/EFCore.Relational/Query/SqlExpressions/ScalarSubqueryExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/ScalarSubqueryExpression.cs index df5121460d4..dd84a683073 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/ScalarSubqueryExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/ScalarSubqueryExpression.cs @@ -5,7 +5,6 @@ using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -27,8 +26,6 @@ public class ScalarSubqueryExpression : SqlExpression public ScalarSubqueryExpression(SelectExpression subquery) : base(Verify(subquery).Projection[0].Type, subquery.Projection[0].Expression.TypeMapping) { - Check.NotNull(subquery, nameof(subquery)); - Subquery = subquery; } @@ -49,11 +46,7 @@ private static SelectExpression Verify(SelectExpression selectExpression) /// protected override Expression VisitChildren(ExpressionVisitor visitor) - { - Check.NotNull(visitor, nameof(visitor)); - - return Update((SelectExpression)visitor.Visit(Subquery)); - } + => Update((SelectExpression)visitor.Visit(Subquery)); /// /// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will @@ -62,19 +55,13 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// The property of the result. /// This expression if no children changed, or an expression with the updated children. public virtual ScalarSubqueryExpression Update(SelectExpression subquery) - { - Check.NotNull(subquery, nameof(subquery)); - - return subquery != Subquery + => subquery != Subquery ? new ScalarSubqueryExpression(subquery) : this; - } /// protected override void Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - expressionPrinter.Append("("); using (expressionPrinter.Indent()) { diff --git a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.Helper.cs b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.Helper.cs index 22f270f7e7a..11144a5ca7b 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.Helper.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.Helper.cs @@ -18,13 +18,9 @@ public sealed partial class SelectExpression 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 SelectExpressionCorrelationFindingExpressionVisitor : ExpressionVisitor @@ -448,10 +444,6 @@ public ConcreteColumnExpression( bool nullable) : base(type, typeMapping) { - Check.NotEmpty(name, nameof(name)); - Check.NotNull(table, nameof(table)); - Check.NotEmpty(table.Alias, $"{nameof(table)}.{nameof(table.Alias)}"); - Name = name; _table = table; IsNullable = nullable; @@ -469,11 +461,7 @@ public override string TableAlias /// protected override Expression VisitChildren(ExpressionVisitor visitor) - { - Check.NotNull(visitor, nameof(visitor)); - - return this; - } + => this; public override ConcreteColumnExpression MakeNullable() => new(Name, _table, Type, TypeMapping!, true); diff --git a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs index 7da958e12cf..eea714da5e2 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs @@ -312,8 +312,6 @@ public IReadOnlyList Orderings /// A list of tags to apply. public void ApplyTags(ISet tags) { - Check.NotNull(tags, nameof(tags)); - Tags = tags; } @@ -1015,11 +1013,7 @@ public Expression GetProjection(ProjectionBindingExpression projectionBindingExp /// An expression to add. /// An int value indicating the index at which the expression was added in the projection list. public int AddToProjection(SqlExpression sqlExpression) - { - Check.NotNull(sqlExpression, nameof(sqlExpression)); - - return AddToProjection(sqlExpression, null); - } + => AddToProjection(sqlExpression, null); private int AddToProjection(SqlExpression sqlExpression, string? alias, bool assignUniqueTableAlias = true) { @@ -1064,8 +1058,6 @@ private int AddToProjection(SqlExpression sqlExpression, string? alias, bool ass /// An expression to use for filtering. public void ApplyPredicate(SqlExpression sqlExpression) { - Check.NotNull(sqlExpression, nameof(sqlExpression)); - if (sqlExpression is SqlConstantExpression sqlConstant && sqlConstant.Value is bool boolValue && boolValue) @@ -1112,8 +1104,6 @@ public void ApplyPredicate(SqlExpression sqlExpression) /// An key selector expression for the GROUP BY. public void ApplyGrouping(Expression keySelector) { - Check.NotNull(keySelector, nameof(keySelector)); - ClearOrdering(); var groupByTerms = new List(); @@ -1163,10 +1153,6 @@ public GroupByShaperExpression ApplyGrouping( Expression shaperExpression, ISqlExpressionFactory sqlExpressionFactory) { - Check.NotNull(keySelector, nameof(keySelector)); - Check.NotNull(shaperExpression, nameof(shaperExpression)); - Check.NotNull(sqlExpressionFactory, nameof(sqlExpressionFactory)); - ClearOrdering(); var keySelectorToAdd = keySelector; @@ -1239,8 +1225,6 @@ private void PopulateGroupByTerms( List groupByAliases, string? name) { - Check.NotNull(keySelector, nameof(keySelector)); - switch (keySelector) { case SqlExpression sqlExpression: @@ -1283,8 +1267,6 @@ private void PopulateGroupByTerms( /// An ordering expression to use for ordering. public void ApplyOrdering(OrderingExpression orderingExpression) { - Check.NotNull(orderingExpression, nameof(orderingExpression)); - if (IsDistinct || Limit != null || Offset != null) @@ -1302,8 +1284,6 @@ public void ApplyOrdering(OrderingExpression orderingExpression) /// An ordering expression to use for ordering. public void AppendOrdering(OrderingExpression orderingExpression) { - Check.NotNull(orderingExpression, nameof(orderingExpression)); - if (_groupBy.Count > 0) { orderingExpression = orderingExpression.Update( @@ -1357,8 +1337,6 @@ public void ClearOrdering() /// An expression representing limit row count. public void ApplyLimit(SqlExpression sqlExpression) { - Check.NotNull(sqlExpression, nameof(sqlExpression)); - if (Limit != null) { PushdownIntoSubquery(); @@ -1373,8 +1351,6 @@ public void ApplyLimit(SqlExpression sqlExpression) /// An expression representing offset row count. public void ApplyOffset(SqlExpression sqlExpression) { - Check.NotNull(sqlExpression, nameof(sqlExpression)); - if (Limit != null || Offset != null || (IsDistinct && Orderings.Count == 0)) @@ -1398,11 +1374,7 @@ private enum SetOperationType /// A to perform the operation. /// A bool value indicating if resulting table source should remove duplicates. public void ApplyExcept(SelectExpression source2, bool distinct) - { - Check.NotNull(source2, nameof(source2)); - - ApplySetOperation(SetOperationType.Except, source2, distinct); - } + => ApplySetOperation(SetOperationType.Except, source2, distinct); /// /// Applies INTERSECT operation to the . @@ -1410,11 +1382,7 @@ public void ApplyExcept(SelectExpression source2, bool distinct) /// A to perform the operation. /// A bool value indicating if resulting table source should remove duplicates. public void ApplyIntersect(SelectExpression source2, bool distinct) - { - Check.NotNull(source2, nameof(source2)); - - ApplySetOperation(SetOperationType.Intersect, source2, distinct); - } + => ApplySetOperation(SetOperationType.Intersect, source2, distinct); /// /// Applies UNION operation to the . @@ -1422,11 +1390,7 @@ public void ApplyIntersect(SelectExpression source2, bool distinct) /// A to perform the operation. /// A bool value indicating if resulting table source should remove duplicates. public void ApplyUnion(SelectExpression source2, bool distinct) - { - Check.NotNull(source2, nameof(source2)); - - ApplySetOperation(SetOperationType.Union, source2, distinct); - } + => ApplySetOperation(SetOperationType.Union, source2, distinct); private void ApplySetOperation(SetOperationType setOperationType, SelectExpression select2, bool distinct) { @@ -1721,8 +1685,6 @@ static bool IsNullableProjection(ProjectionExpression projectionExpression) /// A factory to use for generating required sql expressions. public void ApplyDefaultIfEmpty(ISqlExpressionFactory sqlExpressionFactory) { - Check.NotNull(sqlExpressionFactory, nameof(sqlExpressionFactory)); - var nullSqlExpression = sqlExpressionFactory.ApplyDefaultTypeMapping( new SqlConstantExpression(Constant(null, typeof(string)), null)); @@ -2477,12 +2439,7 @@ static List ExtractColumnsFromProjectionMapping( /// A to join with. /// A predicate to use for the join. public void AddInnerJoin(SelectExpression innerSelectExpression, SqlExpression joinPredicate) - { - Check.NotNull(innerSelectExpression, nameof(innerSelectExpression)); - Check.NotNull(joinPredicate, nameof(joinPredicate)); - - AddJoin(JoinType.InnerJoin, ref innerSelectExpression, joinPredicate); - } + => AddJoin(JoinType.InnerJoin, ref innerSelectExpression, joinPredicate); /// /// Adds the given to table sources using LEFT JOIN. @@ -2490,45 +2447,28 @@ public void AddInnerJoin(SelectExpression innerSelectExpression, SqlExpression j /// A to join with. /// A predicate to use for the join. public void AddLeftJoin(SelectExpression innerSelectExpression, SqlExpression joinPredicate) - { - Check.NotNull(innerSelectExpression, nameof(innerSelectExpression)); - Check.NotNull(joinPredicate, nameof(joinPredicate)); - - AddJoin(JoinType.LeftJoin, ref innerSelectExpression, joinPredicate); - } + => AddJoin(JoinType.LeftJoin, ref innerSelectExpression, joinPredicate); /// /// Adds the given to table sources using CROSS JOIN. /// /// A to join with. public void AddCrossJoin(SelectExpression innerSelectExpression) - { - Check.NotNull(innerSelectExpression, nameof(innerSelectExpression)); - - AddJoin(JoinType.CrossJoin, ref innerSelectExpression); - } + => AddJoin(JoinType.CrossJoin, ref innerSelectExpression); /// /// Adds the given to table sources using CROSS APPLY. /// /// A to join with. public void AddCrossApply(SelectExpression innerSelectExpression) - { - Check.NotNull(innerSelectExpression, nameof(innerSelectExpression)); - - AddJoin(JoinType.CrossApply, ref innerSelectExpression); - } + => AddJoin(JoinType.CrossApply, ref innerSelectExpression); /// /// Adds the given to table sources using OUTER APPLY. /// /// A to join with. public void AddOuterApply(SelectExpression innerSelectExpression) - { - Check.NotNull(innerSelectExpression, nameof(innerSelectExpression)); - - AddJoin(JoinType.OuterApply, ref innerSelectExpression); - } + => AddJoin(JoinType.OuterApply, ref innerSelectExpression); /// /// Adds the query expression of the given to table sources using INNER JOIN and combine shapers. @@ -2541,15 +2481,9 @@ public Expression AddInnerJoin( ShapedQueryExpression innerSource, SqlExpression joinPredicate, Expression outerShaper) - { - Check.NotNull(innerSource, nameof(innerSource)); - Check.NotNull(joinPredicate, nameof(joinPredicate)); - Check.NotNull(outerShaper, nameof(outerShaper)); - - return AddJoin( + => AddJoin( JoinType.InnerJoin, (SelectExpression)innerSource.QueryExpression, outerShaper, innerSource.ShaperExpression, joinPredicate); - } /// /// Adds the query expression of the given to table sources using LEFT JOIN and combine shapers. @@ -2562,14 +2496,8 @@ public Expression AddLeftJoin( ShapedQueryExpression innerSource, SqlExpression joinPredicate, Expression outerShaper) - { - Check.NotNull(innerSource, nameof(innerSource)); - Check.NotNull(joinPredicate, nameof(joinPredicate)); - Check.NotNull(outerShaper, nameof(outerShaper)); - - return AddJoin( + => AddJoin( JoinType.LeftJoin, (SelectExpression)innerSource.QueryExpression, outerShaper, innerSource.ShaperExpression, joinPredicate); - } /// /// Adds the query expression of the given to table sources using CROSS JOIN and combine shapers. @@ -2580,12 +2508,7 @@ public Expression AddLeftJoin( public Expression AddCrossJoin( ShapedQueryExpression innerSource, Expression outerShaper) - { - Check.NotNull(innerSource, nameof(innerSource)); - Check.NotNull(outerShaper, nameof(outerShaper)); - - return AddJoin(JoinType.CrossJoin, (SelectExpression)innerSource.QueryExpression, outerShaper, innerSource.ShaperExpression); - } + => AddJoin(JoinType.CrossJoin, (SelectExpression)innerSource.QueryExpression, outerShaper, innerSource.ShaperExpression); /// /// Adds the query expression of the given to table sources using CROSS APPLY and combine shapers. @@ -2596,12 +2519,7 @@ public Expression AddCrossJoin( public Expression AddCrossApply( ShapedQueryExpression innerSource, Expression outerShaper) - { - Check.NotNull(innerSource, nameof(innerSource)); - Check.NotNull(outerShaper, nameof(outerShaper)); - - return AddJoin(JoinType.CrossApply, (SelectExpression)innerSource.QueryExpression, outerShaper, innerSource.ShaperExpression); - } + => AddJoin(JoinType.CrossApply, (SelectExpression)innerSource.QueryExpression, outerShaper, innerSource.ShaperExpression); /// /// Adds the query expression of the given to table sources using OUTER APPLY and combine shapers. @@ -2612,12 +2530,7 @@ public Expression AddCrossApply( public Expression AddOuterApply( ShapedQueryExpression innerSource, Expression outerShaper) - { - Check.NotNull(innerSource, nameof(innerSource)); - Check.NotNull(outerShaper, nameof(outerShaper)); - - return AddJoin(JoinType.OuterApply, (SelectExpression)innerSource.QueryExpression, outerShaper, innerSource.ShaperExpression); - } + => AddJoin(JoinType.OuterApply, (SelectExpression)innerSource.QueryExpression, outerShaper, innerSource.ShaperExpression); /// /// Pushes down the into a subquery. @@ -3112,8 +3025,6 @@ private static string GenerateUniqueAlias(HashSet usedAliases, string cu /// protected override Expression VisitChildren(ExpressionVisitor visitor) { - Check.NotNull(visitor, nameof(visitor)); - if (_projection.Count == 0) { // If projection is not populated then we need to treat this as mutable object since it is not final yet. @@ -3370,11 +3281,6 @@ public SelectExpression Update( SqlExpression? limit, SqlExpression? offset) { - Check.NotNull(projections, nameof(projections)); - Check.NotNull(tables, nameof(tables)); - Check.NotNull(groupBy, nameof(groupBy)); - Check.NotNull(orderings, nameof(orderings)); - var projectionMapping = new Dictionary(); foreach (var kvp in _projectionMapping) { @@ -3412,8 +3318,6 @@ public SelectExpression Update( /// protected override void Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - if (_clientProjections.Count > 0) { expressionPrinter.AppendLine("Client Projections:"); diff --git a/src/EFCore.Relational/Query/SqlExpressions/SetOperationBase.cs b/src/EFCore.Relational/Query/SqlExpressions/SetOperationBase.cs index c47e9f8e821..36e813c59d2 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SetOperationBase.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SetOperationBase.cs @@ -3,7 +3,6 @@ using System; using System.Diagnostics.CodeAnalysis; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -30,11 +29,8 @@ protected SetOperationBase( SelectExpression source1, SelectExpression source2, bool distinct) - : base(Check.NotEmpty(alias, nameof(alias))) + : base(alias) { - Check.NotNull(source1, nameof(source1)); - Check.NotNull(source2, nameof(source2)); - IsDistinct = distinct; Source1 = source1; Source2 = source2; diff --git a/src/EFCore.Relational/Query/SqlExpressions/SqlBinaryExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SqlBinaryExpression.cs index 636b0fb5ed2..21a512e59c4 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SqlBinaryExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SqlBinaryExpression.cs @@ -7,7 +7,6 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -65,9 +64,6 @@ public SqlBinaryExpression( RelationalTypeMapping? typeMapping) : base(type, typeMapping) { - Check.NotNull(left, nameof(left)); - Check.NotNull(right, nameof(right)); - if (!IsValidOperator(operatorType)) { throw new InvalidOperationException( @@ -98,8 +94,6 @@ public SqlBinaryExpression( /// protected override Expression VisitChildren(ExpressionVisitor visitor) { - Check.NotNull(visitor, nameof(visitor)); - var left = (SqlExpression)visitor.Visit(Left); var right = (SqlExpression)visitor.Visit(Right); @@ -114,20 +108,13 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// The property of the result. /// This expression if no children changed, or an expression with the updated children. public virtual SqlBinaryExpression Update(SqlExpression left, SqlExpression right) - { - Check.NotNull(left, nameof(left)); - Check.NotNull(right, nameof(right)); - - return left != Left || right != Right + => left != Left || right != Right ? new SqlBinaryExpression(OperatorType, left, right, Type, TypeMapping) : this; - } /// protected override void Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - var requiresBrackets = RequiresBrackets(Left); if (requiresBrackets) diff --git a/src/EFCore.Relational/Query/SqlExpressions/SqlConstantExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SqlConstantExpression.cs index e6f2d1af297..d539e197da5 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SqlConstantExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SqlConstantExpression.cs @@ -5,7 +5,6 @@ using System.Collections; using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -28,7 +27,7 @@ public class SqlConstantExpression : SqlExpression /// A . /// The associated with the expression. public SqlConstantExpression(ConstantExpression constantExpression, RelationalTypeMapping? typeMapping) - : base(Check.NotNull(constantExpression, nameof(constantExpression)).Type.UnwrapNullableType(), typeMapping) + : base(constantExpression.Type.UnwrapNullableType(), typeMapping) { _constantExpression = constantExpression; } @@ -49,19 +48,11 @@ public virtual SqlExpression ApplyTypeMapping(RelationalTypeMapping? typeMapping /// protected override Expression VisitChildren(ExpressionVisitor visitor) - { - Check.NotNull(visitor, nameof(visitor)); - - return this; - } + => this; /// protected override void Print(ExpressionPrinter expressionPrinter) - { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - - Print(Value, expressionPrinter); - } + => Print(Value, expressionPrinter); private void Print(object? value, ExpressionPrinter expressionPrinter) => expressionPrinter.Append(TypeMapping?.GenerateSqlLiteral(value) ?? Value?.ToString() ?? "NULL"); diff --git a/src/EFCore.Relational/Query/SqlExpressions/SqlExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SqlExpression.cs index 6ac0b76c09b..927c27b0621 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SqlExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SqlExpression.cs @@ -27,8 +27,6 @@ public abstract class SqlExpression : Expression, IPrintableExpression /// The associated with the expression. protected SqlExpression(Type type, RelationalTypeMapping? typeMapping) { - Check.NotNull(type, nameof(type)); - Check.DebugAssert(!type.IsNullableValueType(), "SqlExpression.Type must be reference type or non-nullable value type"); Type = type; diff --git a/src/EFCore.Relational/Query/SqlExpressions/SqlFragmentExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SqlFragmentExpression.cs index 4986ced452b..751c1229b30 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SqlFragmentExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SqlFragmentExpression.cs @@ -3,7 +3,6 @@ using System; using System.Linq.Expressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -25,8 +24,6 @@ public class SqlFragmentExpression : SqlExpression public SqlFragmentExpression(string sql) : base(typeof(string), null) { - Check.NotEmpty(sql, nameof(sql)); - Sql = sql; } @@ -37,19 +34,11 @@ public SqlFragmentExpression(string sql) /// protected override Expression VisitChildren(ExpressionVisitor visitor) - { - Check.NotNull(visitor, nameof(visitor)); - - return this; - } + => this; /// protected override void Print(ExpressionPrinter expressionPrinter) - { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - - expressionPrinter.Append(Sql); - } + => expressionPrinter.Append(Sql); /// public override bool Equals(object? obj) diff --git a/src/EFCore.Relational/Query/SqlExpressions/SqlFunctionExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SqlFunctionExpression.cs index 7ce00a2ae94..4cd1627421f 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SqlFunctionExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SqlFunctionExpression.cs @@ -3,12 +3,10 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -55,7 +53,7 @@ public SqlFunctionExpression( Type type, RelationalTypeMapping? typeMapping) : this( - instance: null, Check.NotEmpty(schema, nameof(schema)), functionName, nullable, instancePropagatesNullability: null, + instance: null, schema, functionName, nullable, instancePropagatesNullability: null, builtIn: false, type, typeMapping) { } @@ -78,7 +76,7 @@ public SqlFunctionExpression( Type type, RelationalTypeMapping? typeMapping) : this( - Check.NotNull(instance, nameof(instance)), schema: null, functionName, nullable, instancePropagatesNullability, + instance, schema: null, functionName, nullable, instancePropagatesNullability, builtIn: true, type, typeMapping) { } @@ -139,7 +137,7 @@ public SqlFunctionExpression( Type type, RelationalTypeMapping? typeMapping) : this( - instance: null, Check.NullButNotEmpty(schema, nameof(schema)), functionName, arguments, nullable, + instance: null, schema, functionName, arguments, nullable, instancePropagatesNullability: null, argumentsPropagateNullability, builtIn: false, type, typeMapping) { } @@ -165,7 +163,7 @@ public SqlFunctionExpression( Type type, RelationalTypeMapping? typeMapping) : this( - Check.NotNull(instance, nameof(instance)), schema: null, functionName, arguments, nullable, instancePropagatesNullability, + instance, schema: null, functionName, arguments, nullable, instancePropagatesNullability, argumentsPropagateNullability, builtIn: true, type, typeMapping) { } @@ -182,8 +180,8 @@ private SqlFunctionExpression( Type type, RelationalTypeMapping? typeMapping) : this( - instance, schema, name, niladic: false, Check.NotNull(arguments, nameof(arguments)), nullable, - instancePropagatesNullability, Check.NotNull(argumentsPropagateNullability, nameof(argumentsPropagateNullability)), builtIn, + instance, schema, name, niladic: false, arguments, nullable, + instancePropagatesNullability, argumentsPropagateNullability, builtIn, type, typeMapping) { } @@ -202,9 +200,6 @@ private SqlFunctionExpression( RelationalTypeMapping? typeMapping) : base(type, typeMapping) { - Check.NotEmpty(name, nameof(name)); - Check.NotNull(type, nameof(type)); - Instance = instance; Name = name; Schema = schema; @@ -266,8 +261,6 @@ private SqlFunctionExpression( /// protected override Expression VisitChildren(ExpressionVisitor visitor) { - Check.NotNull(visitor, nameof(visitor)); - var changed = false; var instance = (SqlExpression?)visitor.Visit(Instance); changed |= instance != Instance; @@ -346,8 +339,6 @@ public virtual SqlFunctionExpression Update(SqlExpression? instance, IReadOnlyLi /// protected override void Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - if (!string.IsNullOrEmpty(Schema)) { expressionPrinter.Append(Schema).Append(".").Append(Name); diff --git a/src/EFCore.Relational/Query/SqlExpressions/SqlParameterExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SqlParameterExpression.cs index 71eb25d4281..4787578d231 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SqlParameterExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SqlParameterExpression.cs @@ -52,19 +52,11 @@ public SqlExpression ApplyTypeMapping(RelationalTypeMapping? typeMapping) /// protected override Expression VisitChildren(ExpressionVisitor visitor) - { - Check.NotNull(visitor, nameof(visitor)); - - return this; - } + => this; /// protected override void Print(ExpressionPrinter expressionPrinter) - { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - - expressionPrinter.Append("@" + _parameterExpression.Name); - } + => expressionPrinter.Append("@" + _parameterExpression.Name); /// public override bool Equals(object? obj) diff --git a/src/EFCore.Relational/Query/SqlExpressions/SqlUnaryExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SqlUnaryExpression.cs index 20a57984221..3a324ac62eb 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SqlUnaryExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SqlUnaryExpression.cs @@ -48,9 +48,6 @@ public SqlUnaryExpression( RelationalTypeMapping? typeMapping) : base(type, typeMapping) { - Check.NotNull(operand, nameof(operand)); - Check.NotNull(type, nameof(type)); - if (!IsValidOperator(operatorType)) { throw new InvalidOperationException( @@ -74,11 +71,7 @@ public SqlUnaryExpression( /// protected override Expression VisitChildren(ExpressionVisitor visitor) - { - Check.NotNull(visitor, nameof(visitor)); - - return Update((SqlExpression)visitor.Visit(Operand)); - } + => Update((SqlExpression)visitor.Visit(Operand)); /// /// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will @@ -87,19 +80,13 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// The property of the result. /// This expression if no children changed, or an expression with the updated children. public virtual SqlUnaryExpression Update(SqlExpression operand) - { - Check.NotNull(operand, nameof(operand)); - - return operand != Operand + => operand != Operand ? new SqlUnaryExpression(OperatorType, operand, Type, TypeMapping) : this; - } /// protected override void Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - if (OperatorType == ExpressionType.Convert && TypeMapping != null) { diff --git a/src/EFCore.Relational/Query/SqlExpressions/TableExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/TableExpression.cs index c6781bdcb24..4627b5b35a7 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/TableExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/TableExpression.cs @@ -4,7 +4,6 @@ using System; using System.Diagnostics.CodeAnalysis; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -29,8 +28,6 @@ internal TableExpression(ITableBase table) /// protected override void Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - if (!string.IsNullOrEmpty(Schema)) { expressionPrinter.Append(Schema).Append("."); diff --git a/src/EFCore.Relational/Query/SqlExpressions/TableExpressionBase.cs b/src/EFCore.Relational/Query/SqlExpressions/TableExpressionBase.cs index 4f3944e8777..ce8dc53f0ae 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/TableExpressionBase.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/TableExpressionBase.cs @@ -3,7 +3,6 @@ using System; using System.Linq.Expressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -24,8 +23,6 @@ public abstract class TableExpressionBase : Expression, IPrintableExpression /// A string alias for the table source. protected TableExpressionBase(string? alias) { - Check.NullButNotEmpty(alias, nameof(alias)); - Alias = alias; } @@ -36,11 +33,7 @@ protected TableExpressionBase(string? alias) /// protected override Expression VisitChildren(ExpressionVisitor visitor) - { - Check.NotNull(visitor, nameof(visitor)); - - return this; - } + => this; /// public override Type Type diff --git a/src/EFCore.Relational/Query/SqlExpressions/TableValuedFunctionExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/TableValuedFunctionExpression.cs index 1800a6c4d44..35a25cf5714 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/TableValuedFunctionExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/TableValuedFunctionExpression.cs @@ -7,7 +7,6 @@ using System.Linq; using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -30,8 +29,8 @@ public class TableValuedFunctionExpression : TableExpressionBase public TableValuedFunctionExpression(IStoreFunction storeFunction, IReadOnlyList arguments) : this( storeFunction.Name.Substring(0, 1).ToLowerInvariant(), - Check.NotNull(storeFunction, nameof(storeFunction)), - Check.NotNull(arguments, nameof(arguments))) + storeFunction, + arguments) { } @@ -65,8 +64,6 @@ public override string? Alias /// protected override Expression VisitChildren(ExpressionVisitor visitor) { - Check.NotNull(visitor, nameof(visitor)); - var changed = false; var arguments = new SqlExpression[Arguments.Count]; for (var i = 0; i < arguments.Length; i++) @@ -87,13 +84,9 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// The property of the result. /// This expression if no children changed, or an expression with the updated children. public virtual TableValuedFunctionExpression Update(IReadOnlyList arguments) - { - Check.NotNull(arguments, nameof(arguments)); - - return !arguments.SequenceEqual(Arguments) + => !arguments.SequenceEqual(Arguments) ? new TableValuedFunctionExpression(Alias, StoreFunction, arguments) : this; - } /// protected override void Print(ExpressionPrinter expressionPrinter) diff --git a/src/EFCore.Relational/Query/SqlExpressions/UnionExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/UnionExpression.cs index 585303ea6b5..8adf39f4271 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/UnionExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/UnionExpression.cs @@ -3,7 +3,6 @@ using System; using System.Linq.Expressions; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { @@ -37,8 +36,6 @@ public UnionExpression( /// protected override Expression VisitChildren(ExpressionVisitor visitor) { - Check.NotNull(visitor, nameof(visitor)); - var source1 = (SelectExpression)visitor.Visit(Source1); var source2 = (SelectExpression)visitor.Visit(Source2); @@ -53,20 +50,13 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// The property of the result. /// This expression if no children changed, or an expression with the updated children. public virtual UnionExpression Update(SelectExpression source1, SelectExpression source2) - { - Check.NotNull(source1, nameof(source1)); - Check.NotNull(source2, nameof(source2)); - - return source1 != Source1 || source2 != Source2 + => source1 != Source1 || source2 != Source2 ? new UnionExpression(Alias, source1, source2, IsDistinct) : this; - } /// protected override void Print(ExpressionPrinter expressionPrinter) { - Check.NotNull(expressionPrinter, nameof(expressionPrinter)); - expressionPrinter.Append("("); using (expressionPrinter.Indent()) { diff --git a/src/EFCore.Relational/Query/SqlNullabilityProcessor.cs b/src/EFCore.Relational/Query/SqlNullabilityProcessor.cs index d1b6655738b..a82d0dfbf37 100644 --- a/src/EFCore.Relational/Query/SqlNullabilityProcessor.cs +++ b/src/EFCore.Relational/Query/SqlNullabilityProcessor.cs @@ -10,7 +10,6 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Query { @@ -40,8 +39,6 @@ public SqlNullabilityProcessor( RelationalParameterBasedSqlProcessorDependencies dependencies, bool useRelationalNulls) { - Check.NotNull(dependencies, nameof(dependencies)); - Dependencies = dependencies; _sqlExpressionFactory = dependencies.SqlExpressionFactory; @@ -78,9 +75,6 @@ public virtual SelectExpression Process( IReadOnlyDictionary parameterValues, out bool canCache) { - Check.NotNull(selectExpression, nameof(selectExpression)); - Check.NotNull(parameterValues, nameof(parameterValues)); - _canCache = true; _nonNullableColumns.Clear(); _nullValueColumns.Clear(); @@ -103,7 +97,7 @@ protected virtual void DoNotCache() /// /// A column expression to add. protected virtual void AddNonNullableColumn(ColumnExpression columnExpression) - => _nonNullableColumns.Add(Check.NotNull(columnExpression, nameof(columnExpression))); + => _nonNullableColumns.Add(columnExpression); /// /// Visits a . @@ -112,8 +106,6 @@ protected virtual void AddNonNullableColumn(ColumnExpression columnExpression) /// An optimized table expression base. protected virtual TableExpressionBase Visit(TableExpressionBase tableExpressionBase) { - Check.NotNull(tableExpressionBase, nameof(tableExpressionBase)); - switch (tableExpressionBase) { case CrossApplyExpression crossApplyExpression: @@ -201,8 +193,6 @@ protected virtual TableExpressionBase Visit(TableExpressionBase tableExpressionB /// An optimized select expression. protected virtual SelectExpression Visit(SelectExpression selectExpression) { - Check.NotNull(selectExpression, nameof(selectExpression)); - var changed = false; var projections = (List)selectExpression.Projection; for (var i = 0; i < selectExpression.Projection.Count; i++) @@ -429,8 +419,6 @@ protected virtual SqlExpression VisitCustomSqlExpression( /// An optimized sql expression. protected virtual SqlExpression VisitCase(CaseExpression caseExpression, bool allowOptimizedExpansion, out bool nullable) { - Check.NotNull(caseExpression, nameof(caseExpression)); - // if there is no 'else' there is a possibility of null, when none of the conditions are met // otherwise the result is nullable if any of the WhenClause results OR ElseResult is nullable nullable = caseExpression.ElseResult == null; @@ -515,11 +503,7 @@ protected virtual SqlExpression VisitCollate( CollateExpression collateExpression, bool allowOptimizedExpansion, out bool nullable) - { - Check.NotNull(collateExpression, nameof(collateExpression)); - - return collateExpression.Update(Visit(collateExpression.Operand, out nullable)); - } + => collateExpression.Update(Visit(collateExpression.Operand, out nullable)); /// /// Visits a and computes its nullability. @@ -533,8 +517,6 @@ protected virtual SqlExpression VisitColumn( bool allowOptimizedExpansion, out bool nullable) { - Check.NotNull(columnExpression, nameof(columnExpression)); - nullable = columnExpression.IsNullable && !_nonNullableColumns.Contains(columnExpression); return columnExpression; @@ -551,11 +533,7 @@ protected virtual SqlExpression VisitDistinct( DistinctExpression distinctExpression, bool allowOptimizedExpansion, out bool nullable) - { - Check.NotNull(distinctExpression, nameof(distinctExpression)); - - return distinctExpression.Update(Visit(distinctExpression.Operand, out nullable)); - } + => distinctExpression.Update(Visit(distinctExpression.Operand, out nullable)); /// /// Visits an and computes its nullability. @@ -569,8 +547,6 @@ protected virtual SqlExpression VisitExists( bool allowOptimizedExpansion, out bool nullable) { - Check.NotNull(existsExpression, nameof(existsExpression)); - var subquery = Visit(existsExpression.Subquery); nullable = false; @@ -590,8 +566,6 @@ protected virtual SqlExpression VisitExists( /// An optimized sql expression. protected virtual SqlExpression VisitIn(InExpression inExpression, bool allowOptimizedExpansion, out bool nullable) { - Check.NotNull(inExpression, nameof(inExpression)); - var item = Visit(inExpression.Item, out var itemNullable); if (inExpression.Subquery != null) @@ -753,8 +727,6 @@ SqlExpression SimplifyInExpression( /// An optimized sql expression. protected virtual SqlExpression VisitLike(LikeExpression likeExpression, bool allowOptimizedExpansion, out bool nullable) { - Check.NotNull(likeExpression, nameof(likeExpression)); - var match = Visit(likeExpression.Match, out var matchNullable); var pattern = Visit(likeExpression.Pattern, out var patternNullable); var escapeChar = Visit(likeExpression.EscapeChar, out var escapeCharNullable); @@ -776,8 +748,6 @@ protected virtual SqlExpression VisitRowNumber( bool allowOptimizedExpansion, out bool nullable) { - Check.NotNull(rowNumberExpression, nameof(rowNumberExpression)); - var changed = false; var partitions = new List(); foreach (var partition in rowNumberExpression.Partitions) @@ -814,8 +784,6 @@ protected virtual SqlExpression VisitScalarSubquery( bool allowOptimizedExpansion, out bool nullable) { - Check.NotNull(scalarSubqueryExpression, nameof(scalarSubqueryExpression)); - nullable = true; return scalarSubqueryExpression.Update(Visit(scalarSubqueryExpression.Subquery)); @@ -833,8 +801,6 @@ protected virtual SqlExpression VisitSqlBinary( bool allowOptimizedExpansion, out bool nullable) { - Check.NotNull(sqlBinaryExpression, nameof(sqlBinaryExpression)); - var optimize = allowOptimizedExpansion; allowOptimizedExpansion = allowOptimizedExpansion @@ -992,8 +958,6 @@ protected virtual SqlExpression VisitSqlConstant( bool allowOptimizedExpansion, out bool nullable) { - Check.NotNull(sqlConstantExpression, nameof(sqlConstantExpression)); - nullable = sqlConstantExpression.Value == null; return sqlConstantExpression; @@ -1011,8 +975,6 @@ protected virtual SqlExpression VisitSqlFragment( bool allowOptimizedExpansion, out bool nullable) { - Check.NotNull(sqlFragmentExpression, nameof(sqlFragmentExpression)); - nullable = false; return sqlFragmentExpression; @@ -1030,8 +992,6 @@ protected virtual SqlExpression VisitSqlFunction( bool allowOptimizedExpansion, out bool nullable) { - Check.NotNull(sqlFunctionExpression, nameof(sqlFunctionExpression)); - if (sqlFunctionExpression.IsBuiltIn && sqlFunctionExpression.Arguments != null && string.Equals(sqlFunctionExpression.Name, "COALESCE", StringComparison.OrdinalIgnoreCase)) @@ -1089,8 +1049,6 @@ protected virtual SqlExpression VisitSqlParameter( bool allowOptimizedExpansion, out bool nullable) { - Check.NotNull(sqlParameterExpression, nameof(sqlParameterExpression)); - nullable = ParameterValues[sqlParameterExpression.Name] == null; return nullable @@ -1110,8 +1068,6 @@ protected virtual SqlExpression VisitSqlUnary( bool allowOptimizedExpansion, out bool nullable) { - Check.NotNull(sqlUnaryExpression, nameof(sqlUnaryExpression)); - var operand = Visit(sqlUnaryExpression.Operand, out var operandNullable); var updated = sqlUnaryExpression.Update(operand); diff --git a/src/EFCore.Relational/Scaffolding/ProviderCodeGenerator.cs b/src/EFCore.Relational/Scaffolding/ProviderCodeGenerator.cs index 3b198153c4c..e0647ba9be4 100644 --- a/src/EFCore.Relational/Scaffolding/ProviderCodeGenerator.cs +++ b/src/EFCore.Relational/Scaffolding/ProviderCodeGenerator.cs @@ -28,7 +28,9 @@ public abstract class ProviderCodeGenerator : IProviderConfigurationCodeGenerato /// /// The dependencies. protected ProviderCodeGenerator(ProviderCodeGeneratorDependencies dependencies) - => Dependencies = Check.NotNull(dependencies, nameof(dependencies)); + { + Dependencies = dependencies; + } /// /// Relational provider-specific dependencies for this service. diff --git a/src/EFCore.Relational/Scaffolding/ProviderCodeGeneratorDependencies.cs b/src/EFCore.Relational/Scaffolding/ProviderCodeGeneratorDependencies.cs index c129f276896..d7e8170b567 100644 --- a/src/EFCore.Relational/Scaffolding/ProviderCodeGeneratorDependencies.cs +++ b/src/EFCore.Relational/Scaffolding/ProviderCodeGeneratorDependencies.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Scaffolding { @@ -43,8 +42,6 @@ public sealed record ProviderCodeGeneratorDependencies [EntityFrameworkInternal] public ProviderCodeGeneratorDependencies(IEnumerable plugins) { - Check.NotNull(plugins, nameof(plugins)); - Plugins = plugins; } diff --git a/src/EFCore.Relational/Storage/ByteArrayTypeMapping.cs b/src/EFCore.Relational/Storage/ByteArrayTypeMapping.cs index 4fff8247ffa..2640a3e99d5 100644 --- a/src/EFCore.Relational/Storage/ByteArrayTypeMapping.cs +++ b/src/EFCore.Relational/Storage/ByteArrayTypeMapping.cs @@ -4,7 +4,6 @@ using System.Data; using System.Globalization; using System.Text; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Storage { @@ -66,8 +65,6 @@ protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters p /// protected override string GenerateNonNullSqlLiteral(object value) { - Check.NotNull(value, nameof(value)); - var stringBuilder = new StringBuilder(); stringBuilder.Append("X'"); diff --git a/src/EFCore.Relational/Storage/CharTypeMapping.cs b/src/EFCore.Relational/Storage/CharTypeMapping.cs index fc42c354cf4..3e33eca4be6 100644 --- a/src/EFCore.Relational/Storage/CharTypeMapping.cs +++ b/src/EFCore.Relational/Storage/CharTypeMapping.cs @@ -3,7 +3,6 @@ using System; using System.Data; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Storage { @@ -61,7 +60,7 @@ protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters p protected override string GenerateNonNullSqlLiteral(object value) { // NB: We can get Int32 values here too due to compiler-introduced convert nodes - var charValue = Convert.ToChar(Check.NotNull(value, nameof(value))); + var charValue = Convert.ToChar(value); if (charValue == '\'') { return "''''"; diff --git a/src/EFCore.Relational/Storage/DbContextTransactionExtensions.cs b/src/EFCore.Relational/Storage/DbContextTransactionExtensions.cs index d2f75e2e3c8..b62b124c7a3 100644 --- a/src/EFCore.Relational/Storage/DbContextTransactionExtensions.cs +++ b/src/EFCore.Relational/Storage/DbContextTransactionExtensions.cs @@ -5,7 +5,6 @@ using System.Data.Common; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Storage { @@ -28,8 +27,6 @@ public static class DbContextTransactionExtensions /// The underlying . public static DbTransaction GetDbTransaction(this IDbContextTransaction dbContextTransaction) { - Check.NotNull(dbContextTransaction, nameof(dbContextTransaction)); - if (!(dbContextTransaction is IInfrastructure accessor)) { throw new InvalidOperationException(RelationalStrings.RelationalNotInUse); diff --git a/src/EFCore.Relational/Storage/Internal/CompositeRelationalParameter.cs b/src/EFCore.Relational/Storage/Internal/CompositeRelationalParameter.cs index 3849af24f2f..c0d3a48e2ef 100644 --- a/src/EFCore.Relational/Storage/Internal/CompositeRelationalParameter.cs +++ b/src/EFCore.Relational/Storage/Internal/CompositeRelationalParameter.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.Data.Common; using Microsoft.EntityFrameworkCore.Diagnostics; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Storage.Internal { @@ -28,8 +27,6 @@ public CompositeRelationalParameter( IReadOnlyList relationalParameters) : base(invariantName) { - Check.NotNull(relationalParameters, nameof(relationalParameters)); - RelationalParameters = relationalParameters; } @@ -49,9 +46,6 @@ public CompositeRelationalParameter( /// public override void AddDbParameter(DbCommand command, object? value) { - Check.NotNull(command, nameof(command)); - Check.NotNull(value, nameof(value)); - if (value is object[] innerValues) { if (innerValues.Length < RelationalParameters.Count) diff --git a/src/EFCore.Relational/Storage/Internal/DynamicRelationalParameter.cs b/src/EFCore.Relational/Storage/Internal/DynamicRelationalParameter.cs index 73fd4a5486a..e9317b3d50d 100644 --- a/src/EFCore.Relational/Storage/Internal/DynamicRelationalParameter.cs +++ b/src/EFCore.Relational/Storage/Internal/DynamicRelationalParameter.cs @@ -3,7 +3,6 @@ using System; using System.Data.Common; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Storage.Internal { @@ -29,9 +28,6 @@ public DynamicRelationalParameter( IRelationalTypeMappingSource typeMappingSource) : base(invariantName) { - Check.NotEmpty(name, nameof(name)); - Check.NotNull(typeMappingSource, nameof(typeMappingSource)); - Name = name; _typeMappingSource = typeMappingSource; } @@ -52,8 +48,6 @@ public DynamicRelationalParameter( /// public override void AddDbParameter(DbCommand command, object? value) { - Check.NotNull(command, nameof(command)); - if (value == null) { command.Parameters diff --git a/src/EFCore.Relational/Storage/Internal/RawRelationalParameter.cs b/src/EFCore.Relational/Storage/Internal/RawRelationalParameter.cs index fc2d2e2b0f1..9d26bef958b 100644 --- a/src/EFCore.Relational/Storage/Internal/RawRelationalParameter.cs +++ b/src/EFCore.Relational/Storage/Internal/RawRelationalParameter.cs @@ -30,8 +30,6 @@ public RawRelationalParameter( DbParameter parameter) : base(invariantName) { - Check.NotNull(parameter, nameof(parameter)); - _parameter = parameter; } diff --git a/src/EFCore.Relational/Storage/Internal/RawSqlCommandBuilder.cs b/src/EFCore.Relational/Storage/Internal/RawSqlCommandBuilder.cs index 68a39d29bf2..391ba40d66b 100644 --- a/src/EFCore.Relational/Storage/Internal/RawSqlCommandBuilder.cs +++ b/src/EFCore.Relational/Storage/Internal/RawSqlCommandBuilder.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Data.Common; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Storage.Internal { @@ -30,10 +29,6 @@ public RawSqlCommandBuilder( ISqlGenerationHelper sqlGenerationHelper, IParameterNameGeneratorFactory parameterNameGeneratorFactory) { - Check.NotNull(relationalCommandBuilderFactory, nameof(relationalCommandBuilderFactory)); - Check.NotNull(sqlGenerationHelper, nameof(sqlGenerationHelper)); - Check.NotNull(parameterNameGeneratorFactory, nameof(parameterNameGeneratorFactory)); - _relationalCommandBuilderFactory = relationalCommandBuilderFactory; _sqlGenerationHelper = sqlGenerationHelper; _parameterNameGeneratorFactory = parameterNameGeneratorFactory; @@ -48,7 +43,7 @@ public RawSqlCommandBuilder( public virtual IRelationalCommand Build(string sql) => _relationalCommandBuilderFactory .Create() - .Append(Check.NotEmpty(sql, nameof(sql))) + .Append(sql) .Build(); /// diff --git a/src/EFCore.Relational/Storage/Internal/RelationalParameterBase.cs b/src/EFCore.Relational/Storage/Internal/RelationalParameterBase.cs index 2c04808ea01..a5086a0fc1b 100644 --- a/src/EFCore.Relational/Storage/Internal/RelationalParameterBase.cs +++ b/src/EFCore.Relational/Storage/Internal/RelationalParameterBase.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.Data.Common; using Microsoft.EntityFrameworkCore.Diagnostics; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Storage.Internal { @@ -25,8 +24,6 @@ public abstract class RelationalParameterBase : IRelationalParameter /// protected RelationalParameterBase(string invariantName) { - Check.NotEmpty(invariantName, nameof(invariantName)); - InvariantName = invariantName; } @@ -54,9 +51,6 @@ protected RelationalParameterBase(string invariantName) /// public virtual void AddDbParameter(DbCommand command, IReadOnlyDictionary parameterValues) { - Check.NotNull(command, nameof(command)); - Check.NotNull(parameterValues, nameof(parameterValues)); - if (parameterValues.TryGetValue(InvariantName, out var parameterValue)) { AddDbParameter(command, parameterValue); diff --git a/src/EFCore.Relational/Storage/Internal/TypeMappedRelationalParameter.cs b/src/EFCore.Relational/Storage/Internal/TypeMappedRelationalParameter.cs index a0f2a7b1034..3d716ef3a0e 100644 --- a/src/EFCore.Relational/Storage/Internal/TypeMappedRelationalParameter.cs +++ b/src/EFCore.Relational/Storage/Internal/TypeMappedRelationalParameter.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Data.Common; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Storage.Internal { @@ -27,9 +26,6 @@ public TypeMappedRelationalParameter( bool? nullable) : base(invariantName) { - Check.NotEmpty(name, nameof(name)); - Check.NotNull(relationalTypeMapping, nameof(relationalTypeMapping)); - Name = name; RelationalTypeMapping = relationalTypeMapping; IsNullable = nullable; @@ -56,13 +52,9 @@ public TypeMappedRelationalParameter( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public override void AddDbParameter(DbCommand command, object? value) - { - Check.NotNull(command, nameof(command)); - - command.Parameters + => command.Parameters .Add( RelationalTypeMapping .CreateParameter(command, Name, value, IsNullable)); - } } } diff --git a/src/EFCore.Relational/Storage/ParameterNameGeneratorFactory.cs b/src/EFCore.Relational/Storage/ParameterNameGeneratorFactory.cs index 0943fe3dd21..52296cfa927 100644 --- a/src/EFCore.Relational/Storage/ParameterNameGeneratorFactory.cs +++ b/src/EFCore.Relational/Storage/ParameterNameGeneratorFactory.cs @@ -1,7 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Storage @@ -34,8 +33,6 @@ public class ParameterNameGeneratorFactory : IParameterNameGeneratorFactory /// Parameter object containing dependencies for this service. public ParameterNameGeneratorFactory(ParameterNameGeneratorDependencies dependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Dependencies = dependencies; } diff --git a/src/EFCore.Relational/Storage/RawSqlCommand.cs b/src/EFCore.Relational/Storage/RawSqlCommand.cs index d83a9c9220d..c9987ce4e9c 100644 --- a/src/EFCore.Relational/Storage/RawSqlCommand.cs +++ b/src/EFCore.Relational/Storage/RawSqlCommand.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Storage { @@ -30,9 +29,6 @@ public RawSqlCommand( IRelationalCommand relationalCommand, IReadOnlyDictionary parameterValues) { - Check.NotNull(relationalCommand, nameof(relationalCommand)); - Check.NotNull(parameterValues, nameof(parameterValues)); - RelationalCommand = relationalCommand; ParameterValues = parameterValues; } diff --git a/src/EFCore.Relational/Storage/RelationalCommand.cs b/src/EFCore.Relational/Storage/RelationalCommand.cs index 9bd401b6cfb..ae10d9548a0 100644 --- a/src/EFCore.Relational/Storage/RelationalCommand.cs +++ b/src/EFCore.Relational/Storage/RelationalCommand.cs @@ -9,7 +9,6 @@ using System.Threading.Tasks; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query.Internal; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Storage { @@ -48,10 +47,6 @@ public RelationalCommand( string commandText, IReadOnlyList parameters) { - Check.NotNull(dependencies, nameof(dependencies)); - Check.NotNull(commandText, nameof(commandText)); - Check.NotNull(parameters, nameof(parameters)); - Dependencies = dependencies; CommandText = commandText; Parameters = parameters; diff --git a/src/EFCore.Relational/Storage/RelationalCommandBuilder.cs b/src/EFCore.Relational/Storage/RelationalCommandBuilder.cs index e986b5fafb3..d4d67eb32f1 100644 --- a/src/EFCore.Relational/Storage/RelationalCommandBuilder.cs +++ b/src/EFCore.Relational/Storage/RelationalCommandBuilder.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Storage { @@ -38,8 +37,6 @@ public class RelationalCommandBuilder : IRelationalCommandBuilder public RelationalCommandBuilder( RelationalCommandBuilderDependencies dependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Dependencies = dependencies; } @@ -80,8 +77,6 @@ public virtual IReadOnlyList Parameters /// The same builder instance so that multiple calls can be chained. public virtual IRelationalCommandBuilder AddParameter(IRelationalParameter parameter) { - Check.NotNull(parameter, nameof(parameter)); - _parameters.Add(parameter); return this; @@ -94,8 +89,6 @@ public virtual IRelationalCommandBuilder AddParameter(IRelationalParameter param /// The same builder instance so that multiple calls can be chained. public virtual IRelationalCommandBuilder Append(string value) { - Check.NotNull(value, nameof(value)); - _commandTextBuilder.Append(value); return this; diff --git a/src/EFCore.Relational/Storage/RelationalCommandBuilderDependencies.cs b/src/EFCore.Relational/Storage/RelationalCommandBuilderDependencies.cs index 3940e073dd9..0c4e008baec 100644 --- a/src/EFCore.Relational/Storage/RelationalCommandBuilderDependencies.cs +++ b/src/EFCore.Relational/Storage/RelationalCommandBuilderDependencies.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Storage @@ -51,8 +50,6 @@ public sealed record RelationalCommandBuilderDependencies public RelationalCommandBuilderDependencies( IRelationalTypeMappingSource typeMappingSource) { - Check.NotNull(typeMappingSource, nameof(typeMappingSource)); - TypeMappingSource = typeMappingSource; } diff --git a/src/EFCore.Relational/Storage/RelationalCommandBuilderExtensions.cs b/src/EFCore.Relational/Storage/RelationalCommandBuilderExtensions.cs index 7e1c6cd3ead..d529af686ac 100644 --- a/src/EFCore.Relational/Storage/RelationalCommandBuilderExtensions.cs +++ b/src/EFCore.Relational/Storage/RelationalCommandBuilderExtensions.cs @@ -7,7 +7,6 @@ using System.IO; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.Internal; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Storage { @@ -30,9 +29,6 @@ public static IRelationalCommandBuilder AppendLine( this IRelationalCommandBuilder commandBuilder, string value) { - Check.NotNull(commandBuilder, nameof(commandBuilder)); - Check.NotNull(value, nameof(value)); - commandBuilder.Append(value).AppendLine(); return commandBuilder; @@ -51,9 +47,6 @@ public static IRelationalCommandBuilder AppendLines( string value, bool skipFinalNewline = false) { - Check.NotNull(commandBuilder, nameof(commandBuilder)); - Check.NotNull(value, nameof(value)); - using (var reader = new StringReader(value)) { var first = true; @@ -90,7 +83,7 @@ public static IRelationalCommandBuilder AppendLines( /// The command builder. /// The same builder instance so that multiple calls can be chained. public static IDisposable Indent(this IRelationalCommandBuilder commandBuilder) - => new Indenter(Check.NotNull(commandBuilder, nameof(commandBuilder))); + => new Indenter(commandBuilder); /// /// Adds a parameter. @@ -109,17 +102,11 @@ public static IRelationalCommandBuilder AddParameter( this IRelationalCommandBuilder commandBuilder, string invariantName, string name) - { - Check.NotNull(commandBuilder, nameof(commandBuilder)); - Check.NotEmpty(invariantName, nameof(invariantName)); - Check.NotEmpty(name, nameof(name)); - - return commandBuilder.AddParameter( + => commandBuilder.AddParameter( new DynamicRelationalParameter( - Check.NotEmpty(invariantName, nameof(invariantName)), - Check.NotEmpty(name, nameof(name)), + invariantName, + name, commandBuilder.TypeMappingSource)); - } /// /// Adds a parameter. @@ -146,19 +133,12 @@ public static IRelationalCommandBuilder AddParameter( string name, RelationalTypeMapping typeMapping, bool nullable) - { - Check.NotNull(commandBuilder, nameof(commandBuilder)); - Check.NotEmpty(invariantName, nameof(invariantName)); - Check.NotEmpty(name, nameof(name)); - Check.NotNull(typeMapping, nameof(typeMapping)); - - return commandBuilder.AddParameter( + => commandBuilder.AddParameter( new TypeMappedRelationalParameter( invariantName, name, typeMapping, nullable)); - } /// /// Adds a parameter. @@ -180,19 +160,12 @@ public static IRelationalCommandBuilder AddParameter( string invariantName, string name, IProperty property) - { - Check.NotNull(commandBuilder, nameof(commandBuilder)); - Check.NotEmpty(invariantName, nameof(invariantName)); - Check.NotEmpty(name, nameof(name)); - Check.NotNull(property, nameof(property)); - - return commandBuilder.AddParameter( + => commandBuilder.AddParameter( new TypeMappedRelationalParameter( invariantName, name, property.GetRelationalTypeMapping(), property.IsNullable)); - } /// /// Adds a parameter. @@ -215,19 +188,12 @@ public static IRelationalCommandBuilder AddParameter( string name, RelationalTypeMapping relationalTypeMapping, bool? nullable) - { - Check.NotNull(commandBuilder, nameof(commandBuilder)); - Check.NotEmpty(invariantName, nameof(invariantName)); - Check.NotEmpty(name, nameof(name)); - Check.NotNull(relationalTypeMapping, nameof(relationalTypeMapping)); - - return commandBuilder.AddParameter( + => commandBuilder.AddParameter( new TypeMappedRelationalParameter( invariantName, name, relationalTypeMapping, nullable)); - } /// /// Adds a parameter that is ultimately represented as multiple s in the @@ -246,10 +212,6 @@ public static IRelationalCommandBuilder AddCompositeParameter( string invariantName, IReadOnlyList subParameters) { - Check.NotNull(commandBuilder, nameof(commandBuilder)); - Check.NotEmpty(invariantName, nameof(invariantName)); - Check.NotNull(subParameters, nameof(subParameters)); - if (subParameters.Count > 0) { commandBuilder.AddParameter( @@ -276,14 +238,8 @@ public static IRelationalCommandBuilder AddRawParameter( this IRelationalCommandBuilder commandBuilder, string invariantName, DbParameter dbParameter) - { - Check.NotNull(commandBuilder, nameof(commandBuilder)); - Check.NotEmpty(invariantName, nameof(invariantName)); - Check.NotNull(dbParameter, nameof(dbParameter)); - - return commandBuilder.AddParameter( + => commandBuilder.AddParameter( new RawRelationalParameter(invariantName, dbParameter)); - } /// /// Adds a parameter. @@ -307,19 +263,12 @@ public static IRelationalCommandBuilder AddPropertyParameter( string invariantName, string name, IProperty property) - { - Check.NotNull(commandBuilder, nameof(commandBuilder)); - Check.NotEmpty(invariantName, nameof(invariantName)); - Check.NotEmpty(name, nameof(name)); - Check.NotNull(property, nameof(property)); - - return commandBuilder.AddParameter( + => commandBuilder.AddParameter( new TypeMappedPropertyRelationalParameter( invariantName, name, property.GetRelationalTypeMapping(), property)); - } private sealed class Indenter : IDisposable { diff --git a/src/EFCore.Relational/Storage/RelationalCommandBuilderFactory.cs b/src/EFCore.Relational/Storage/RelationalCommandBuilderFactory.cs index 6dbb4f935a3..e02980c0539 100644 --- a/src/EFCore.Relational/Storage/RelationalCommandBuilderFactory.cs +++ b/src/EFCore.Relational/Storage/RelationalCommandBuilderFactory.cs @@ -1,7 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Storage @@ -41,8 +40,6 @@ public class RelationalCommandBuilderFactory : IRelationalCommandBuilderFactory public RelationalCommandBuilderFactory( RelationalCommandBuilderDependencies dependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Dependencies = dependencies; } diff --git a/src/EFCore.Relational/Storage/RelationalCommandParameterObject.cs b/src/EFCore.Relational/Storage/RelationalCommandParameterObject.cs index 863daee9b9c..52fde8149c2 100644 --- a/src/EFCore.Relational/Storage/RelationalCommandParameterObject.cs +++ b/src/EFCore.Relational/Storage/RelationalCommandParameterObject.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Diagnostics; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Storage { @@ -123,8 +122,6 @@ public RelationalCommandParameterObject( bool detailedErrorsEnabled, CommandSource commandSource) { - Check.NotNull(connection, nameof(connection)); - Connection = connection; ParameterValues = parameterValues; ReaderColumns = readerColumns; diff --git a/src/EFCore.Relational/Storage/RelationalConnection.cs b/src/EFCore.Relational/Storage/RelationalConnection.cs index 74628e55290..61249f588f3 100644 --- a/src/EFCore.Relational/Storage/RelationalConnection.cs +++ b/src/EFCore.Relational/Storage/RelationalConnection.cs @@ -14,7 +14,6 @@ using System.Transactions; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; using IsolationLevel = System.Data.IsolationLevel; @@ -61,8 +60,6 @@ public abstract class RelationalConnection : IRelationalConnection, ITransaction /// Parameter object containing dependencies for this service. protected RelationalConnection(RelationalConnectionDependencies dependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Context = dependencies.CurrentContext.Context; _relationalCommandBuilder = dependencies.RelationalCommandBuilderFactory.Create(); diff --git a/src/EFCore.Relational/Storage/RelationalConnectionDependencies.cs b/src/EFCore.Relational/Storage/RelationalConnectionDependencies.cs index 540fb820684..a27e3dc1b9f 100644 --- a/src/EFCore.Relational/Storage/RelationalConnectionDependencies.cs +++ b/src/EFCore.Relational/Storage/RelationalConnectionDependencies.cs @@ -4,7 +4,6 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.Internal; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Storage @@ -60,14 +59,6 @@ public RelationalConnectionDependencies( ICurrentDbContext currentContext, IRelationalCommandBuilderFactory relationalCommandBuilderFactory) { - Check.NotNull(contextOptions, nameof(contextOptions)); - Check.NotNull(transactionLogger, nameof(transactionLogger)); - Check.NotNull(connectionLogger, nameof(connectionLogger)); - Check.NotNull(connectionStringResolver, nameof(connectionStringResolver)); - Check.NotNull(relationalTransactionFactory, nameof(relationalTransactionFactory)); - Check.NotNull(currentContext, nameof(currentContext)); - Check.NotNull(relationalCommandBuilderFactory, nameof(relationalCommandBuilderFactory)); - ContextOptions = contextOptions; TransactionLogger = transactionLogger; ConnectionLogger = connectionLogger; diff --git a/src/EFCore.Relational/Storage/RelationalDataReader.cs b/src/EFCore.Relational/Storage/RelationalDataReader.cs index f7282ef167f..b29085b69c3 100644 --- a/src/EFCore.Relational/Storage/RelationalDataReader.cs +++ b/src/EFCore.Relational/Storage/RelationalDataReader.cs @@ -7,7 +7,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore.Diagnostics; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Storage { @@ -53,9 +52,6 @@ public virtual void Initialize( Guid commandId, IRelationalCommandDiagnosticsLogger? logger) { - Check.NotNull(command, nameof(command)); - Check.NotNull(reader, nameof(reader)); - _relationalConnection = relationalConnection; _command = command; _reader = reader; diff --git a/src/EFCore.Relational/Storage/RelationalDatabase.cs b/src/EFCore.Relational/Storage/RelationalDatabase.cs index 028dda524e6..8a43b61796a 100644 --- a/src/EFCore.Relational/Storage/RelationalDatabase.cs +++ b/src/EFCore.Relational/Storage/RelationalDatabase.cs @@ -6,7 +6,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore.Update; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Storage @@ -44,8 +43,6 @@ public RelationalDatabase( RelationalDatabaseDependencies relationalDependencies) : base(dependencies) { - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - RelationalDependencies = relationalDependencies; } @@ -60,15 +57,11 @@ public RelationalDatabase( /// Entries representing the changes to be persisted. /// The number of state entries persisted to the database. public override int SaveChanges(IList entries) - { - Check.NotNull(entries, nameof(entries)); - - return RelationalDependencies.BatchExecutor.Execute( + => RelationalDependencies.BatchExecutor.Execute( RelationalDependencies.BatchPreparer.BatchCommands( entries, Dependencies.UpdateAdapterFactory.Create()), RelationalDependencies.Connection); - } /// /// Asynchronously persists changes from the supplied entries to the database. @@ -83,15 +76,11 @@ public override int SaveChanges(IList entries) public override Task SaveChangesAsync( IList entries, CancellationToken cancellationToken = default) - { - Check.NotNull(entries, nameof(entries)); - - return RelationalDependencies.BatchExecutor.ExecuteAsync( + => RelationalDependencies.BatchExecutor.ExecuteAsync( RelationalDependencies.BatchPreparer.BatchCommands( entries, Dependencies.UpdateAdapterFactory.Create()), RelationalDependencies.Connection, cancellationToken); - } } } diff --git a/src/EFCore.Relational/Storage/RelationalDatabaseCreator.cs b/src/EFCore.Relational/Storage/RelationalDatabaseCreator.cs index 9ce0d9a4641..62de83b4b2f 100644 --- a/src/EFCore.Relational/Storage/RelationalDatabaseCreator.cs +++ b/src/EFCore.Relational/Storage/RelationalDatabaseCreator.cs @@ -44,8 +44,6 @@ public abstract class RelationalDatabaseCreator : IRelationalDatabaseCreator /// Parameter object containing dependencies for this service. protected RelationalDatabaseCreator(RelationalDatabaseCreatorDependencies dependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Dependencies = dependencies; } diff --git a/src/EFCore.Relational/Storage/RelationalDatabaseDependencies.cs b/src/EFCore.Relational/Storage/RelationalDatabaseDependencies.cs index a63697c4dc6..77c589b7e6e 100644 --- a/src/EFCore.Relational/Storage/RelationalDatabaseDependencies.cs +++ b/src/EFCore.Relational/Storage/RelationalDatabaseDependencies.cs @@ -3,7 +3,6 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Update; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Storage @@ -55,10 +54,6 @@ public RelationalDatabaseDependencies( IBatchExecutor batchExecutor, IRelationalConnection connection) { - Check.NotNull(batchPreparer, nameof(batchPreparer)); - Check.NotNull(batchExecutor, nameof(batchExecutor)); - Check.NotNull(connection, nameof(connection)); - BatchPreparer = batchPreparer; BatchExecutor = batchExecutor; Connection = connection; diff --git a/src/EFCore.Relational/Storage/RelationalExecutionStrategyFactory.cs b/src/EFCore.Relational/Storage/RelationalExecutionStrategyFactory.cs index a9a1f9ee956..be535e44a14 100644 --- a/src/EFCore.Relational/Storage/RelationalExecutionStrategyFactory.cs +++ b/src/EFCore.Relational/Storage/RelationalExecutionStrategyFactory.cs @@ -3,7 +3,6 @@ using System; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Storage @@ -34,8 +33,6 @@ public class RelationalExecutionStrategyFactory : IExecutionStrategyFactory /// Parameter object containing dependencies for this service. public RelationalExecutionStrategyFactory(ExecutionStrategyDependencies dependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Dependencies = dependencies; var configuredFactory = RelationalOptionsExtension.Extract(dependencies.Options)?.ExecutionStrategyFactory; diff --git a/src/EFCore.Relational/Storage/RelationalSqlGenerationHelper.cs b/src/EFCore.Relational/Storage/RelationalSqlGenerationHelper.cs index 3e6376ab704..5feaff2b6d8 100644 --- a/src/EFCore.Relational/Storage/RelationalSqlGenerationHelper.cs +++ b/src/EFCore.Relational/Storage/RelationalSqlGenerationHelper.cs @@ -4,7 +4,6 @@ using System; using System.IO; using System.Text; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Storage @@ -37,8 +36,6 @@ public class RelationalSqlGenerationHelper : ISqlGenerationHelper /// Parameter object containing dependencies for this service. public RelationalSqlGenerationHelper(RelationalSqlGenerationHelperDependencies dependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Dependencies = dependencies; } @@ -119,7 +116,7 @@ public virtual void GenerateParameterNamePlaceholder(StringBuilder builder, stri /// The generated string. /// public virtual string EscapeIdentifier(string identifier) - => Check.NotEmpty(identifier, nameof(identifier)).Replace("\"", "\"\""); + => identifier.Replace("\"", "\"\""); /// /// Writes the escaped SQL representation of an identifier (column name, table name, etc.). @@ -128,8 +125,6 @@ public virtual string EscapeIdentifier(string identifier) /// The identifier to be escaped. public virtual void EscapeIdentifier(StringBuilder builder, string identifier) { - Check.NotEmpty(identifier, nameof(identifier)); - var initialLength = builder.Length; builder.Append(identifier); builder.Replace("\"", "\"\"", initialLength, identifier.Length); @@ -143,7 +138,7 @@ public virtual void EscapeIdentifier(StringBuilder builder, string identifier) /// The generated string. /// public virtual string DelimitIdentifier(string identifier) - => $"\"{EscapeIdentifier(Check.NotEmpty(identifier, nameof(identifier)))}\""; // Interpolation okay; strings + => $"\"{EscapeIdentifier(identifier)}\""; // Interpolation okay; strings /// /// Writes the delimited SQL representation of an identifier (column name, table name, etc.). @@ -152,8 +147,6 @@ public virtual string DelimitIdentifier(string identifier) /// The identifier to delimit. public virtual void DelimitIdentifier(StringBuilder builder, string identifier) { - Check.NotEmpty(identifier, nameof(identifier)); - builder.Append('"'); EscapeIdentifier(builder, identifier); builder.Append('"'); @@ -171,7 +164,7 @@ public virtual string DelimitIdentifier(string name, string? schema) => (!string.IsNullOrEmpty(schema) ? DelimitIdentifier(schema) + "." : string.Empty) - + DelimitIdentifier(Check.NotEmpty(name, nameof(name))); + + DelimitIdentifier(name); /// /// Writes the delimited SQL representation of an identifier (column name, table name, etc.). @@ -197,8 +190,6 @@ public virtual void DelimitIdentifier(StringBuilder builder, string name, string /// The generated SQL. public virtual string GenerateComment(string text) { - Check.NotEmpty(text, nameof(text)); - var builder = new StringBuilder(); using (var reader = new StringReader(text)) { diff --git a/src/EFCore.Relational/Storage/RelationalTransaction.cs b/src/EFCore.Relational/Storage/RelationalTransaction.cs index c2753bc59e8..2c4e974ac44 100644 --- a/src/EFCore.Relational/Storage/RelationalTransaction.cs +++ b/src/EFCore.Relational/Storage/RelationalTransaction.cs @@ -52,11 +52,6 @@ public RelationalTransaction( bool transactionOwned, ISqlGenerationHelper sqlGenerationHelper) { - Check.NotNull(connection, nameof(connection)); - Check.NotNull(transaction, nameof(transaction)); - Check.NotNull(logger, nameof(logger)); - Check.NotNull(sqlGenerationHelper, nameof(sqlGenerationHelper)); - if (connection.DbConnection != transaction.Connection) { throw new InvalidOperationException(RelationalStrings.TransactionAssociatedWithDifferentConnection); diff --git a/src/EFCore.Relational/Storage/RelationalTransactionFactory.cs b/src/EFCore.Relational/Storage/RelationalTransactionFactory.cs index d0a4011ad30..a7d245d506c 100644 --- a/src/EFCore.Relational/Storage/RelationalTransactionFactory.cs +++ b/src/EFCore.Relational/Storage/RelationalTransactionFactory.cs @@ -4,7 +4,6 @@ using System; using System.Data.Common; using Microsoft.EntityFrameworkCore.Diagnostics; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Storage @@ -36,8 +35,6 @@ public class RelationalTransactionFactory : IRelationalTransactionFactory /// Parameter object containing dependencies for this service. public RelationalTransactionFactory(RelationalTransactionFactoryDependencies dependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Dependencies = dependencies; } diff --git a/src/EFCore.Relational/Storage/RelationalTransactionFactoryDependencies.cs b/src/EFCore.Relational/Storage/RelationalTransactionFactoryDependencies.cs index c7ad7251f00..73c02f4f17b 100644 --- a/src/EFCore.Relational/Storage/RelationalTransactionFactoryDependencies.cs +++ b/src/EFCore.Relational/Storage/RelationalTransactionFactoryDependencies.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Storage @@ -51,8 +50,6 @@ public sealed record RelationalTransactionFactoryDependencies [EntityFrameworkInternal] public RelationalTransactionFactoryDependencies(ISqlGenerationHelper sqlGenerationHelper) { - Check.NotNull(sqlGenerationHelper, nameof(sqlGenerationHelper)); - SqlGenerationHelper = sqlGenerationHelper; } diff --git a/src/EFCore.Relational/Storage/RelationalTypeMapping.cs b/src/EFCore.Relational/Storage/RelationalTypeMapping.cs index 0abaf7f257f..f81541ee72c 100644 --- a/src/EFCore.Relational/Storage/RelationalTypeMapping.cs +++ b/src/EFCore.Relational/Storage/RelationalTypeMapping.cs @@ -56,8 +56,6 @@ public RelationalTypeMappingParameters( int? precision = null, int? scale = null) { - Check.NotNull(storeType, nameof(storeType)); - var converterHints = coreParameters.Converter?.MappingHints; CoreParameters = coreParameters; @@ -297,9 +295,6 @@ protected virtual string ProcessStoreType( string storeType, string storeTypeNameBase) { - Check.NotNull(storeType, nameof(storeType)); - Check.NotNull(storeTypeNameBase, nameof(storeTypeNameBase)); - var size = parameters.Size; if (size != null @@ -482,8 +477,6 @@ public virtual DbParameter CreateParameter( object? value, bool? nullable = null) { - Check.NotNull(command, nameof(command)); - var parameter = command.CreateParameter(); parameter.Direction = ParameterDirection.Input; parameter.ParameterName = name; @@ -583,7 +576,7 @@ public virtual string GenerateProviderValueSqlLiteral(object? value) /// The generated string. /// protected virtual string GenerateNonNullSqlLiteral(object value) - => string.Format(CultureInfo.InvariantCulture, SqlLiteralFormatString, Check.NotNull(value, nameof(value))); + => string.Format(CultureInfo.InvariantCulture, SqlLiteralFormatString, value); /// /// The method to use when reading values of the given type. The method must be defined diff --git a/src/EFCore.Relational/Storage/RelationalTypeMappingInfo.cs b/src/EFCore.Relational/Storage/RelationalTypeMappingInfo.cs index bc93bde10c9..802143f57e8 100644 --- a/src/EFCore.Relational/Storage/RelationalTypeMappingInfo.cs +++ b/src/EFCore.Relational/Storage/RelationalTypeMappingInfo.cs @@ -6,7 +6,6 @@ using System.Reflection; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Storage { @@ -89,9 +88,6 @@ public RelationalTypeMappingInfo( int? scale) { // Note: Empty string is allowed for store type name because SQLite - Check.NotNull(storeTypeName, nameof(storeTypeName)); - Check.NotNull(storeTypeNameBase, nameof(storeTypeNameBase)); - _coreTypeMappingInfo = new TypeMappingInfo(null, false, unicode, size, null, precision, scale); StoreTypeName = storeTypeName; StoreTypeNameBase = storeTypeNameBase; @@ -117,8 +113,6 @@ public RelationalTypeMappingInfo( int? precision = null, int? scale = null) { - Check.NotNull(member, nameof(member)); - _coreTypeMappingInfo = new TypeMappingInfo(member, unicode, size, precision, scale); StoreTypeName = storeTypeName; diff --git a/src/EFCore.Relational/Storage/RelationalTypeMappingSource.cs b/src/EFCore.Relational/Storage/RelationalTypeMappingSource.cs index f06f502d8ff..5af88f3c98b 100644 --- a/src/EFCore.Relational/Storage/RelationalTypeMappingSource.cs +++ b/src/EFCore.Relational/Storage/RelationalTypeMappingSource.cs @@ -10,7 +10,6 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; #pragma warning disable 1574, CS0419 // Ambiguous reference in cref attribute @@ -52,8 +51,6 @@ protected RelationalTypeMappingSource( RelationalTypeMappingSourceDependencies relationalDependencies) : base(dependencies) { - Check.NotNull(relationalDependencies, nameof(relationalDependencies)); - RelationalDependencies = relationalDependencies; } diff --git a/src/EFCore.Relational/Storage/RelationalTypeMappingSourceDependencies.cs b/src/EFCore.Relational/Storage/RelationalTypeMappingSourceDependencies.cs index 6c454844ada..789d65b623f 100644 --- a/src/EFCore.Relational/Storage/RelationalTypeMappingSourceDependencies.cs +++ b/src/EFCore.Relational/Storage/RelationalTypeMappingSourceDependencies.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Storage @@ -53,8 +52,6 @@ public sealed record RelationalTypeMappingSourceDependencies public RelationalTypeMappingSourceDependencies( IEnumerable plugins) { - Check.NotNull(plugins, nameof(plugins)); - Plugins = plugins; } diff --git a/src/EFCore.Relational/Storage/RelationalTypeMappingSourceExtensions.cs b/src/EFCore.Relational/Storage/RelationalTypeMappingSourceExtensions.cs index 9944053de92..64a49139564 100644 --- a/src/EFCore.Relational/Storage/RelationalTypeMappingSourceExtensions.cs +++ b/src/EFCore.Relational/Storage/RelationalTypeMappingSourceExtensions.cs @@ -58,7 +58,6 @@ public static RelationalTypeMapping GetMapping( this IRelationalTypeMappingSource typeMappingSource, IProperty property) { - Check.NotNull(typeMappingSource, nameof(typeMappingSource)); Check.NotNull(property, nameof(property)); var mapping = typeMappingSource.FindMapping(property); @@ -85,7 +84,6 @@ public static RelationalTypeMapping GetMapping( this IRelationalTypeMappingSource typeMappingSource, Type clrType) { - Check.NotNull(typeMappingSource, nameof(typeMappingSource)); Check.NotNull(clrType, nameof(clrType)); var mapping = typeMappingSource.FindMapping(clrType); @@ -133,7 +131,6 @@ public static RelationalTypeMapping GetMapping( this IRelationalTypeMappingSource typeMappingSource, string typeName) { - Check.NotNull(typeMappingSource, nameof(typeMappingSource)); // Note: Empty string is allowed for store type name because SQLite Check.NotNull(typeName, nameof(typeName)); diff --git a/src/EFCore.Relational/Storage/RelationalValueBufferFactoryDependencies.cs b/src/EFCore.Relational/Storage/RelationalValueBufferFactoryDependencies.cs index 2fd45ad5231..946b0796fb1 100644 --- a/src/EFCore.Relational/Storage/RelationalValueBufferFactoryDependencies.cs +++ b/src/EFCore.Relational/Storage/RelationalValueBufferFactoryDependencies.cs @@ -3,7 +3,6 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.Internal; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Storage @@ -54,9 +53,6 @@ public RelationalValueBufferFactoryDependencies( IRelationalTypeMappingSource typeMappingSource, ICoreSingletonOptions coreOptions) { - Check.NotNull(typeMappingSource, nameof(typeMappingSource)); - Check.NotNull(coreOptions, nameof(coreOptions)); - TypeMappingSource = typeMappingSource; CoreOptions = coreOptions; } diff --git a/src/EFCore.Relational/Storage/StringTypeMapping.cs b/src/EFCore.Relational/Storage/StringTypeMapping.cs index a28ff96be0a..9ce789d8900 100644 --- a/src/EFCore.Relational/Storage/StringTypeMapping.cs +++ b/src/EFCore.Relational/Storage/StringTypeMapping.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Data; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Storage { @@ -65,7 +64,7 @@ protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters p /// The generated string. /// protected virtual string EscapeSqlLiteral(string literal) - => Check.NotNull(literal, nameof(literal)).Replace("'", "''"); + => literal.Replace("'", "''"); /// /// Generates the SQL representation of a literal value. diff --git a/src/EFCore.Relational/Storage/TypeMaterializationInfo.cs b/src/EFCore.Relational/Storage/TypeMaterializationInfo.cs index 2e963fcd6fd..3b05be62457 100644 --- a/src/EFCore.Relational/Storage/TypeMaterializationInfo.cs +++ b/src/EFCore.Relational/Storage/TypeMaterializationInfo.cs @@ -3,7 +3,6 @@ using System; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Storage { @@ -30,8 +29,6 @@ public TypeMaterializationInfo( RelationalTypeMapping mapping, bool? nullable = null) { - Check.NotNull(modelClrType, nameof(modelClrType)); - ProviderClrType = mapping.Converter?.ProviderClrType ?? modelClrType; ModelClrType = modelClrType; Mapping = mapping; diff --git a/src/EFCore.Relational/Storage/TypedRelationalValueBufferFactoryFactory.cs b/src/EFCore.Relational/Storage/TypedRelationalValueBufferFactoryFactory.cs index b2ccde0a43d..069f6be5d72 100644 --- a/src/EFCore.Relational/Storage/TypedRelationalValueBufferFactoryFactory.cs +++ b/src/EFCore.Relational/Storage/TypedRelationalValueBufferFactoryFactory.cs @@ -13,7 +13,6 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Storage.Internal; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Storage @@ -67,8 +66,6 @@ private static readonly MethodInfo _throwReadValueExceptionMethod /// Parameter object containing dependencies for this service. public TypedRelationalValueBufferFactoryFactory(RelationalValueBufferFactoryDependencies dependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Dependencies = dependencies; } @@ -111,15 +108,11 @@ public override int GetHashCode() /// Types and mapping for the values to be read. /// The newly created . public virtual IRelationalValueBufferFactory Create(IReadOnlyList types) - { - Check.NotNull(types, nameof(types)); - - return _cache.GetOrAdd( + => _cache.GetOrAdd( new CacheKey(types), k => new TypedRelationalValueBufferFactory( Dependencies, CreateArrayInitializer(k, Dependencies.CoreOptions.AreDetailedErrorsEnabled))); - } /// /// Creates value buffer assignment expressions for the given type information. @@ -128,7 +121,7 @@ public virtual IRelationalValueBufferFactory Create(IReadOnlyListThe value buffer assignment expressions. [Obsolete] public virtual IReadOnlyList CreateAssignmentExpressions(IReadOnlyList types) - => Check.NotNull(types, nameof(types)) + => types .Select( (mi, i) => CreateGetValueExpression( diff --git a/src/EFCore.Relational/Update/ColumnModification.cs b/src/EFCore.Relational/Update/ColumnModification.cs index b95b7110673..99938518581 100644 --- a/src/EFCore.Relational/Update/ColumnModification.cs +++ b/src/EFCore.Relational/Update/ColumnModification.cs @@ -89,7 +89,7 @@ public ColumnModification( bool isCondition, bool sensitiveLoggingEnabled) : this( - Check.NotNull(column, nameof(column)).Name, + column.Name, originalValue: null, value: null, property: property, @@ -102,10 +102,6 @@ public ColumnModification( sensitiveLoggingEnabled: sensitiveLoggingEnabled, column.IsNullable) { - Check.NotNull(entry, nameof(entry)); - Check.NotNull(property, nameof(property)); - Check.NotNull(generateParameterName, nameof(generateParameterName)); - Entry = entry; _generateParameterName = generateParameterName; UseParameter = true; @@ -137,9 +133,9 @@ public ColumnModification( : this( entry, property, - Check.NotNull(property, nameof(property)).GetTableColumnMappings().First().Column, + property.GetTableColumnMappings().First().Column, generateParameterName, - Check.NotNull(property, nameof(property)).GetTableColumnMappings().First().TypeMapping, + property.GetTableColumnMappings().First().TypeMapping, isRead: isRead, isWrite: isWrite, isKey: isKey, @@ -178,8 +174,6 @@ public ColumnModification( bool sensitiveLoggingEnabled, bool? isNullable = null) { - Check.NotNull(columnName, nameof(columnName)); - ColumnName = columnName; _originalValue = originalValue; _value = value; @@ -220,8 +214,6 @@ public ColumnModification( bool isCondition, bool sensitiveLoggingEnabled) { - Check.NotNull(columnName, nameof(columnName)); - ColumnName = columnName; _originalValue = originalValue; _value = value; diff --git a/src/EFCore.Relational/Update/ColumnModificationParameters.cs b/src/EFCore.Relational/Update/ColumnModificationParameters.cs index 0ee3b41ebde..cdc5c3b8850 100644 --- a/src/EFCore.Relational/Update/ColumnModificationParameters.cs +++ b/src/EFCore.Relational/Update/ColumnModificationParameters.cs @@ -4,7 +4,6 @@ using System; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Update { @@ -121,8 +120,6 @@ public ColumnModificationParameters( bool sensitiveLoggingEnabled, bool? isNullable = null) { - Check.NotNull(columnName, nameof(columnName)); - ColumnName = columnName; OriginalValue = originalValue; Value = value; @@ -167,12 +164,6 @@ public ColumnModificationParameters( bool columnIsCondition, bool sensitiveLoggingEnabled) { - Check.NotNull(entry, nameof(entry)); - Check.NotNull(property, nameof(property)); - Check.NotNull(column, nameof(column)); - Check.NotNull(column.Name, "column.Name"); - Check.NotNull(generateParameterName, nameof(generateParameterName)); - ColumnName = column.Name; OriginalValue = null; Value = null; diff --git a/src/EFCore.Relational/Update/ModificationCommand.cs b/src/EFCore.Relational/Update/ModificationCommand.cs index 61994b90d66..0d82660409c 100644 --- a/src/EFCore.Relational/Update/ModificationCommand.cs +++ b/src/EFCore.Relational/Update/ModificationCommand.cs @@ -122,8 +122,6 @@ public virtual bool RequiresResultPropagation /// public virtual void AddEntry(IUpdateEntry entry, bool mainEntry) { - Check.NotNull(entry, nameof(entry)); - AssertColumnsNotInitialized(); switch (entry.EntityState) @@ -437,8 +435,6 @@ private void InitializeSharedColumns( /// The buffer containing the values read from the database. public virtual void PropagateResults(ValueBuffer valueBuffer) { - Check.NotNull(valueBuffer, nameof(valueBuffer)); - // Note that this call sets the value into a sidecar and will only commit to the actual entity // if SaveChanges is successful. var index = 0; diff --git a/src/EFCore.Relational/Update/ModificationCommandBatchFactoryDependencies.cs b/src/EFCore.Relational/Update/ModificationCommandBatchFactoryDependencies.cs index 82dffade8ab..018971093c8 100644 --- a/src/EFCore.Relational/Update/ModificationCommandBatchFactoryDependencies.cs +++ b/src/EFCore.Relational/Update/ModificationCommandBatchFactoryDependencies.cs @@ -4,7 +4,6 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Update @@ -59,12 +58,6 @@ public ModificationCommandBatchFactoryDependencies( ICurrentDbContext currentContext, IRelationalCommandDiagnosticsLogger logger) { - Check.NotNull(commandBuilderFactory, nameof(commandBuilderFactory)); - Check.NotNull(sqlGenerationHelper, nameof(sqlGenerationHelper)); - Check.NotNull(updateSqlGenerator, nameof(updateSqlGenerator)); - Check.NotNull(valueBufferFactoryFactory, nameof(valueBufferFactoryFactory)); - Check.NotNull(logger, nameof(logger)); - CommandBuilderFactory = commandBuilderFactory; SqlGenerationHelper = sqlGenerationHelper; UpdateSqlGenerator = updateSqlGenerator; diff --git a/src/EFCore.Relational/Update/ReaderModificationCommandBatch.cs b/src/EFCore.Relational/Update/ReaderModificationCommandBatch.cs index bae89be0016..56c9c4c0a0f 100644 --- a/src/EFCore.Relational/Update/ReaderModificationCommandBatch.cs +++ b/src/EFCore.Relational/Update/ReaderModificationCommandBatch.cs @@ -9,7 +9,6 @@ using System.Threading.Tasks; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Update { @@ -36,8 +35,6 @@ public abstract class ReaderModificationCommandBatch : ModificationCommandBatch /// Service dependencies. protected ReaderModificationCommandBatch(ModificationCommandBatchFactoryDependencies dependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Dependencies = dependencies; CachedCommandText = new StringBuilder(); } @@ -84,8 +81,6 @@ public override IReadOnlyList ModificationCommands /// public override bool AddCommand(IReadOnlyModificationCommand modificationCommand) { - Check.NotNull(modificationCommand, nameof(modificationCommand)); - if (ModificationCommands.Count == 0) { ResetCommandText(); @@ -241,8 +236,6 @@ protected virtual RawSqlCommand CreateStoreCommand() /// The connection to the database to update. public override void Execute(IRelationalConnection connection) { - Check.NotNull(connection, nameof(connection)); - var storeCommand = CreateStoreCommand(); try @@ -277,8 +270,6 @@ public override async Task ExecuteAsync( IRelationalConnection connection, CancellationToken cancellationToken = default) { - Check.NotNull(connection, nameof(connection)); - var storeCommand = CreateStoreCommand(); try @@ -332,7 +323,7 @@ protected virtual IRelationalValueBufferFactory CreateValueBufferFactory( IReadOnlyList columnModifications) => Dependencies.ValueBufferFactoryFactory .Create( - Check.NotNull(columnModifications, nameof(columnModifications)) + columnModifications .Where(c => c.IsRead) .Select(c => new TypeMaterializationInfo(c.Property!.ClrType, c.Property, c.TypeMapping!)) .ToArray()); diff --git a/src/EFCore.Relational/Update/UpdateSqlGenerator.cs b/src/EFCore.Relational/Update/UpdateSqlGenerator.cs index 9c31e740f92..58d97af10ff 100644 --- a/src/EFCore.Relational/Update/UpdateSqlGenerator.cs +++ b/src/EFCore.Relational/Update/UpdateSqlGenerator.cs @@ -7,7 +7,6 @@ using System.Text; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Update @@ -40,8 +39,6 @@ public abstract class UpdateSqlGenerator : IUpdateSqlGenerator /// Parameter object containing dependencies for this service. protected UpdateSqlGenerator(UpdateSqlGeneratorDependencies dependencies) { - Check.NotNull(dependencies, nameof(dependencies)); - Dependencies = dependencies; } @@ -68,9 +65,6 @@ public virtual ResultSetMapping AppendInsertOperation( IReadOnlyModificationCommand command, int commandPosition) { - Check.NotNull(commandStringBuilder, nameof(commandStringBuilder)); - Check.NotNull(command, nameof(command)); - var name = command.TableName; var schema = command.Schema; var operations = command.ColumnModifications; @@ -102,9 +96,6 @@ public virtual ResultSetMapping AppendUpdateOperation( IReadOnlyModificationCommand command, int commandPosition) { - Check.NotNull(commandStringBuilder, nameof(commandStringBuilder)); - Check.NotNull(command, nameof(command)); - var name = command.TableName; var schema = command.Schema; var operations = command.ColumnModifications; @@ -137,9 +128,6 @@ public virtual ResultSetMapping AppendDeleteOperation( IReadOnlyModificationCommand command, int commandPosition) { - Check.NotNull(commandStringBuilder, nameof(commandStringBuilder)); - Check.NotNull(command, nameof(command)); - var name = command.TableName; var schema = command.Schema; var conditionOperations = command.ColumnModifications.Where(o => o.IsCondition).ToList(); @@ -162,10 +150,6 @@ protected virtual void AppendInsertCommand( string? schema, IReadOnlyList writeOperations) { - Check.NotNull(commandStringBuilder, nameof(commandStringBuilder)); - Check.NotEmpty(name, nameof(name)); - Check.NotNull(writeOperations, nameof(writeOperations)); - AppendInsertCommandHeader(commandStringBuilder, name, schema, writeOperations); AppendValuesHeader(commandStringBuilder, writeOperations); AppendValues(commandStringBuilder, name, schema, writeOperations); @@ -187,11 +171,6 @@ protected virtual void AppendUpdateCommand( IReadOnlyList writeOperations, IReadOnlyList conditionOperations) { - Check.NotNull(commandStringBuilder, nameof(commandStringBuilder)); - Check.NotEmpty(name, nameof(name)); - Check.NotEmpty(writeOperations, nameof(writeOperations)); - Check.NotNull(conditionOperations, nameof(conditionOperations)); - AppendUpdateCommandHeader(commandStringBuilder, name, schema, writeOperations); AppendWhereClause(commandStringBuilder, conditionOperations); commandStringBuilder.AppendLine(SqlGenerationHelper.StatementTerminator); @@ -210,10 +189,6 @@ protected virtual void AppendDeleteCommand( string? schema, IReadOnlyList conditionOperations) { - Check.NotNull(commandStringBuilder, nameof(commandStringBuilder)); - Check.NotEmpty(name, nameof(name)); - Check.NotNull(conditionOperations, nameof(conditionOperations)); - AppendDeleteCommandHeader(commandStringBuilder, name, schema); AppendWhereClause(commandStringBuilder, conditionOperations); commandStringBuilder.AppendLine(SqlGenerationHelper.StatementTerminator); @@ -252,11 +227,6 @@ protected virtual ResultSetMapping AppendSelectAffectedCommand( IReadOnlyList conditionOperations, int commandPosition) { - Check.NotNull(commandStringBuilder, nameof(commandStringBuilder)); - Check.NotEmpty(name, nameof(name)); - Check.NotNull(readOperations, nameof(readOperations)); - Check.NotNull(conditionOperations, nameof(conditionOperations)); - AppendSelectCommandHeader(commandStringBuilder, readOperations); AppendFromClause(commandStringBuilder, name, schema); AppendWhereAffectedClause(commandStringBuilder, conditionOperations); @@ -279,10 +249,6 @@ protected virtual void AppendInsertCommandHeader( string? schema, IReadOnlyList operations) { - Check.NotNull(commandStringBuilder, nameof(commandStringBuilder)); - Check.NotEmpty(name, nameof(name)); - Check.NotNull(operations, nameof(operations)); - commandStringBuilder.Append("INSERT INTO "); SqlGenerationHelper.DelimitIdentifier(commandStringBuilder, name, schema); @@ -309,9 +275,6 @@ protected virtual void AppendDeleteCommandHeader( string name, string? schema) { - Check.NotNull(commandStringBuilder, nameof(commandStringBuilder)); - Check.NotEmpty(name, nameof(name)); - commandStringBuilder.Append("DELETE FROM "); SqlGenerationHelper.DelimitIdentifier(commandStringBuilder, name, schema); } @@ -329,10 +292,6 @@ protected virtual void AppendUpdateCommandHeader( string? schema, IReadOnlyList operations) { - Check.NotNull(commandStringBuilder, nameof(commandStringBuilder)); - Check.NotEmpty(name, nameof(name)); - Check.NotNull(operations, nameof(operations)); - commandStringBuilder.Append("UPDATE "); SqlGenerationHelper.DelimitIdentifier(commandStringBuilder, name, schema); commandStringBuilder.Append(" SET ") @@ -363,17 +322,12 @@ protected virtual void AppendUpdateCommandHeader( protected virtual void AppendSelectCommandHeader( StringBuilder commandStringBuilder, IReadOnlyList operations) - { - Check.NotNull(commandStringBuilder, nameof(commandStringBuilder)); - Check.NotNull(operations, nameof(operations)); - - commandStringBuilder + => commandStringBuilder .Append("SELECT ") .AppendJoin( operations, SqlGenerationHelper, (sb, o, helper) => helper.DelimitIdentifier(sb, o.ColumnName)); - } /// /// Appends a SQL fragment for starting a FROM clause. @@ -386,9 +340,6 @@ protected virtual void AppendFromClause( string name, string? schema) { - Check.NotNull(commandStringBuilder, nameof(commandStringBuilder)); - Check.NotEmpty(name, nameof(name)); - commandStringBuilder .AppendLine() .Append("FROM "); @@ -404,9 +355,6 @@ protected virtual void AppendValuesHeader( StringBuilder commandStringBuilder, IReadOnlyList operations) { - Check.NotNull(commandStringBuilder, nameof(commandStringBuilder)); - Check.NotNull(operations, nameof(operations)); - commandStringBuilder.AppendLine(); commandStringBuilder.Append(operations.Count > 0 ? "VALUES " : "DEFAULT VALUES"); } @@ -424,9 +372,6 @@ protected virtual void AppendValues( string? schema, IReadOnlyList operations) { - Check.NotNull(commandStringBuilder, nameof(commandStringBuilder)); - Check.NotNull(operations, nameof(operations)); - if (operations.Count > 0) { commandStringBuilder @@ -466,9 +411,6 @@ protected virtual void AppendWhereClause( StringBuilder commandStringBuilder, IReadOnlyList operations) { - Check.NotNull(commandStringBuilder, nameof(commandStringBuilder)); - Check.NotNull(operations, nameof(operations)); - if (operations.Count > 0) { commandStringBuilder @@ -487,9 +429,6 @@ protected virtual void AppendWhereAffectedClause( StringBuilder commandStringBuilder, IReadOnlyList operations) { - Check.NotNull(commandStringBuilder, nameof(commandStringBuilder)); - Check.NotNull(operations, nameof(operations)); - commandStringBuilder .AppendLine() .Append("WHERE "); @@ -553,9 +492,6 @@ protected virtual void AppendWhereCondition( IColumnModification columnModification, bool useOriginalValue) { - Check.NotNull(commandStringBuilder, nameof(commandStringBuilder)); - Check.NotNull(columnModification, nameof(columnModification)); - SqlGenerationHelper.DelimitIdentifier(commandStringBuilder, columnModification.ColumnName); var parameterValue = useOriginalValue @@ -623,7 +559,7 @@ public virtual string GenerateNextSequenceValueOperation(string name, string? sc public virtual void AppendNextSequenceValueOperation(StringBuilder commandStringBuilder, string name, string? schema) { commandStringBuilder.Append("SELECT NEXT VALUE FOR "); - SqlGenerationHelper.DelimitIdentifier(commandStringBuilder, Check.NotNull(name, nameof(name)), schema); + SqlGenerationHelper.DelimitIdentifier(commandStringBuilder, name, schema); } private void AppendSqlLiteral( diff --git a/src/EFCore.Relational/Update/UpdateSqlGeneratorDependencies.cs b/src/EFCore.Relational/Update/UpdateSqlGeneratorDependencies.cs index ab380bc4fac..a7ecc0285a2 100644 --- a/src/EFCore.Relational/Update/UpdateSqlGeneratorDependencies.cs +++ b/src/EFCore.Relational/Update/UpdateSqlGeneratorDependencies.cs @@ -3,7 +3,6 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Update @@ -54,9 +53,6 @@ public UpdateSqlGeneratorDependencies( ISqlGenerationHelper sqlGenerationHelper, IRelationalTypeMappingSource typeMappingSource) { - Check.NotNull(sqlGenerationHelper, nameof(sqlGenerationHelper)); - Check.NotNull(typeMappingSource, nameof(typeMappingSource)); - SqlGenerationHelper = sqlGenerationHelper; TypeMappingSource = typeMappingSource; } diff --git a/src/EFCore.Relational/ValueGeneration/RelationalValueGeneratorSelector.cs b/src/EFCore.Relational/ValueGeneration/RelationalValueGeneratorSelector.cs index 80b9485f41c..edc866fa315 100644 --- a/src/EFCore.Relational/ValueGeneration/RelationalValueGeneratorSelector.cs +++ b/src/EFCore.Relational/ValueGeneration/RelationalValueGeneratorSelector.cs @@ -3,7 +3,6 @@ using System; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.EntityFrameworkCore.ValueGeneration.Internal; using Microsoft.Extensions.DependencyInjection; @@ -55,9 +54,6 @@ public RelationalValueGeneratorSelector(ValueGeneratorSelectorDependencies depen /// The newly created value generator. public override ValueGenerator Create(IProperty property, IEntityType entityType) { - Check.NotNull(property, nameof(property)); - Check.NotNull(entityType, nameof(entityType)); - if (property.ValueGenerated != ValueGenerated.Never) { var propertyType = property.ClrType.UnwrapNullableType().UnwrapEnumType(); diff --git a/test/EFCore.Tests/Metadata/Conventions/QueryFilterRewritingConventionTest.cs b/test/EFCore.Tests/Metadata/Conventions/QueryFilterRewritingConventionTest.cs index 3433547c35e..f6b48961331 100644 --- a/test/EFCore.Tests/Metadata/Conventions/QueryFilterRewritingConventionTest.cs +++ b/test/EFCore.Tests/Metadata/Conventions/QueryFilterRewritingConventionTest.cs @@ -1,7 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. - // ReSharper disable InconsistentNaming // ReSharper disable UnusedMember.Local using System;