From e337283acd5e709b31730fd9eb7ff9857dcb7366 Mon Sep 17 00:00:00 2001 From: AndriySvyryd Date: Fri, 23 Aug 2019 12:25:00 -0700 Subject: [PATCH] Code cleanup --- All.sln.DotSettings | 2 +- .../DbFunctionAttribute.cs | 2 +- src/EFCore.Abstractions/OwnedAttribute.cs | 2 +- .../InternalUsageDiagnosticAnalyzer.cs | 33 ++- .../CosmosDbContextOptionsExtensions.cs | 4 +- .../CosmosEntityTypeBuilderExtensions.cs | 2 +- .../Extensions/CosmosEntityTypeExtensions.cs | 8 +- .../CosmosModelBuilderExtensions.cs | 2 +- .../Extensions/CosmosModelExtensions.cs | 5 +- .../CosmosPropertyBuilderExtensions.cs | 2 +- .../Extensions/CosmosPropertyExtensions.cs | 5 +- .../CosmosServiceCollectionExtensions.cs | 3 +- .../CosmosDbContextOptionsBuilder.cs | 4 +- .../Internal/CosmosDbOptionExtension.cs | 8 +- .../Internal/CosmosSingletonOptions.cs | 7 +- .../Internal/ICosmosSingletonOptions.cs | 6 +- .../Internal/CosmosModelValidator.cs | 8 +- .../CosmosDiscriminatorConvention.cs | 1 - .../Conventions/StoreKeyConvention.cs | 2 +- .../Internal/CosmosAnnotationNames.cs | 2 +- .../Internal/CosmosEntityTypeExtensions.cs | 6 +- .../Internal/CosmosNavigationExtensions.cs | 2 +- .../Query/Internal/ContainsTranslator.cs | 2 +- .../CosmosMemberTranslatorProvider.cs | 5 +- .../CosmosMethodCallTranslatorProvider.cs | 10 +- ...osmosProjectionBindingExpressionVisitor.cs | 8 +- .../Query/Internal/CosmosQueryContext.cs | 2 +- .../Internal/CosmosQueryContextFactory.cs | 2 +- ...yableMethodTranslatingExpressionVisitor.cs | 102 ++++--- ...thodTranslatingExpressionVisitorFactory.cs | 2 +- ...pressionVisitor.AsyncQueryingEnumerable.cs | 8 +- ...jectionBindingRemovingExpressionVisitor.cs | 40 ++- ...ressionValuesExpandingExpressionVisitor.cs | 14 +- ...sitor.JObjectInjectingExpressionVisitor.cs | 15 +- ...ingExpressionVisitor.QueryingEnumerable.cs | 2 +- ...osShapedQueryCompilingExpressionVisitor.cs | 3 +- ...dQueryCompilingExpressionVisitorFactory.cs | 2 +- .../CosmosSqlTranslatingExpressionVisitor.cs | 20 +- .../Internal/EntityProjectionExpression.cs | 3 +- .../Query/Internal/EqualsTranslator.cs | 7 +- .../Query/Internal/ExpressionExtensions.cs | 2 +- .../Query/Internal/IAccessExpression.cs | 2 +- .../Query/Internal/IMemberTranslator.cs | 2 +- .../Query/Internal/IMemberTranslatorPlugin.cs | 3 +- .../Internal/IMemberTranslatorProvider.cs | 2 +- .../Query/Internal/IMethodCallTranslator.cs | 2 +- .../Internal/IMethodCallTranslatorPlugin.cs | 3 +- .../Internal/IMethodCallTranslatorProvider.cs | 2 +- .../Internal/IQuerySqlGeneratorFactory.cs | 2 +- .../Query/Internal/ISqlExpressionFactory.cs | 2 +- .../Query/Internal/InExpression.cs | 16 +- .../Query/Internal/KeyAccessExpression.cs | 12 +- .../Query/Internal/ObjectAccessExpression.cs | 8 +- .../ObjectArrayProjectionExpression.cs | 2 +- .../Query/Internal/OrderingExpression.cs | 10 +- .../Query/Internal/ProjectionExpression.cs | 10 +- .../Query/Internal/QuerySqlGenerator.cs | 5 +- .../Internal/QuerySqlGeneratorFactory.cs | 2 +- .../Query/Internal/RootReferenceExpression.cs | 2 +- .../Query/Internal/SelectExpression.cs | 12 +- .../Query/Internal/SqlBinaryExpression.cs | 18 +- .../Internal/SqlConditionalExpression.cs | 14 +- .../Query/Internal/SqlConstantExpression.cs | 16 +- .../Query/Internal/SqlExpression.cs | 10 +- .../Query/Internal/SqlExpressionFactory.cs | 16 +- .../Query/Internal/SqlExpressionVisitor.cs | 2 +- .../Query/Internal/SqlFunctionExpression.cs | 13 +- .../Query/Internal/SqlParameterExpression.cs | 10 +- .../Query/Internal/SqlUnaryExpression.cs | 17 +- .../Storage/Internal/ByteArrayConverter.cs | 2 +- .../Storage/Internal/CosmosClientWrapper.cs | 28 +- .../Storage/Internal/CosmosDatabaseCreator.cs | 2 +- .../Storage/Internal/CosmosDatabaseWrapper.cs | 12 +- .../Internal/CosmosExecutionStrategy.cs | 2 +- .../CosmosExecutionStrategyFactory.cs | 6 +- .../Storage/Internal/CosmosSqlQuery.cs | 3 +- .../Internal/CosmosTransactionManager.cs | 2 +- .../Storage/Internal/CosmosTypeMapping.cs | 3 +- .../Storage/Internal/HttpException.cs | 2 +- .../Internal/SingletonCosmosClientWrapper.cs | 5 +- .../Storage/Internal/SqlParameter.cs | 2 +- .../Internal/IdValueGenerator.cs | 1 + .../Design/DbContextActivator.cs | 2 +- .../DesignTimeServiceCollectionExtensions.cs | 2 +- src/EFCore.Design/Design/ICSharpHelper.cs | 2 +- .../Design/ILanguageBasedService.cs | 2 +- .../Design/IOperationReportHandler.cs | 2 +- .../Design/IOperationResultHandler.cs | 2 +- src/EFCore.Design/Design/IPluralizer.cs | 2 +- .../Internal/AppServiceProviderFactory.cs | 2 +- .../Design/Internal/CSharpHelper.cs | 55 ++-- .../Design/Internal/DatabaseOperations.cs | 14 +- .../DesignTimeConnectionStringResolver.cs | 6 +- .../Internal/DesignTimeServicesBuilder.cs | 6 +- .../Design/Internal/IOperationReporter.cs | 2 +- .../Design/Internal/LanguageBasedSelector.cs | 2 +- .../Design/Internal/MigrationsOperations.cs | 6 +- .../Design/Internal/NamespaceComparer.cs | 2 +- .../Design/Internal/NullPluralizer.cs | 2 +- .../Design/Internal/OperationLogger.cs | 2 +- .../Design/Internal/OperationReporter.cs | 2 +- src/EFCore.Design/Design/OperationExecutor.cs | 30 +- .../Design/OperationResultHandler.cs | 2 +- .../Internal/ScaffoldingModelExtensions.cs | 1 - ...MigrationOperationGeneratorDependencies.cs | 2 +- .../Design/CSharpMigrationsGenerator.cs | 5 +- .../CSharpMigrationsGeneratorDependencies.cs | 2 +- .../Design/CSharpSnapshotGenerator.cs | 22 +- .../CSharpSnapshotGeneratorDependencies.cs | 2 +- .../IMigrationsCodeGeneratorSelector.cs | 2 +- .../Design/MigrationsCodeGenerator.cs | 9 +- .../MigrationsCodeGeneratorDependencies.cs | 2 +- .../Migrations/Design/MigrationsScaffolder.cs | 7 +- .../MigrationsScaffolderDependencies.cs | 2 +- .../MigrationsCodeGeneratorSelector.cs | 2 +- .../Internal/SnapshotModelProcessor.cs | 1 - .../Scaffolding/IModelCodeGenerator.cs | 2 +- .../IModelCodeGeneratorSelector.cs | 2 +- .../Scaffolding/IReverseEngineerScaffolder.cs | 2 +- .../Internal/CSharpDbContextGenerator.cs | 50 +--- .../Internal/CSharpEntityTypeGenerator.cs | 6 +- .../Internal/CSharpModelGenerator.cs | 8 +- .../Scaffolding/Internal/CSharpUtilities.cs | 6 +- .../Internal/CandidateNamingService.cs | 8 +- .../Internal/ICSharpDbContextGenerator.cs | 2 +- .../Internal/ICSharpEntityTypeGenerator.cs | 2 +- .../Scaffolding/Internal/ICSharpUtilities.cs | 10 +- .../Internal/ICandidateNamingService.cs | 2 +- .../Internal/IScaffoldingTypeMapper.cs | 2 +- .../Internal/ModelCodeGeneratorSelector.cs | 2 +- .../RelationalScaffoldingModelFactory.cs | 23 +- .../Internal/ReverseEngineerScaffolder.cs | 2 +- .../Internal/ScaffoldingTypeMapper.cs | 8 +- .../Internal/DatabaseColumnExtensions.cs | 2 +- .../Internal/DatabaseForeignKeyExtensions.cs | 2 +- .../Internal/DatabaseTableExtensions.cs | 2 +- .../Scaffolding/ModelCodeGenerationOptions.cs | 6 +- .../ModelCodeGeneratorDependencies.cs | 2 +- .../ModelReverseEngineerOptions.cs | 2 +- .../Scaffolding/ScaffoldedFile.cs | 2 +- .../Scaffolding/ScaffoldedModel.cs | 2 +- .../InMemoryServiceCollectionExtensions.cs | 3 +- .../Internal/IInMemorySingletonOptions.cs | 6 +- .../Internal/InMemorySingletonOptions.cs | 6 +- .../InMemoryConventionSetBuilder.cs | 21 +- .../Internal/EntityProjectionExpression.cs | 2 +- ...yExpressionTranslatingExpressionVisitor.cs | 59 ++-- .../Internal/InMemoryLinqOperatorProvider.cs | 6 +- ...emoryProjectionBindingExpressionVisitor.cs | 22 +- .../Query/Internal/InMemoryQueryContext.cs | 3 +- .../Internal/InMemoryQueryContextFactory.cs | 4 +- .../Query/Internal/InMemoryQueryExpression.cs | 58 ++-- .../InMemoryQueryTranslationPostprocessor.cs | 2 +- ...oryQueryTranslationPostprocessorFactory.cs | 2 +- ...yableMethodTranslatingExpressionVisitor.cs | 97 ++++--- ...thodTranslatingExpressionVisitorFactory.cs | 2 +- ....CustomShaperCompilingExpressionVisitor.cs | 1 - ...jectionBindingRemovingExpressionVisitor.cs | 2 +- ...ingExpressionVisitor.QueryingEnumerable.cs | 2 +- ...ryShapedQueryCompilingExpressionVisitor.cs | 2 +- ...moryShapedQueryExpressionVisitorFactory.cs | 3 +- .../Query/Internal/InMemoryTableExpression.cs | 3 +- ...erExpressionProcessingExpressionVisitor.cs | 5 +- .../Storage/Internal/IInMemoryDatabase.cs | 4 +- .../Storage/Internal/InMemoryDatabase.cs | 4 +- .../Internal/InMemoryDatabaseCreator.cs | 4 +- .../Storage/Internal/InMemoryTable.cs | 16 +- .../Storage/Internal/InMemoryTableFactory.cs | 3 +- .../Internal/InMemoryTransactionManager.cs | 4 +- .../Storage/Internal/InMemoryTypeMapping.cs | 5 +- .../Internal/InMemoryTypeMappingSource.cs | 8 +- .../InMemoryValueGeneratorSelector.cs | 4 +- .../Internal/ProxiesConventionSetPlugin.cs | 4 +- .../Proxies/Internal/ProxyBindingRewriter.cs | 9 +- .../Design/AnnotationCodeGenerator.cs | 2 +- .../AnnotationCodeGeneratorDependencies.cs | 2 +- .../Design/IAnnotationCodeGenerator.cs | 2 +- .../Design/MethodCallCodeFragment.cs | 2 +- .../Design/NestedClosureCodeFragment.cs | 2 +- .../Diagnostics/CommandCorrelatedEventData.cs | 4 +- .../Diagnostics/CommandEndEventData.cs | 2 +- .../Diagnostics/CommandErrorEventData.cs | 2 +- .../Diagnostics/CommandEventData.cs | 2 +- .../Diagnostics/CommandExecutedEventData.cs | 2 +- .../Diagnostics/DbCommandInterceptor.cs | 92 +++--- .../Diagnostics/DbConnectionInterceptor.cs | 38 +-- .../Diagnostics/DbTransactionInterceptor.cs | 58 ++-- .../Diagnostics/IDbCommandInterceptor.cs | 92 +++--- .../Diagnostics/IDbConnectionInterceptor.cs | 40 +-- .../Diagnostics/IDbTransactionInterceptor.cs | 73 +++-- .../Diagnostics/MigrationAssemblyEventData.cs | 2 +- .../Diagnostics/RelationalEventId.cs | 10 +- .../Diagnostics/RelationalLoggerExtensions.cs | 31 +- .../RelationalLoggingDefinitions.cs | 2 +- .../Diagnostics/TransactionEndEventData.cs | 2 +- .../TransactionEnlistedEventData.cs | 2 +- .../Diagnostics/TransactionErrorEventData.cs | 2 +- .../TransactionStartingEventData.cs | 4 +- .../Internal/MethodInfoExtensions.cs | 2 +- .../RelationalDatabaseFacadeExtensions.cs | 2 +- .../RelationalEntityTypeBuilderExtensions.cs | 3 +- .../RelationalEntityTypeExtensions.cs | 2 +- .../Extensions/RelationalKeyExtensions.cs | 1 - .../Extensions/RelationalModelExtensions.cs | 1 - .../RelationalPropertyExtensions.cs | 6 +- .../RelationalQueryableExtensions.cs | 9 +- ...alDbContextOptionsBuilderInfrastructure.cs | 2 +- .../RelationalDbContextOptionsBuilder.cs | 1 - .../RelationalModelCustomizer.cs | 8 +- .../RelationalModelValidator.cs | 44 +-- .../RelationalModelValidatorDependencies.cs | 6 +- .../RelationalOptionsExtension.cs | 4 +- .../IRelationalDatabaseFacadeDependencies.cs | 4 +- .../Metadata/Builders/DbFunctionBuilder.cs | 8 +- .../Builders/DbFunctionParameterBuilder.cs | 14 +- .../IConventionDbFunctionParameterBuilder.cs | 2 +- .../DbFunctionTypeMappingConvention.cs | 4 +- .../RelationalConventionSetBuilder.cs | 6 +- .../RelationalColumnAttributeConvention.cs | 2 +- ...RelationalDbFunctionAttributeConvention.cs | 11 +- ...yFilterDefiningQueryRewritingConvention.cs | 13 +- .../RelationalTableAttributeConvention.cs | 2 +- .../RelationalValueGenerationConvention.cs | 4 +- .../Conventions/SharedTableConvention.cs | 19 +- .../TableNameFromDbSetConvention.cs | 2 +- .../Metadata/IConventionCheckConstraint.cs | 2 +- .../Metadata/IConventionDbFunction.cs | 5 +- .../IConventionDbFunctionParameter.cs | 4 +- src/EFCore.Relational/Metadata/IDbFunction.cs | 2 +- .../Metadata/IDbFunctionParameter.cs | 2 +- .../Metadata/IMutableDbFunction.cs | 2 +- .../Metadata/IMutableDbFunctionParameter.cs | 2 +- .../Metadata/Internal/CheckConstraint.cs | 6 +- .../Metadata/Internal/DbFunctionParameter.cs | 2 +- .../RelationalForeignKeyExtensions.cs | 3 +- .../Internal/RelationalIndexExtensions.cs | 2 +- .../Metadata/Internal/Sequence.cs | 5 +- .../Metadata/Internal/TableMapping.cs | 11 +- .../Migrations/HistoryRepository.cs | 6 +- .../HistoryRepositoryDependencies.cs | 6 +- .../Migrations/IHistoryRepository.cs | 4 +- .../Migrations/IMigrationCommandExecutor.cs | 8 +- .../IMigrationsAnnotationProvider.cs | 6 +- .../Migrations/IMigrationsAssembly.cs | 4 +- .../Migrations/IMigrationsIdGenerator.cs | 6 +- .../Migrations/IMigrationsModelDiffer.cs | 4 +- .../Migrations/IMigrationsSqlGenerator.cs | 4 +- src/EFCore.Relational/Migrations/IMigrator.cs | 4 +- .../Internal/MigrationCommandExecutor.cs | 9 +- .../Migrations/Internal/MigrationsAssembly.cs | 4 +- .../Internal/MigrationsIdGenerator.cs | 6 +- .../Migrations/Internal/Migrator.cs | 4 +- .../Migrations/MigrationBuilder.cs | 169 ++--------- .../Migrations/MigrationCommand.cs | 4 +- .../MigrationsAnnotationProvider.cs | 6 +- ...igrationsAnnotationProviderDependencies.cs | 6 +- .../Migrations/MigrationsSqlGenerator.cs | 86 +++--- .../MigrationsSqlGeneratorDependencies.cs | 6 +- .../Operations/AlterTableOperation.cs | 1 - .../Operations/Builders/CreateTableBuilder.cs | 15 +- .../CreateCheckConstraintOperation.cs | 8 +- .../Query/CollectionInitializingExpression.cs | 2 +- .../Query/CollectionPopulatingExpression.cs | 2 +- .../Query/EntityProjectionExpression.cs | 27 +- .../Query/ExpressionExtensions.cs | 2 +- .../Query/IMemberTranslator.cs | 2 +- .../Query/IMemberTranslatorPlugin.cs | 8 +- .../Query/IMemberTranslatorProvider.cs | 10 +- .../Query/IMethodCallTranslator.cs | 2 +- .../Query/IMethodCallTranslatorPlugin.cs | 8 +- .../Query/IMethodCallTranslatorProvider.cs | 10 +- .../Query/IQuerySqlGeneratorFactory.cs | 10 +- ...lSqlTranslatingExpressionVisitorFactory.cs | 10 +- .../Query/ISqlExpressionFactory.cs | 34 ++- ...CollectionJoinApplyingExpressionVisitor.cs | 2 +- .../Query/Internal/ComparisonTranslator.cs | 15 +- .../Query/Internal/ContainsTranslator.cs | 5 +- .../Query/Internal/EnumHasFlagTranslator.cs | 2 +- .../Query/Internal/EqualsTranslator.cs | 13 +- .../Internal/GetValueOrDefaultTranslator.cs | 7 +- .../Query/Internal/LikeTranslator.cs | 2 +- ...ComparisonTransformingExpressionVisitor.cs | 2 +- ...NullSemanticsRewritingExpressionVisitor.cs | 10 +- .../Internal/NullableMemberTranslator.cs | 2 +- .../Internal/QuerySqlGeneratorFactory.cs | 2 +- ...ionalProjectionBindingExpressionVisitor.cs | 39 +-- .../Internal/RelationalQueryContextFactory.cs | 9 +- ...nalQueryTranslationPostprocessorFactory.cs | 10 +- ...onalQueryTranslationPreprocessorFactory.cs | 10 +- ...thodTranslatingExpressionVisitorFactory.cs | 10 +- ...dQueryCompilingExpressionVisitorFactory.cs | 10 +- ...ranslatingExpressionVisitorDependencies.cs | 18 +- ...sionProjectionApplyingExpressionVisitor.cs | 3 +- ...qlExpressionOptimizingExpressionVisitor.cs | 2 +- .../Query/Internal/StringMethodTranslator.cs | 2 +- .../TableAliasUniquifyingExpressionVisitor.cs | 3 +- .../Query/QuerySqlGenerator.cs | 52 ++-- .../Query/QuerySqlGeneratorDependencies.cs | 8 +- .../RelationalCollectionShaperExpression.cs | 9 +- ...elationalCompiledQueryCacheKeyGenerator.cs | 4 +- ...piledQueryCacheKeyGeneratorDependencies.cs | 4 +- .../RelationalEvaluatableExpressionFilter.cs | 9 +- ...EvaluatableExpressionFilterDependencies.cs | 6 +- .../RelationalMemberTranslatorProvider.cs | 7 +- ...nalMemberTranslatorProviderDependencies.cs | 6 +- .../RelationalMethodCallTranslatorProvider.cs | 22 +- ...ethodCallTranslatorProviderDependencies.cs | 6 +- .../RelationalQueryContextDependencies.cs | 4 +- ...eryTranslationPostprocessorDependencies.cs | 8 +- ...ueryTranslationPreprocessorDependencies.cs | 6 +- ...yableMethodTranslatingExpressionVisitor.cs | 122 ++++---- ...ranslatingExpressionVisitorDependencies.cs | 15 +- ...pressionVisitor.AsyncQueryingEnumerable.cs | 13 +- ....CustomShaperCompilingExpressionVisitor.cs | 36 +-- ...omSqlParameterApplyingExpressionVisitor.cs | 3 +- ...ressionValuesExpandingExpressionVisitor.cs | 17 +- ...eterValueBasedSelectExpressionOptimizer.cs | 2 +- ...ingExpressionVisitor.QueryingEnumerable.cs | 15 +- ...jectionBindingRemovingExpressionVisitor.cs | 10 +- ...erExpressionProcessingExpressionVisitor.cs | 72 ++--- ...alShapedQueryCompilingExpressionVisitor.cs | 17 +- ...yCompilingExpressionVisitorDependencies.cs | 10 +- ...lationalSqlTranslatingExpressionVisitor.cs | 85 +++--- .../Query/SqlExpressionFactory.cs | 74 ++--- .../Query/SqlExpressionFactoryDependencies.cs | 6 +- .../Query/SqlExpressionVisitor.cs | 2 +- .../Query/SqlExpressions/CaseExpression.cs | 18 +- .../Query/SqlExpressions/CaseWhenClause.cs | 10 +- .../Query/SqlExpressions/ColumnExpression.cs | 26 +- .../SqlExpressions/CrossApplyExpression.cs | 8 +- .../SqlExpressions/CrossJoinExpression.cs | 8 +- .../Query/SqlExpressions/ExceptExpression.cs | 10 +- .../Query/SqlExpressions/ExistsExpression.cs | 13 +- .../Query/SqlExpressions/InExpression.cs | 19 +- .../SqlExpressions/InnerJoinExpression.cs | 8 +- .../SqlExpressions/IntersectExpression.cs | 10 +- .../SqlExpressions/JoinExpressionBase.cs | 10 +- .../SqlExpressions/LeftJoinExpression.cs | 8 +- .../Query/SqlExpressions/LikeExpression.cs | 14 +- .../SqlExpressions/OrderingExpression.cs | 11 +- .../SqlExpressions/OuterApplyExpression.cs | 8 +- .../PredicateJoinExpressionBase.cs | 10 +- .../SqlExpressions/ProjectionExpression.cs | 12 +- .../SqlExpressions/RowNumberExpression.cs | 18 +- .../ScalarSubqueryExpression.cs | 13 +- .../Query/SqlExpressions/SelectExpression.cs | 222 ++++++++------ .../Query/SqlExpressions/SetOperationBase.cs | 12 +- .../SqlExpressions/SqlBinaryExpression.cs | 20 +- .../SqlExpressions/SqlConstantExpression.cs | 12 +- .../Query/SqlExpressions/SqlExpression.cs | 10 +- .../SqlExpressions/SqlFragmentExpression.cs | 11 +- .../SqlExpressions/SqlFunctionExpression.cs | 22 +- .../SqlExpressions/SqlParameterExpression.cs | 12 +- .../SqlExpressions/SqlUnaryExpression.cs | 16 +- .../Query/SqlExpressions/TableExpression.cs | 2 +- .../SqlExpressions/TableExpressionBase.cs | 9 +- .../Query/SqlExpressions/UnionExpression.cs | 10 +- .../Scaffolding/DatabaseModelFactory.cs | 2 +- .../DatabaseModelFactoryOptions.cs | 8 +- .../IProviderCodeGeneratorPlugin.cs | 2 +- .../IProviderConfigurationCodeGenerator.cs | 2 +- .../Metadata/DatabasePrimaryKey.cs | 2 +- .../Metadata/DatabaseUniqueConstraint.cs | 2 +- .../Scaffolding/Metadata/DatabaseView.cs | 2 +- .../Scaffolding/ProviderCodeGenerator.cs | 2 +- .../ProviderCodeGeneratorDependencies.cs | 2 +- .../ProviderCodeGeneratorPlugin.cs | 2 +- .../Storage/IParameterNameGeneratorFactory.cs | 6 +- .../Storage/IRawSqlCommandBuilder.cs | 6 +- .../Storage/IRelationalCommand.cs | 2 +- .../Storage/IRelationalCommandBuilder.cs | 4 +- .../IRelationalCommandBuilderFactory.cs | 6 +- .../Storage/IRelationalConnection.cs | 6 +- .../Storage/IRelationalDatabaseCreator.cs | 4 +- .../Storage/IRelationalTransactionFactory.cs | 6 +- .../Storage/IRelationalTransactionManager.cs | 8 +- .../Storage/IRelationalTypeMappingSource.cs | 6 +- .../IRelationalTypeMappingSourcePlugin.cs | 8 +- .../IRelationalValueBufferFactoryFactory.cs | 6 +- .../Storage/ISqlGenerationHelper.cs | 6 +- .../Internal/DynamicRelationalParameter.cs | 2 +- .../INamedConnectionStringResolver.cs | 4 +- .../Internal/NamedConnectionStringResolver.cs | 4 +- .../NamedConnectionStringResolverBase.cs | 4 +- .../Internal/RawRelationalParameter.cs | 2 +- .../Storage/Internal/RawSqlCommandBuilder.cs | 6 +- .../TypeMappedPropertyRelationalParameter.cs | 3 +- .../Internal/TypeMappedRelationalParameter.cs | 2 +- .../ParameterNameGeneratorDependencies.cs | 6 +- .../Storage/ParameterNameGeneratorFactory.cs | 6 +- .../Storage/RawSqlCommand.cs | 2 +- .../Storage/RelationalCommand.cs | 5 +- .../Storage/RelationalCommandBuilder.cs | 4 +- .../RelationalCommandBuilderDependencies.cs | 8 +- .../RelationalCommandBuilderFactory.cs | 10 +- .../RelationalCommandParameterObject.cs | 4 +- .../Storage/RelationalConnection.cs | 18 +- .../RelationalConnectionDependencies.cs | 6 +- .../Storage/RelationalDataReader.cs | 1 - .../Storage/RelationalDatabase.cs | 4 +- .../Storage/RelationalDatabaseCreator.cs | 11 +- .../RelationalDatabaseCreatorDependencies.cs | 6 +- .../Storage/RelationalDatabaseDependencies.cs | 4 +- .../RelationalExecutionStrategyExtensions.cs | 2 +- .../RelationalExecutionStrategyFactory.cs | 4 +- .../Storage/RelationalSqlGenerationHelper.cs | 6 +- ...lationalSqlGenerationHelperDependencies.cs | 6 +- .../Storage/RelationalTransaction.cs | 5 +- .../Storage/RelationalTransactionFactory.cs | 6 +- ...elationalTransactionFactoryDependencies.cs | 6 +- .../Storage/RelationalTypeMapping.cs | 2 +- .../Storage/RelationalTypeMappingInfo.cs | 20 +- .../Storage/RelationalTypeMappingSource.cs | 35 ++- ...RelationalTypeMappingSourceDependencies.cs | 6 +- ...elationalValueBufferFactoryDependencies.cs | 6 +- ...ypedRelationalValueBufferFactoryFactory.cs | 9 +- .../Update/ColumnModification.cs | 9 +- .../Update/IBatchExecutor.cs | 4 +- .../Update/ICommandBatchPreparer.cs | 4 +- .../IModificationCommandBatchFactory.cs | 4 +- .../Update/IUpdateSqlGenerator.cs | 9 +- .../Update/Internal/BatchExecutor.cs | 4 +- .../Update/Internal/CommandBatchPreparer.cs | 15 +- .../CommandBatchPreparerDependencies.cs | 4 +- .../Internal/IKeyValueIndexFactorySource.cs | 6 +- .../Internal/KeyValueIndexFactorySource.cs | 6 +- .../Internal/ModificationCommandComparer.cs | 6 +- .../Update/Internal/SharedTableEntryMap.cs | 3 +- .../Update/ModificationCommand.cs | 12 +- ...ficationCommandBatchFactoryDependencies.cs | 6 +- .../Update/ReaderModificationCommandBatch.cs | 3 +- .../Update/UpdateSqlGenerator.cs | 12 +- .../Update/UpdateSqlGeneratorDependencies.cs | 6 +- .../RelationalValueGeneratorSelector.cs | 4 +- ...erverNetTopologySuiteDesignTimeServices.cs | 2 +- ...ySuiteDbContextOptionsBuilderExtensions.cs | 2 +- ...opologySuiteServiceCollectionExtensions.cs | 2 +- ...lServerNetTopologySuiteOptionsExtension.cs | 2 +- ...erverGeometryCollectionMemberTranslator.cs | 2 +- ...erverGeometryCollectionMethodTranslator.cs | 5 +- .../SqlServerGeometryMemberTranslator.cs | 45 ++- .../SqlServerGeometryMethodTranslator.cs | 12 +- .../SqlServerLineStringMemberTranslator.cs | 9 +- .../SqlServerLineStringMethodTranslator.cs | 8 +- ...qlServerMultiLineStringMemberTranslator.cs | 2 +- ...rNetTopologySuiteMemberTranslatorPlugin.cs | 11 +- ...TopologySuiteMethodCallTranslatorPlugin.cs | 11 +- .../SqlServerPointMemberTranslator.cs | 11 +- .../SqlServerPolygonMemberTranslator.cs | 8 +- .../SqlServerPolygonMethodTranslator.cs | 33 +-- ...rverNetTopologySuiteCodeGeneratorPlugin.cs | 2 +- .../Internal/SqlServerGeometryTypeMapping.cs | 12 +- ...NetTopologySuiteTypeMappingSourcePlugin.cs | 11 +- .../Internal/GeometryValueConverter.cs | 2 +- .../SqlServerAnnotationCodeGenerator.cs | 2 +- .../Diagnostics/SqlServerEventId.cs | 6 +- .../SqlServerDbFunctionsExtensions.cs | 2 +- .../SqlServerMigrationBuilderExtensions.cs | 8 +- .../Extensions/SqlServerPropertyExtensions.cs | 4 +- .../SqlServerServiceCollectionExtensions.cs | 4 +- .../Internal/ISqlServerOptions.cs | 6 +- .../Internal/SqlServerModelValidator.cs | 20 +- .../Internal/SqlServerOptions.cs | 6 +- .../SqlServerConventionSetBuilder.cs | 5 +- .../SqlServerStoreGenerationConvention.cs | 4 +- .../SqlServerValueGenerationConvention.cs | 14 +- ...ServerValueGenerationStrategyConvention.cs | 7 +- .../Internal/SqlServerHistoryRepository.cs | 4 +- .../SqlServerMigrationsAnnotationProvider.cs | 7 +- .../SqlServerMigrationsSqlGenerator.cs | 58 ++-- .../Properties/AssemblyInfo.cs | 2 +- ...rchConditionConvertingExpressionVisitor.cs | 30 +- ...SqlServerCompiledQueryCacheKeyGenerator.cs | 4 +- .../Internal/SqlServerConvertTranslator.cs | 9 +- .../SqlServerDateDiffFunctionsTranslator.cs | 10 +- .../SqlServerDateTimeMemberTranslator.cs | 20 +- .../SqlServerDateTimeMethodTranslator.cs | 7 +- ...ServerFullTextSearchFunctionsTranslator.cs | 17 +- .../SqlServerIsDateFunctionTranslator.cs | 11 +- .../Query/Internal/SqlServerMathTranslator.cs | 9 +- .../SqlServerMemberTranslatorProvider.cs | 5 +- .../SqlServerMethodCallTranslatorProvider.cs | 27 +- .../Internal/SqlServerNewGuidTranslator.cs | 2 +- .../SqlServerObjectToStringTranslator.cs | 9 +- .../Internal/SqlServerQuerySqlGenerator.cs | 1 - .../SqlServerQueryTranslationPostprocessor.cs | 2 +- ...verQueryTranslationPostprocessorFactory.cs | 2 +- ...qlServerSqlTranslatingExpressionVisitor.cs | 11 +- ...rSqlTranslatingExpressionVisitorFactory.cs | 2 +- .../SqlServerStringMemberTranslator.cs | 2 +- .../SqlServerStringMethodTranslator.cs | 81 ++---- .../Internal/SqlServerCodeGenerator.cs | 2 +- .../Internal/SqlServerDatabaseModelFactory.cs | 53 ++-- .../Storage/Internal/ISqlServerConnection.cs | 4 +- .../Internal/SqlServerBoolTypeMapping.cs | 2 +- .../Internal/SqlServerByteTypeMapping.cs | 2 +- .../Storage/Internal/SqlServerConnection.cs | 9 +- .../Internal/SqlServerDatabaseCreator.cs | 24 +- .../Internal/SqlServerDateTimeTypeMapping.cs | 5 +- .../SqlServerExecutionStrategyFactory.cs | 4 +- .../Internal/SqlServerLongTypeMapping.cs | 2 +- .../Internal/SqlServerShortTypeMapping.cs | 2 +- .../Internal/SqlServerSqlGenerationHelper.cs | 6 +- .../Internal/SqlServerTypeMappingSource.cs | 9 +- .../Internal/SqlServerUdtTypeMapping.cs | 3 +- .../Internal/ISqlServerUpdateSqlGenerator.cs | 6 +- .../SqlServerModificationCommandBatch.cs | 3 +- ...qlServerModificationCommandBatchFactory.cs | 4 +- .../Internal/SqlServerUpdateSqlGenerator.cs | 25 +- .../Internal/ISqlServerValueGeneratorCache.cs | 6 +- .../SqlServerSequenceValueGeneratorFactory.cs | 30 +- .../Internal/SqlServerValueGeneratorCache.cs | 6 +- .../SqlServerValueGeneratorSelector.cs | 4 +- .../Internal/SqliteLoggingDefinitions.cs | 2 +- .../Diagnostics/SqliteEventId.cs | 8 +- .../SqliteMigrationBuilderExtensions.cs | 8 +- .../SqlitePropertyBuilderExtensions.cs | 2 +- .../Extensions/SqlitePropertyExtensions.cs | 2 +- .../SqliteServiceCollectionExtensions.cs | 3 +- .../Infrastructure/SpatialiteLoader.cs | 4 +- .../Internal/SqliteLoggerExtensions.cs | 2 +- .../Internal/SqliteModelValidator.cs | 14 +- .../Conventions/SqliteConventionSetBuilder.cs | 2 +- .../Internal/SqliteHistoryRepository.cs | 4 +- .../SqliteMigrationsAnnotationProvider.cs | 8 +- .../SqliteMigrationsSqlGenerator.cs | 34 +-- .../Properties/AssemblyInfo.cs | 2 +- .../Internal/SqliteDateTimeAddTranslator.cs | 5 +- .../SqliteDateTimeMemberTranslator.cs | 2 +- .../Query/Internal/SqliteExpression.cs | 8 +- .../Query/Internal/SqliteMathTranslator.cs | 2 +- .../SqliteMemberTranslatorProvider.cs | 5 +- .../SqliteMethodCallTranslatorProvider.cs | 4 +- .../Query/Internal/SqliteQuerySqlGenerator.cs | 9 +- .../SqliteQuerySqlGeneratorFactory.cs | 2 +- ...yableMethodTranslatingExpressionVisitor.cs | 13 +- ...thodTranslatingExpressionVisitorFactory.cs | 2 +- .../SqliteSqlTranslatingExpressionVisitor.cs | 13 +- ...eSqlTranslatingExpressionVisitorFactory.cs | 2 +- .../Internal/SqliteStringLengthTranslator.cs | 4 +- .../Internal/SqliteStringMethodTranslator.cs | 43 ++- .../Internal/SqliteCodeGenerator.cs | 2 +- .../Internal/SqliteDatabaseModelFactory.cs | 36 +-- .../Internal/ISqliteRelationalConnection.cs | 4 +- .../Storage/Internal/SqliteDatabaseCreator.cs | 4 +- .../Internal/SqliteDecimalTypeMapping.cs | 2 +- .../Internal/SqliteRelationalConnection.cs | 9 +- .../Internal/SqliteSqlGenerationHelper.cs | 6 +- .../Internal/SqliteTypeMappingSource.cs | 11 +- .../Internal/SqliteULongTypeMapping.cs | 2 +- .../SqliteModificationCommandBatchFactory.cs | 4 +- .../Internal/SqliteUpdateSqlGenerator.cs | 9 +- ...qliteNetTopologySuiteDesignTimeServices.cs | 2 +- ...ySuiteDbContextOptionsBuilderExtensions.cs | 2 +- ...tTopologySuitePropertyBuilderExtensions.cs | 2 +- ...opologySuiteServiceCollectionExtensions.cs | 2 +- .../SqliteNetTopologySuiteOptionsExtension.cs | 2 +- ...qliteGeometryCollectionMemberTranslator.cs | 2 +- ...qliteGeometryCollectionMethodTranslator.cs | 5 +- .../SqliteGeometryMemberTranslator.cs | 34 +-- .../SqliteGeometryMethodTranslator.cs | 17 +- .../SqliteLineStringMemberTranslator.cs | 2 +- .../SqliteLineStringMethodTranslator.cs | 6 +- .../SqliteMultiLineStringMemberTranslator.cs | 5 +- ...eNetTopologySuiteMemberTranslatorPlugin.cs | 9 +- ...TopologySuiteMethodCallTranslatorPlugin.cs | 9 +- .../Internal/SqlitePointMemberTranslator.cs | 3 +- .../Internal/SqlitePolygonMemberTranslator.cs | 3 +- .../Internal/SqlitePolygonMethodTranslator.cs | 7 +- ...liteNetTopologySuiteCodeGeneratorPlugin.cs | 2 +- .../Internal/SqliteGeometryTypeMapping.cs | 2 +- ...NetTopologySuiteTypeMappingSourcePlugin.cs | 8 +- .../Internal/GeometryValueConverter.cs | 2 +- src/EFCore/ChangeTracking/ChangeTracker.cs | 6 +- src/EFCore/ChangeTracking/CollectionEntry.cs | 16 +- src/EFCore/ChangeTracking/CollectionEntry`.cs | 4 +- src/EFCore/ChangeTracking/EntityEntry.cs | 2 +- src/EFCore/ChangeTracking/EntityEntry`.cs | 1 - .../ChangeTracking/GeometryValueComparer.cs | 2 +- .../IEntityEntryGraphIterator.cs | 6 +- .../ChangeTracking/Internal/ChangeDetector.cs | 7 +- .../Internal/ChangeTrackerFactory.cs | 4 +- .../Internal/CompositeValueFactory.cs | 1 + .../Internal/EntityEntryGraphIterator.cs | 6 +- .../Internal/EntityGraphAttacher.cs | 4 +- .../Internal/EntityReferenceMap.cs | 3 + .../Internal/IChangeDetector.cs | 4 +- .../Internal/IChangeTrackerFactory.cs | 4 +- .../Internal/IEntityGraphAttacher.cs | 4 +- .../ChangeTracking/Internal/IIdentityMap.cs | 6 +- .../Internal/IInternalEntityEntryFactory.cs | 6 +- .../Internal/IInternalEntityEntryNotifier.cs | 4 +- .../IInternalEntityEntrySubscriber.cs | 6 +- .../ChangeTracking/Internal/IKeyPropagator.cs | 4 +- .../Internal/ILocalViewListener.cs | 4 +- .../Internal/INavigationFixer.cs | 4 +- .../ChangeTracking/Internal/IStateManager.cs | 16 +- .../Internal/IValueGenerationManager.cs | 4 +- .../ChangeTracking/Internal/IdentityMap.cs | 41 ++- .../Internal/IdentityMapFactoryFactory.cs | 3 +- .../Internal/InternalEntityEntry.cs | 10 +- .../Internal/InternalEntityEntryFactory.cs | 9 +- .../Internal/InternalEntityEntryNotifier.cs | 4 +- .../Internal/InternalEntityEntrySubscriber.cs | 6 +- .../Internal/InternalMixedEntityEntry.cs | 2 +- .../ChangeTracking/Internal/KeyPropagator.cs | 8 +- .../Internal/LocalViewListener.cs | 4 +- .../Internal/NavigationFixer.cs | 22 +- .../Internal/NullableKeyIdentityMap.cs | 1 - .../SimpleNullableDependentKeyValueFactory.cs | 3 +- .../Internal/SnapshotFactoryFactory.cs | 5 +- .../ChangeTracking/Internal/StateManager.cs | 33 ++- .../Internal/StateManagerDependencies.cs | 4 +- .../Internal/ValueGenerationManager.cs | 4 +- src/EFCore/ChangeTracking/LocalView.cs | 7 +- src/EFCore/ChangeTracking/NavigationEntry.cs | 5 +- src/EFCore/ChangeTracking/ReferenceEntry.cs | 2 +- src/EFCore/ChangeTracking/ValueComparer.cs | 6 +- src/EFCore/DbContext.cs | 2 +- src/EFCore/DbContextOptions.cs | 2 +- src/EFCore/DbContextOptions`.cs | 2 +- src/EFCore/DbFunctions.cs | 2 +- src/EFCore/DbFunctionsExtensions.cs | 2 +- src/EFCore/DbSet.cs | 12 +- src/EFCore/DeleteBehavior.cs | 7 +- src/EFCore/Design/IDesignTimeServices.cs | 2 +- src/EFCore/Diagnostics/CoreEventId.cs | 12 +- .../Diagnostics/CoreLoggerExtensions.cs | 61 +--- src/EFCore/Diagnostics/EventDefinitionBase.cs | 15 +- src/EFCore/Diagnostics/IDiagnosticsLogger.cs | 6 +- src/EFCore/Diagnostics/IDiagnosticsLogger`.cs | 4 +- src/EFCore/Diagnostics/IInterceptor.cs | 2 +- src/EFCore/Diagnostics/ILoggingOptions.cs | 6 +- src/EFCore/Diagnostics/InterceptionResult.cs | 4 +- src/EFCore/Diagnostics/InterceptionResult`.cs | 6 +- .../Diagnostics/Internal/Interceptors.cs | 6 +- .../Diagnostics/ValueConverterEventData.cs | 2 +- .../ConventionAnnotatableExtensions.cs | 3 +- .../ConventionEntityTypeExtensions.cs | 9 +- .../Extensions/ConventionModelExtensions.cs | 5 +- .../ConventionTypeBaseExtensions.cs | 2 +- .../EntityFrameworkQueryableExtensions.cs | 84 ++++-- src/EFCore/Extensions/EntityTypeExtensions.cs | 7 +- .../Internal/EFPropertyExtensions.cs | 2 +- .../Internal/ExpressionExtensions.cs | 12 +- .../Internal/MethodInfoExtensions.cs | 2 +- .../Internal/QueryableExtensions.cs | 5 +- .../Extensions/Internal/TypeExtensions.cs | 4 +- .../Extensions/MutableEntityTypeExtensions.cs | 4 +- .../Extensions/MutableModelExtensions.cs | 2 +- .../TransactionsDatabaseFacadeExtensions.cs | 6 +- src/EFCore/IQueryTypeConfiguration.cs | 2 +- .../Infrastructure/AccessorExtensions.cs | 1 - src/EFCore/Infrastructure/Annotatable.cs | 2 +- .../Infrastructure/CoreOptionsExtension.cs | 2 +- .../DbContextOptionsExtensionInfo.cs | 2 +- .../EntityFrameworkServicesBuilder.cs | 8 +- .../Infrastructure/ExpressionExtensions.cs | 5 +- .../Infrastructure/IConcurrencyDetector.cs | 6 +- .../Infrastructure/ICoreSingletonOptions.cs | 8 +- .../Infrastructure/ICurrentDbContext.cs | 8 +- .../Infrastructure/IDbContextOptions.cs | 4 +- .../Infrastructure/IModelCacheKeyFactory.cs | 6 +- src/EFCore/Infrastructure/IModelCustomizer.cs | 6 +- src/EFCore/Infrastructure/IModelSource.cs | 6 +- src/EFCore/Infrastructure/IModelValidator.cs | 6 +- .../Infrastructure/IResettableService.cs | 6 +- .../Infrastructure/ISingletonOptions.cs | 6 +- .../Internal/DbContextOptionsExtensions.cs | 2 +- .../Infrastructure/ModelCacheKeyFactory.cs | 6 +- .../ModelCacheKeyFactoryDependencies.cs | 6 +- src/EFCore/Infrastructure/ModelCustomizer.cs | 6 +- .../ModelCustomizerDependencies.cs | 6 +- src/EFCore/Infrastructure/ModelSource.cs | 8 +- .../Infrastructure/ModelSourceDependencies.cs | 6 +- src/EFCore/Infrastructure/ModelValidator.cs | 63 ++-- .../ModelValidatorDependencies.cs | 6 +- src/EFCore/Infrastructure/TypeExtensions.cs | 2 +- src/EFCore/Infrastructure/Uniquifier.cs | 2 +- src/EFCore/Internal/ConcurrencyDetector.cs | 4 +- src/EFCore/Internal/CoreOptions.cs | 8 +- src/EFCore/Internal/CurrentDbContext.cs | 4 +- src/EFCore/Internal/DbContextPool.cs | 2 +- .../DbContextPoolConfigurationSnapshot.cs | 2 +- src/EFCore/Internal/DbContextServices.cs | 4 +- src/EFCore/Internal/DbSetFinder.cs | 6 +- src/EFCore/Internal/DbSetInitializer.cs | 6 +- src/EFCore/Internal/DbSetProperty.cs | 1 - src/EFCore/Internal/DbSetSource.cs | 8 +- src/EFCore/Internal/DiagnosticsLogger.cs | 4 +- src/EFCore/Internal/EntityFinder.cs | 18 +- src/EFCore/Internal/EntityFinderSource.cs | 8 +- src/EFCore/Internal/Graph.cs | 2 +- .../Internal/IDatabaseFacadeDependencies.cs | 4 +- src/EFCore/Internal/IDbContextDependencies.cs | 4 +- src/EFCore/Internal/IDbContextPool.cs | 2 +- src/EFCore/Internal/IDbContextPoolable.cs | 2 +- src/EFCore/Internal/IDbContextServices.cs | 4 +- src/EFCore/Internal/IDbSetFinder.cs | 6 +- src/EFCore/Internal/IDbSetInitializer.cs | 6 +- src/EFCore/Internal/IDbSetSource.cs | 6 +- src/EFCore/Internal/IEntityFinderSource.cs | 6 +- src/EFCore/Internal/IRegisteredServices.cs | 6 +- .../Internal/ISingletonOptionsInitializer.cs | 6 +- src/EFCore/Internal/InternalDbSet.cs | 2 +- src/EFCore/Internal/LazyLoader.cs | 5 +- src/EFCore/Internal/LoggingOptions.cs | 6 +- src/EFCore/Internal/Multigraph.cs | 12 +- .../ReferenceEnumerableEqualityComparer.cs | 1 + src/EFCore/Internal/RegisteredServices.cs | 6 +- .../Internal/SemanticVersionComparer.cs | 2 +- src/EFCore/Internal/ServiceProviderCache.cs | 7 +- .../Internal/SingletonOptionsInitializer.cs | 6 +- .../Builders/CollectionNavigationBuilder`.cs | 1 - .../Metadata/Builders/EntityTypeBuilder`.cs | 3 +- .../Builders/IConventionPropertyBuilder.cs | 2 +- .../IConventionServicePropertyBuilder.cs | 3 +- src/EFCore/Metadata/Builders/IndexBuilder.cs | 2 +- src/EFCore/Metadata/Builders/KeyBuilder.cs | 2 +- .../Builders/OwnedEntityTypeBuilder.cs | 2 +- .../Builders/OwnedEntityTypeBuilder`.cs | 2 +- .../Builders/OwnedNavigationBuilder`.cs | 2 +- .../Metadata/Builders/OwnershipBuilder`.cs | 2 +- .../Metadata/Builders/QueryTypeBuilder`.cs | 2 +- .../Builders/ReferenceNavigationBuilder.cs | 12 +- .../Builders/ReferenceNavigationBuilder`.cs | 1 - .../Conventions/CascadeDeleteConvention.cs | 4 +- .../ChangeTrackingStrategyConvention.cs | 2 +- .../ConcurrencyCheckAttributeConvention.cs | 2 +- .../DatabaseGeneratedAttributeConvention.cs | 8 +- .../Conventions/DbSetFindingConvention.cs | 7 +- .../ForeignKeyAttributeConvention.cs | 15 +- .../Conventions/ForeignKeyIndexConvention.cs | 3 +- .../ForeignKeyPropertyDiscoveryConvention.cs | 11 +- .../IEntityTypeRemovedConvention.cs | 2 +- ...ForeignKeyRequirednessChangedConvention.cs | 2 +- .../IModelAnnotationChangedConvention.cs | 2 +- .../Conventions/IModelFinalizedConvention.cs | 3 +- .../IModelInitializedConvention.cs | 3 +- ...roviderConventionSetBuilderDependencies.cs | 5 +- .../Internal/ConventionDispatcher.cs | 4 +- .../Conventions/Internal/ConventionNode.cs | 12 +- .../Conventions/Internal/ConventionVisitor.cs | 4 +- .../InversePropertyAttributeConvention.cs | 11 +- .../Conventions/KeyAttributeConvention.cs | 7 +- .../MaxLengthAttributeConvention.cs | 2 +- .../NavigationAttributeConventionBase.cs | 2 +- .../NonNullableNavigationConvention.cs | 4 +- .../NonNullableReferencePropertyConvention.cs | 1 - .../NotMappedEntityTypeAttributeConvention.cs | 2 +- .../NotMappedMemberAttributeConvention.cs | 2 +- .../OwnedEntityTypeAttributeConvention.cs | 4 +- .../PropertyDiscoveryConvention.cs | 2 +- ...yFilterDefiningQueryRewritingConvention.cs | 8 +- .../RelationshipDiscoveryConvention.cs | 31 +- .../RequiredNavigationAttributeConvention.cs | 2 +- .../RequiredPropertyAttributeConvention.cs | 2 +- .../StringLengthAttributeConvention.cs | 2 +- .../TimestampAttributeConvention.cs | 2 +- .../Conventions/TypeMappingConvention.cs | 2 +- .../Conventions/ValueGenerationConvention.cs | 6 +- ...pendencyInjectionMethodParameterBinding.cs | 5 +- src/EFCore/Metadata/IConventionEntityType.cs | 2 +- src/EFCore/Metadata/IMutableEntityType.cs | 2 +- .../Metadata/Internal/ClrAccessorFactory.cs | 5 +- .../Internal/ClrCollectionAccessor.cs | 4 + .../Internal/ClrCollectionAccessorFactory.cs | 5 +- .../Internal/ClrPropertyGetterFactory.cs | 12 +- .../Internal/ClrPropertySetterFactory.cs | 5 +- src/EFCore/Metadata/Internal/EntityType.cs | 88 ++---- .../Metadata/Internal/EntityTypeExtensions.cs | 3 +- .../Internal/EntityTypePathComparer.cs | 1 - src/EFCore/Metadata/Internal/ForeignKey.cs | 18 +- .../Metadata/Internal/IMemberClassifier.cs | 2 +- .../Internal/InternalEntityTypeBuilder.cs | 93 +++--- .../Metadata/Internal/InternalModelBuilder.cs | 3 +- .../Internal/InternalNavigationBuilder.cs | 2 +- .../InternalOwnedEntityTypeBuilder.cs | 2 +- .../Internal/InternalRelationshipBuilder.cs | 99 ++++--- src/EFCore/Metadata/Internal/Key.cs | 21 +- .../Metadata/Internal/MemberClassifier.cs | 2 +- src/EFCore/Metadata/Internal/Model.cs | 15 +- .../Metadata/Internal/PropertiesSnapshot.cs | 2 +- .../Internal/PropertyAccessorsFactory.cs | 5 +- .../Metadata/Internal/PropertyExtensions.cs | 10 +- .../Metadata/Internal/PropertyListComparer.cs | 2 +- .../Metadata/Internal/TypeBaseExtensions.cs | 3 - src/EFCore/Metadata/MemberIdentity.cs | 1 - .../Metadata/ServiceParameterBinding.cs | 5 +- src/EFCore/ModelBuilder.cs | 11 +- .../Query/CollectionShaperExpression.cs | 2 +- .../Query/CompiledQueryCacheKeyGenerator.cs | 4 +- ...piledQueryCacheKeyGeneratorDependencies.cs | 4 +- src/EFCore/Query/EntityMaterializerSource.cs | 5 +- src/EFCore/Query/EntityShaperExpression.cs | 2 +- .../Query/EvaluatableExpressionFilter.cs | 8 +- ...EvaluatableExpressionFilterDependencies.cs | 6 +- src/EFCore/Query/ExpressionPrinter.cs | 17 +- src/EFCore/Query/GroupByShaperExpression.cs | 2 +- .../Query/ICompiledQueryCacheKeyGenerator.cs | 4 +- .../Query/IEvaluatableExpressionFilter.cs | 8 +- src/EFCore/Query/IPrintableExpression.cs | 2 +- .../Query/IQueryCompilationContextFactory.cs | 4 +- src/EFCore/Query/IQueryContextFactory.cs | 4 +- .../IQueryTranslationPostprocessorFactory.cs | 10 +- .../IQueryTranslationPreprocessorFactory.cs | 10 +- ...thodTranslatingExpressionVisitorFactory.cs | 10 +- ...dQueryCompilingExpressionVisitorFactory.cs | 10 +- src/EFCore/Query/IncludeExpression.cs | 10 +- ...AnyToContainsRewritingExpressionVisitor.cs | 17 +- src/EFCore/Query/Internal/AnonymousObject.cs | 1 + .../Internal/AsyncQueryProviderExtensions.cs | 2 +- .../Query/Internal/CompiledQueryCache.cs | 6 +- ...ntityEqualityRewritingExpressionVisitor.cs | 171 ++++++----- .../Query/Internal/EntityQueryProvider.cs | 4 +- ...ryableMethodConvertingExpressionVisitor.cs | 11 +- .../FunctionPreprocessingExpressionVisitor.cs | 4 +- .../GroupJoinFlatteningExpressionVisitor.cs | 75 +++-- .../Query/Internal/IAsyncQueryProvider.cs | 4 +- .../Query/Internal/ICompiledQueryCache.cs | 6 +- src/EFCore/Query/Internal/IQueryCompiler.cs | 4 +- ...ingExpressionVisitor.ExpressionVisitors.cs | 115 ++++---- ...nExpandingExpressionVisitor.Expressions.cs | 28 +- .../NavigationExpandingExpressionVisitor.cs | 234 ++++++++------- .../NegationOptimizingExpressionVisitor.cs | 21 +- .../Query/Internal/NullAsyncQueryProvider.cs | 4 +- .../NullCheckRemovingExpressionVisitor.cs | 5 +- .../ParameterExtractingExpressionVisitor.cs | 5 +- .../QueryCompilationContextFactory.cs | 2 +- src/EFCore/Query/Internal/QueryCompiler.cs | 4 +- ...ueryMetadataExtractingExpressionVisitor.cs | 2 +- .../QueryTranslationPostprocessorFactory.cs | 2 +- .../QueryTranslationPreprocessorFactory.cs | 10 +- ...SubqueryMemberPushdownExpressionVisitor.cs | 54 ++-- ...terializeCollectionNavigationExpression.cs | 2 +- src/EFCore/Query/NullConditionalExpression.cs | 2 +- .../Query/ProjectionBindingExpression.cs | 8 +- src/EFCore/Query/ProjectionMember.cs | 2 +- src/EFCore/Query/QueryCompilationContext.cs | 24 +- .../QueryCompilationContextDependencies.cs | 3 +- src/EFCore/Query/QueryContext.cs | 3 +- src/EFCore/Query/QueryContextDependencies.cs | 4 +- .../Query/QueryTranslationPostprocessor.cs | 2 +- ...eryTranslationPostprocessorDependencies.cs | 6 +- .../Query/QueryTranslationPreprocessor.cs | 5 +- ...ueryTranslationPreprocessorDependencies.cs | 6 +- ...yableMethodTranslatingExpressionVisitor.cs | 270 +++++++++++------- ...ranslatingExpressionVisitorDependencies.cs | 6 +- src/EFCore/Query/QueryableMethods.cs | 88 ++++-- .../Query/ReplacingExpressionVisitor.cs | 2 +- src/EFCore/Query/ResultCardinality.cs | 1 + .../ShapedQueryCompilingExpressionVisitor.cs | 155 +++++----- .../Query/TransparentIdentifierFactory.cs | 2 +- src/EFCore/Storage/Database.cs | 4 +- src/EFCore/Storage/DatabaseDependencies.cs | 6 +- src/EFCore/Storage/DatabaseProvider.cs | 6 +- .../Storage/DatabaseProviderDependencies.cs | 6 +- src/EFCore/Storage/ExecutionStrategy.cs | 3 +- .../Storage/ExecutionStrategyDependencies.cs | 4 +- .../Storage/ExecutionStrategyExtensions.cs | 24 +- src/EFCore/Storage/IDatabase.cs | 4 +- src/EFCore/Storage/IDatabaseProvider.cs | 6 +- src/EFCore/Storage/IDbContextTransaction.cs | 4 +- .../Storage/IDbContextTransactionManager.cs | 4 +- .../Storage/IExecutionStrategyFactory.cs | 4 +- .../Storage/ITransactionEnlistmentManager.cs | 2 +- src/EFCore/Storage/ITypeMappingSource.cs | 8 +- .../Storage/ITypeMappingSourcePlugin.cs | 8 +- .../Internal/ExecutionStrategyFactory.cs | 4 +- src/EFCore/Storage/TypeMappingSource.cs | 8 +- src/EFCore/Storage/TypeMappingSourceBase.cs | 8 +- .../Storage/TypeMappingSourceDependencies.cs | 6 +- src/EFCore/Storage/ValueBuffer.cs | 1 + .../ValueConversion/CastingConverter.cs | 3 +- .../DateTimeOffsetToBytesConverter.cs | 3 +- .../DateTimeOffsetToStringConverter.cs | 3 +- ...faultValueConverterRegistryDependencies.cs | 6 +- .../ValueConversion/EnumToNumberConverter.cs | 3 +- .../IValueConverterSelector.cs | 6 +- .../Internal/StringCharConverter.cs | 2 +- .../Internal/StringDateTimeConverter.cs | 2 +- .../Internal/StringDateTimeOffsetConverter.cs | 2 +- .../Internal/StringEnumConverter.cs | 2 +- .../Internal/StringGuidConverter.cs | 2 +- .../Internal/StringNumberConverter.cs | 2 +- .../Internal/StringTimeSpanConverter.cs | 2 +- .../Internal/StringUriConverter.cs | 5 +- .../ValueConversion/NumberToBytesConverter.cs | 3 +- .../NumberToStringConverter.cs | 3 +- .../ValueConversion/StringToBoolConverter.cs | 2 +- .../ValueConversion/StringToCharConverter.cs | 2 +- .../StringToDateTimeConverter.cs | 2 +- .../StringToDateTimeOffsetConverter.cs | 5 +- .../ValueConversion/StringToEnumConverter.cs | 2 +- .../ValueConversion/StringToGuidConverter.cs | 2 +- .../StringToNumberConverter.cs | 5 +- .../StringToTimeSpanConverter.cs | 2 +- .../ValueConversion/StringToUriConverter.cs | 2 +- .../ValueConversion/ValueConverterSelector.cs | 36 ++- src/EFCore/Update/IUpdateAdapter.cs | 10 +- src/EFCore/Update/IUpdateAdapterFactory.cs | 2 +- src/EFCore/Update/UpdateEntryExtensions.cs | 2 +- .../ValueGeneration/IValueGeneratorCache.cs | 6 +- .../IValueGeneratorSelector.cs | 4 +- .../ValueGeneration/ValueGeneratorCache.cs | 6 +- .../ValueGeneratorCacheDependencies.cs | 6 +- .../ValueGeneration/ValueGeneratorSelector.cs | 4 +- .../ValueGeneratorSelectorDependencies.cs | 4 +- .../Extensions/SQLitePCLExtensions.cs | 4 +- src/Microsoft.Data.Sqlite.Core/SqliteBlob.cs | 3 +- .../SqliteCacheMode.cs | 2 +- .../SqliteCommand.cs | 3 +- .../SqliteConnection.CreateAggregate.cs | 1 + .../SqliteConnection.CreateAggregate.tt | 3 +- .../SqliteConnection.CreateFunction.cs | 1 + .../SqliteConnection.CreateFunction.tt | 3 +- .../SqliteConnection.cs | 24 +- .../SqliteDataReader.cs | 43 ++- .../SqliteDataRecord.cs | 25 +- .../SqliteException.cs | 4 +- .../SqliteFactory.cs | 2 +- .../SqliteOpenMode.cs | 2 +- .../SqliteParameter.cs | 1 - .../SqliteParameterBinder.cs | 3 +- .../SqliteParameterReader.cs | 3 +- .../SqliteResultBinder.cs | 3 +- .../SqliteTransaction.cs | 7 +- .../SqliteValueBinder.cs | 2 +- .../SqliteValueReader.cs | 3 +- .../Utilities/BundleInitializer.cs | 2 +- src/Shared/MemberInfoExtensions.cs | 3 +- src/dotnet-ef/Commands/ProjectCommandBase.cs | 2 +- src/dotnet-ef/Exe.cs | 8 +- src/dotnet-ef/Program.cs | 10 +- src/dotnet-ef/Project.cs | 9 +- src/dotnet-ef/ProjectOptions.cs | 51 +--- src/dotnet-ef/Properties/AssemblyInfo.cs | 2 +- src/dotnet-ef/RootCommand.cs | 32 +-- src/ef/AnsiConsole.cs | 2 +- src/ef/AnsiConstants.cs | 2 +- src/ef/AnsiTextWriter.cs | 2 +- src/ef/AppDomainOperationExecutor.cs | 3 +- src/ef/CommandException.cs | 2 +- .../CommandLineApplication.cs | 66 +++-- .../CommandLineApplicationExtensions.cs | 2 +- src/ef/CommandLineUtils/CommandOption.cs | 20 +- .../CommandParsingException.cs | 2 +- src/ef/Commands/CommandBase.cs | 16 +- src/ef/Commands/ContextCommandBase.cs | 2 +- src/ef/Commands/DatabaseCommand.cs | 2 +- .../Commands/DatabaseDropCommand.Configure.cs | 2 +- src/ef/Commands/DatabaseDropCommand.cs | 2 +- .../DatabaseUpdateCommand.Configure.cs | 2 +- src/ef/Commands/DatabaseUpdateCommand.cs | 2 +- src/ef/Commands/DbContextCommand.cs | 2 +- .../DbContextInfoCommand.Configure.cs | 2 +- src/ef/Commands/DbContextInfoCommand.cs | 2 +- .../DbContextListCommand.Configure.cs | 2 +- src/ef/Commands/DbContextListCommand.cs | 2 +- .../DbContextScaffoldCommand.Configure.cs | 2 +- src/ef/Commands/DbContextScaffoldCommand.cs | 3 +- .../DbContextScriptCommand.Configure.cs | 2 +- src/ef/Commands/DbContextScriptCommand.cs | 2 +- src/ef/Commands/EFCommandBase.cs | 2 +- src/ef/Commands/HelpCommandBase.cs | 2 +- .../MigrationsAddCommand.Configure.cs | 2 +- src/ef/Commands/MigrationsAddCommand.cs | 2 +- src/ef/Commands/MigrationsCommand.cs | 2 +- .../MigrationsListCommand.Configure.cs | 2 +- src/ef/Commands/MigrationsListCommand.cs | 2 +- .../MigrationsRemoveCommand.Configure.cs | 2 +- src/ef/Commands/MigrationsRemoveCommand.cs | 2 +- .../MigrationsScriptCommand.Configure.cs | 2 +- src/ef/Commands/MigrationsScriptCommand.cs | 2 +- src/ef/Commands/ProjectCommandBase.cs | 2 +- src/ef/Commands/RootCommand.cs | 2 +- src/ef/IOperationExecutor.cs | 2 +- src/ef/Json.cs | 2 +- src/ef/OperationExecutorBase.cs | 41 +-- src/ef/Program.cs | 7 +- src/ef/Properties/AssemblyInfo.cs | 2 +- src/ef/ReflectionOperationExecutor.cs | 4 +- src/ef/Reporter.cs | 2 +- src/ef/WrappedException.cs | 2 +- 984 files changed, 4882 insertions(+), 4730 deletions(-) diff --git a/All.sln.DotSettings b/All.sln.DotSettings index aec0e6f5183..d794c295092 100644 --- a/All.sln.DotSettings +++ b/All.sln.DotSettings @@ -72,7 +72,7 @@ False NEVER NEVER - False + True False True LINE_BREAK diff --git a/src/EFCore.Abstractions/DbFunctionAttribute.cs b/src/EFCore.Abstractions/DbFunctionAttribute.cs index 006df50089e..c5367469d64 100644 --- a/src/EFCore.Abstractions/DbFunctionAttribute.cs +++ b/src/EFCore.Abstractions/DbFunctionAttribute.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Abstractions/OwnedAttribute.cs b/src/EFCore.Abstractions/OwnedAttribute.cs index ba178be816f..a5e74e5b99b 100644 --- a/src/EFCore.Abstractions/OwnedAttribute.cs +++ b/src/EFCore.Abstractions/OwnedAttribute.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Analyzers/InternalUsageDiagnosticAnalyzer.cs b/src/EFCore.Analyzers/InternalUsageDiagnosticAnalyzer.cs index ca3cb147583..4cd7f9113cb 100644 --- a/src/EFCore.Analyzers/InternalUsageDiagnosticAnalyzer.cs +++ b/src/EFCore.Analyzers/InternalUsageDiagnosticAnalyzer.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -24,7 +24,7 @@ public const string MessageFormat protected const string DefaultTitle = "Internal EF Core API usage."; protected const string Category = "Usage"; - static readonly int EFLen = "EntityFrameworkCore".Length; + private static readonly int EFLen = "EntityFrameworkCore".Length; private static readonly DiagnosticDescriptor _descriptor = new DiagnosticDescriptor( @@ -40,7 +40,8 @@ private static readonly DiagnosticDescriptor _descriptor public override void Initialize(AnalysisContext context) { context.EnableConcurrentExecution(); - context.RegisterSyntaxNodeAction(AnalyzeNode, + context.RegisterSyntaxNodeAction( + AnalyzeNode, SyntaxKind.SimpleMemberAccessExpression, SyntaxKind.ObjectCreationExpression, SyntaxKind.ClassDeclaration); @@ -52,30 +53,33 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context) { case MemberAccessExpressionSyntax memberAccessSyntax: { - if (context.SemanticModel.GetSymbolInfo(context.Node, context.CancellationToken).Symbol is ISymbol symbol && - symbol.ContainingAssembly != context.Compilation.Assembly) + if (context.SemanticModel.GetSymbolInfo(context.Node, context.CancellationToken).Symbol is ISymbol symbol + && symbol.ContainingAssembly != context.Compilation.Assembly) { var containingType = symbol.ContainingType; if (HasInternalAttribute(symbol)) { - context.ReportDiagnostic(Diagnostic.Create(_descriptor, memberAccessSyntax.Name.GetLocation(), $"{containingType}.{symbol.Name}")); + context.ReportDiagnostic( + Diagnostic.Create(_descriptor, memberAccessSyntax.Name.GetLocation(), $"{containingType}.{symbol.Name}")); return; } - if (IsInInternalNamespace(containingType) || HasInternalAttribute(containingType)) + if (IsInInternalNamespace(containingType) + || HasInternalAttribute(containingType)) { context.ReportDiagnostic(Diagnostic.Create(_descriptor, memberAccessSyntax.Name.GetLocation(), containingType)); return; } } + return; } case ObjectCreationExpressionSyntax creationSyntax: { - if (context.SemanticModel.GetSymbolInfo(context.Node, context.CancellationToken).Symbol is ISymbol symbol && - symbol.ContainingAssembly != context.Compilation.Assembly) + if (context.SemanticModel.GetSymbolInfo(context.Node, context.CancellationToken).Symbol is ISymbol symbol + && symbol.ContainingAssembly != context.Compilation.Assembly) { var containingType = symbol.ContainingType; @@ -85,7 +89,8 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context) return; } - if (IsInInternalNamespace(containingType) || HasInternalAttribute(containingType)) + if (IsInInternalNamespace(containingType) + || HasInternalAttribute(containingType)) { context.ReportDiagnostic(Diagnostic.Create(_descriptor, creationSyntax.Type.GetLocation(), containingType)); return; @@ -97,10 +102,10 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context) case ClassDeclarationSyntax declarationSyntax: { - if (context.SemanticModel.GetDeclaredSymbol(declarationSyntax)?.BaseType is ISymbol symbol && - symbol.ContainingAssembly != context.Compilation.Assembly && - (IsInInternalNamespace(symbol) || HasInternalAttribute(symbol)) && - declarationSyntax.BaseList?.Types.Count > 0) + if (context.SemanticModel.GetDeclaredSymbol(declarationSyntax)?.BaseType is ISymbol symbol + && symbol.ContainingAssembly != context.Compilation.Assembly + && (IsInInternalNamespace(symbol) || HasInternalAttribute(symbol)) + && declarationSyntax.BaseList?.Types.Count > 0) { context.ReportDiagnostic(Diagnostic.Create(_descriptor, declarationSyntax.BaseList.Types[0].GetLocation(), symbol)); } diff --git a/src/EFCore.Cosmos/Extensions/CosmosDbContextOptionsExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosDbContextOptionsExtensions.cs index 30a90f42958..cec74d4b980 100644 --- a/src/EFCore.Cosmos/Extensions/CosmosDbContextOptionsExtensions.cs +++ b/src/EFCore.Cosmos/Extensions/CosmosDbContextOptionsExtensions.cs @@ -1,10 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using JetBrains.Annotations; -using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Cosmos.Infrastructure.Internal; +using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Utilities; // ReSharper disable once CheckNamespace diff --git a/src/EFCore.Cosmos/Extensions/CosmosEntityTypeBuilderExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosEntityTypeBuilderExtensions.cs index c14bc691b8b..b4cdd73b94a 100644 --- a/src/EFCore.Cosmos/Extensions/CosmosEntityTypeBuilderExtensions.cs +++ b/src/EFCore.Cosmos/Extensions/CosmosEntityTypeBuilderExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Cosmos/Extensions/CosmosEntityTypeExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosEntityTypeExtensions.cs index 9d614685b4d..2af9187b4b3 100644 --- a/src/EFCore.Cosmos/Extensions/CosmosEntityTypeExtensions.cs +++ b/src/EFCore.Cosmos/Extensions/CosmosEntityTypeExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; @@ -101,7 +101,8 @@ public static void SetCosmosContainingPropertyName( /// /// The entity type to find configuration source for. /// The for the parent property to which the entity type is mapped. - public static ConfigurationSource? GetCosmosContainingPropertyNameConfigurationSource([NotNull] this IConventionEntityType entityType) + public static ConfigurationSource? GetCosmosContainingPropertyNameConfigurationSource( + [NotNull] this IConventionEntityType entityType) => entityType.FindAnnotation(CosmosAnnotationNames.PropertyName) ?.GetConfigurationSource(); @@ -141,7 +142,8 @@ public static void SetCosmosPartitionKeyPropertyName( /// /// The entity type to find configuration source for. /// The for the partition key property. - public static ConfigurationSource? GetCosmosPartitionKeyPropertyNameConfigurationSource([NotNull] this IConventionEntityType entityType) + public static ConfigurationSource? GetCosmosPartitionKeyPropertyNameConfigurationSource( + [NotNull] this IConventionEntityType entityType) => entityType.FindAnnotation(CosmosAnnotationNames.PartitionKeyName) ?.GetConfigurationSource(); } diff --git a/src/EFCore.Cosmos/Extensions/CosmosModelBuilderExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosModelBuilderExtensions.cs index ddf3495ff42..f82df462269 100644 --- a/src/EFCore.Cosmos/Extensions/CosmosModelBuilderExtensions.cs +++ b/src/EFCore.Cosmos/Extensions/CosmosModelBuilderExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Cosmos/Extensions/CosmosModelExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosModelExtensions.cs index efc2652096d..c58b1ef5729 100644 --- a/src/EFCore.Cosmos/Extensions/CosmosModelExtensions.cs +++ b/src/EFCore.Cosmos/Extensions/CosmosModelExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; @@ -38,7 +38,8 @@ public static void SetCosmosDefaultContainer([NotNull] this IMutableModel model, /// The model. /// The name to set. /// Indicates whether the configuration was specified using a data annotation. - public static void SetCosmosDefaultContainer([NotNull] this IConventionModel model, [CanBeNull] string name, bool fromDataAnnotation = false) + public static void SetCosmosDefaultContainer( + [NotNull] this IConventionModel model, [CanBeNull] string name, bool fromDataAnnotation = false) => model.SetOrRemoveAnnotation( CosmosAnnotationNames.ContainerName, Check.NullButNotEmpty(name, nameof(name)), diff --git a/src/EFCore.Cosmos/Extensions/CosmosPropertyBuilderExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosPropertyBuilderExtensions.cs index 25cc6bd7f86..2e7deec6c51 100644 --- a/src/EFCore.Cosmos/Extensions/CosmosPropertyBuilderExtensions.cs +++ b/src/EFCore.Cosmos/Extensions/CosmosPropertyBuilderExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Cosmos/Extensions/CosmosPropertyExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosPropertyExtensions.cs index d09996dc4d5..c7fc852d8f1 100644 --- a/src/EFCore.Cosmos/Extensions/CosmosPropertyExtensions.cs +++ b/src/EFCore.Cosmos/Extensions/CosmosPropertyExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq; @@ -59,7 +59,8 @@ public static void SetCosmosPropertyName([NotNull] this IMutableProperty propert /// The property. /// The name to set. /// Indicates whether the configuration was specified using a data annotation. - public static void SetCosmosPropertyName([NotNull] this IConventionProperty property, [CanBeNull] string name, bool fromDataAnnotation = false) + public static void SetCosmosPropertyName( + [NotNull] this IConventionProperty property, [CanBeNull] string name, bool fromDataAnnotation = false) => property.SetOrRemoveAnnotation( CosmosAnnotationNames.PropertyName, name, diff --git a/src/EFCore.Cosmos/Extensions/CosmosServiceCollectionExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosServiceCollectionExtensions.cs index 1b84cc4827b..a24402ed220 100644 --- a/src/EFCore.Cosmos/Extensions/CosmosServiceCollectionExtensions.cs +++ b/src/EFCore.Cosmos/Extensions/CosmosServiceCollectionExtensions.cs @@ -35,7 +35,7 @@ public static class CosmosServiceCollectionExtensions /// Calling this method is no longer necessary when building most applications, including those that /// use dependency injection in ASP.NET or elsewhere. /// It is only needed when building the internal service provider for use with - /// the method. + /// the method. /// This is not recommend other than for some advanced scenarios. /// /// @@ -63,7 +63,6 @@ public static IServiceCollection AddEntityFrameworkCosmos([NotNull] this IServic // New Query pipeline .TryAdd() .TryAdd() - .TryAdd(p => p.GetService()) .TryAddProviderSpecificServices( b => b diff --git a/src/EFCore.Cosmos/Infrastructure/CosmosDbContextOptionsBuilder.cs b/src/EFCore.Cosmos/Infrastructure/CosmosDbContextOptionsBuilder.cs index ccd10b7ab93..9735378e3f8 100644 --- a/src/EFCore.Cosmos/Infrastructure/CosmosDbContextOptionsBuilder.cs +++ b/src/EFCore.Cosmos/Infrastructure/CosmosDbContextOptionsBuilder.cs @@ -45,14 +45,14 @@ public virtual CosmosDbContextOptionsBuilder ExecutionStrategy( => WithOption(e => e.WithExecutionStrategyFactory(Check.NotNull(getExecutionStrategy, nameof(getExecutionStrategy)))); /// - /// Configures the context to use the provided Region. + /// Configures the context to use the provided Region. /// /// CosmosDB region name public virtual CosmosDbContextOptionsBuilder Region([NotNull] string region) => WithOption(e => e.WithRegion(Check.NotNull(region, nameof(region)))); /// - /// Configures the context to use the provided connection mode. + /// Configures the context to use the provided connection mode. /// /// CosmosDB connection mode public virtual CosmosDbContextOptionsBuilder ConnectionMode(ConnectionMode connectionMode) diff --git a/src/EFCore.Cosmos/Infrastructure/Internal/CosmosDbOptionExtension.cs b/src/EFCore.Cosmos/Infrastructure/Internal/CosmosDbOptionExtension.cs index ca5de287f30..f8ccf733b12 100644 --- a/src/EFCore.Cosmos/Infrastructure/Internal/CosmosDbOptionExtension.cs +++ b/src/EFCore.Cosmos/Infrastructure/Internal/CosmosDbOptionExtension.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -262,9 +262,11 @@ public override void PopulateDebugInfo(IDictionary debugInfo) { Check.NotNull(debugInfo, nameof(debugInfo)); - debugInfo["Cosmos:" + nameof(AccountEndpoint)] = Extension._accountEndpoint.GetHashCode().ToString(CultureInfo.InvariantCulture); + debugInfo["Cosmos:" + nameof(AccountEndpoint)] = + Extension._accountEndpoint.GetHashCode().ToString(CultureInfo.InvariantCulture); debugInfo["Cosmos:" + nameof(AccountKey)] = Extension._accountKey.GetHashCode().ToString(CultureInfo.InvariantCulture); - debugInfo["Cosmos:" + nameof(CosmosDbContextOptionsBuilder.Region)] = (Extension._region?.GetHashCode() ?? 0).ToString(CultureInfo.InvariantCulture); + debugInfo["Cosmos:" + nameof(CosmosDbContextOptionsBuilder.Region)] = + (Extension._region?.GetHashCode() ?? 0).ToString(CultureInfo.InvariantCulture); } public override string LogFragment diff --git a/src/EFCore.Cosmos/Infrastructure/Internal/CosmosSingletonOptions.cs b/src/EFCore.Cosmos/Infrastructure/Internal/CosmosSingletonOptions.cs index 170f5177dd7..29abc72f144 100644 --- a/src/EFCore.Cosmos/Infrastructure/Internal/CosmosSingletonOptions.cs +++ b/src/EFCore.Cosmos/Infrastructure/Internal/CosmosSingletonOptions.cs @@ -17,9 +17,9 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.Infrastructure.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class CosmosSingletonOptions : ICosmosSingletonOptions @@ -56,7 +56,6 @@ public class CosmosSingletonOptions : ICosmosSingletonOptions /// public virtual ConnectionMode? ConnectionMode { get; private set; } - /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in diff --git a/src/EFCore.Cosmos/Infrastructure/Internal/ICosmosSingletonOptions.cs b/src/EFCore.Cosmos/Infrastructure/Internal/ICosmosSingletonOptions.cs index ffc257ce103..7f6b652e14f 100644 --- a/src/EFCore.Cosmos/Infrastructure/Internal/ICosmosSingletonOptions.cs +++ b/src/EFCore.Cosmos/Infrastructure/Internal/ICosmosSingletonOptions.cs @@ -15,10 +15,10 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.Infrastructure.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is and multiple registrations - /// are allowed. This means a single instance of each service is used by many + /// The service lifetime is and multiple registrations + /// are allowed. This means a single instance of each service is used by many /// instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public interface ICosmosSingletonOptions : ISingletonOptions diff --git a/src/EFCore.Cosmos/Internal/CosmosModelValidator.cs b/src/EFCore.Cosmos/Internal/CosmosModelValidator.cs index 11022b018dd..a1c2a77bab8 100644 --- a/src/EFCore.Cosmos/Internal/CosmosModelValidator.cs +++ b/src/EFCore.Cosmos/Internal/CosmosModelValidator.cs @@ -102,11 +102,12 @@ protected virtual void ValidateSharedContainerCompatibility( } var keyType = nextPartitionKeyProperty.GetTypeMapping().Converter?.ProviderClrType - ?? nextPartitionKeyProperty.ClrType; + ?? nextPartitionKeyProperty.ClrType; if (keyType != typeof(string)) { - throw new InvalidOperationException(CosmosStrings.PartitionKeyNonStringStoreType( - partitionKeyPropertyName, entityType.DisplayName(), keyType.ShortDisplayName())); + throw new InvalidOperationException( + CosmosStrings.PartitionKeyNonStringStoreType( + partitionKeyPropertyName, entityType.DisplayName(), keyType.ShortDisplayName())); } if (partitionKey == null) @@ -115,6 +116,7 @@ protected virtual void ValidateSharedContainerCompatibility( { throw new InvalidOperationException(CosmosStrings.NoPartitionKey(firstEntityType.DisplayName(), container)); } + partitionKey = nextPartitionKeyProperty; } else if (partitionKey.GetCosmosPropertyName() != nextPartitionKeyProperty.GetCosmosPropertyName()) diff --git a/src/EFCore.Cosmos/Metadata/Conventions/CosmosDiscriminatorConvention.cs b/src/EFCore.Cosmos/Metadata/Conventions/CosmosDiscriminatorConvention.cs index b1e0f6f8f1f..3629af2d2b7 100644 --- a/src/EFCore.Cosmos/Metadata/Conventions/CosmosDiscriminatorConvention.cs +++ b/src/EFCore.Cosmos/Metadata/Conventions/CosmosDiscriminatorConvention.cs @@ -54,7 +54,6 @@ private static bool Any([NotNull] IEnumerable source) return false; } - /// /// Called after the base type of an entity type changes. /// diff --git a/src/EFCore.Cosmos/Metadata/Conventions/StoreKeyConvention.cs b/src/EFCore.Cosmos/Metadata/Conventions/StoreKeyConvention.cs index 46a95560336..7125a467138 100644 --- a/src/EFCore.Cosmos/Metadata/Conventions/StoreKeyConvention.cs +++ b/src/EFCore.Cosmos/Metadata/Conventions/StoreKeyConvention.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Cosmos/Metadata/Internal/CosmosAnnotationNames.cs b/src/EFCore.Cosmos/Metadata/Internal/CosmosAnnotationNames.cs index 084da62d276..bb43cd56a15 100644 --- a/src/EFCore.Cosmos/Metadata/Internal/CosmosAnnotationNames.cs +++ b/src/EFCore.Cosmos/Metadata/Internal/CosmosAnnotationNames.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. namespace Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal diff --git a/src/EFCore.Cosmos/Metadata/Internal/CosmosEntityTypeExtensions.cs b/src/EFCore.Cosmos/Metadata/Internal/CosmosEntityTypeExtensions.cs index 03f5a1006c1..a3ad9541c52 100644 --- a/src/EFCore.Cosmos/Metadata/Internal/CosmosEntityTypeExtensions.cs +++ b/src/EFCore.Cosmos/Metadata/Internal/CosmosEntityTypeExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.Metadata; @@ -21,7 +21,7 @@ public static class CosmosEntityTypeExtensions /// public static bool IsDocumentRoot(this IEntityType entityType) => entityType.BaseType?.IsDocumentRoot() - ?? (!entityType.IsOwned() - || entityType[CosmosAnnotationNames.ContainerName] != null); + ?? (!entityType.IsOwned() + || entityType[CosmosAnnotationNames.ContainerName] != null); } } diff --git a/src/EFCore.Cosmos/Metadata/Internal/CosmosNavigationExtensions.cs b/src/EFCore.Cosmos/Metadata/Internal/CosmosNavigationExtensions.cs index 9fdb9fadd25..f3953e0a7c7 100644 --- a/src/EFCore.Cosmos/Metadata/Internal/CosmosNavigationExtensions.cs +++ b/src/EFCore.Cosmos/Metadata/Internal/CosmosNavigationExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.Metadata; diff --git a/src/EFCore.Cosmos/Query/Internal/ContainsTranslator.cs b/src/EFCore.Cosmos/Query/Internal/ContainsTranslator.cs index 287bef77ea0..6a5c0446d45 100644 --- a/src/EFCore.Cosmos/Query/Internal/ContainsTranslator.cs +++ b/src/EFCore.Cosmos/Query/Internal/ContainsTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections; diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosMemberTranslatorProvider.cs b/src/EFCore.Cosmos/Query/Internal/CosmosMemberTranslatorProvider.cs index d54221ef676..cb93951885f 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosMemberTranslatorProvider.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosMemberTranslatorProvider.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -25,7 +25,8 @@ public class CosmosMemberTranslatorProvider : IMemberTranslatorProvider /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public CosmosMemberTranslatorProvider(ISqlExpressionFactory sqlExpressionFactory, + public CosmosMemberTranslatorProvider( + ISqlExpressionFactory sqlExpressionFactory, IEnumerable plugins) { _plugins.AddRange(plugins.SelectMany(p => p.Translators)); diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosMethodCallTranslatorProvider.cs b/src/EFCore.Cosmos/Query/Internal/CosmosMethodCallTranslatorProvider.cs index 5f4dc4bd12b..cc8a8b526b2 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosMethodCallTranslatorProvider.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosMethodCallTranslatorProvider.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; @@ -32,10 +32,11 @@ public CosmosMethodCallTranslatorProvider( _plugins.AddRange(plugins.SelectMany(p => p.Translators)); _translators.AddRange( - new IMethodCallTranslator[] { + new IMethodCallTranslator[] + { new EqualsTranslator(sqlExpressionFactory), //new StringMethodTranslator(sqlExpressionFactory), - new ContainsTranslator(sqlExpressionFactory), + new ContainsTranslator(sqlExpressionFactory) //new LikeTranslator(sqlExpressionFactory), //new EnumHasFlagTranslator(sqlExpressionFactory), //new GetValueOrDefaultTranslator(sqlExpressionFactory), @@ -49,7 +50,8 @@ public CosmosMethodCallTranslatorProvider( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual SqlExpression Translate(IModel model, SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + IModel model, SqlExpression instance, MethodInfo method, IReadOnlyList arguments) { // TODO: UDF support. See issue#15338 //var dbFunction = model.FindDbFunction(method); diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosProjectionBindingExpressionVisitor.cs b/src/EFCore.Cosmos/Query/Internal/CosmosProjectionBindingExpressionVisitor.cs index f539c5f4c04..eb6168dda6a 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosProjectionBindingExpressionVisitor.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosProjectionBindingExpressionVisitor.cs @@ -1,9 +1,8 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq.Expressions; using System.Reflection; using Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal; @@ -26,8 +25,10 @@ public class CosmosProjectionBindingExpressionVisitor : ExpressionVisitor private readonly CosmosSqlTranslatingExpressionVisitor _sqlTranslator; private SelectExpression _selectExpression; private bool _clientEval; + private readonly IDictionary _projectionMapping = new Dictionary(); + private readonly Stack _projectionMembers = new Stack(); /// @@ -181,6 +182,7 @@ protected override Expression VisitMember(MemberExpression memberExpression) { return memberExpression.Update(innerExpression); } + break; default: @@ -264,6 +266,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp { return null; } + break; default: @@ -420,6 +423,7 @@ protected override Expression VisitNew(NewExpression newExpression) { return null; } + _projectionMembers.Pop(); } } diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosQueryContext.cs b/src/EFCore.Cosmos/Query/Internal/CosmosQueryContext.cs index 43526bedcff..40fedab447a 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosQueryContext.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosQueryContext.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosQueryContextFactory.cs b/src/EFCore.Cosmos/Query/Internal/CosmosQueryContextFactory.cs index a5b044641b8..ecfcb472076 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosQueryContextFactory.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosQueryContextFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs index b877e3f1875..6743e7e3c2f 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -101,12 +101,12 @@ protected override ShapedQueryExpression CreateShapedQueryExpression(Type elemen return new ShapedQueryExpression( selectExpression, new EntityShaperExpression( - entityType, - new ProjectionBindingExpression( - selectExpression, - new ProjectionMember(), - typeof(ValueBuffer)), - false)); + entityType, + new ProjectionBindingExpression( + selectExpression, + new ProjectionMember(), + typeof(ValueBuffer)), + false)); } /// @@ -185,8 +185,9 @@ protected override ShapedQueryExpression TranslateCast(ShapedQueryExpression sou /// protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression source1, ShapedQueryExpression source2) { - throw new InvalidOperationException(CoreStrings.TranslationFailed( - source1.Print() + "; " + source2.Print())); + throw new InvalidOperationException( + CoreStrings.TranslationFailed( + source1.Print() + "; " + source2.Print())); } /// @@ -224,10 +225,7 @@ protected override ShapedQueryExpression TranslateCount(ShapedQueryExpression so var translation = _sqlExpressionFactory.ApplyDefaultTypeMapping( _sqlExpressionFactory.Function("COUNT", new[] { _sqlExpressionFactory.Constant(1) }, typeof(int))); - var projectionMapping = new Dictionary - { - { new ProjectionMember(), translation } - }; + var projectionMapping = new Dictionary { { new ProjectionMember(), translation } }; selectExpression.ClearOrdering(); selectExpression.ReplaceProjectionMapping(projectionMapping); @@ -266,7 +264,8 @@ protected override ShapedQueryExpression TranslateDistinct(ShapedQueryExpression /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected override ShapedQueryExpression TranslateElementAtOrDefault(ShapedQueryExpression source, Expression index, bool returnDefault) + protected override ShapedQueryExpression TranslateElementAtOrDefault( + ShapedQueryExpression source, Expression index, bool returnDefault) { throw new InvalidOperationException(CoreStrings.TranslationFailed(index.Print())); } @@ -279,8 +278,9 @@ protected override ShapedQueryExpression TranslateElementAtOrDefault(ShapedQuery /// protected override ShapedQueryExpression TranslateExcept(ShapedQueryExpression source1, ShapedQueryExpression source2) { - throw new InvalidOperationException(CoreStrings.TranslationFailed( - source1.Print() + "; " + source2.Print())); + throw new InvalidOperationException( + CoreStrings.TranslationFailed( + source1.Print() + "; " + source2.Print())); } /// @@ -289,7 +289,8 @@ protected override ShapedQueryExpression TranslateExcept(ShapedQueryExpression s /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected override ShapedQueryExpression TranslateFirstOrDefault(ShapedQueryExpression source, LambdaExpression predicate, Type returnType, bool returnDefault) + protected override ShapedQueryExpression TranslateFirstOrDefault( + ShapedQueryExpression source, LambdaExpression predicate, Type returnType, bool returnDefault) { if (predicate != null) { @@ -313,10 +314,12 @@ protected override ShapedQueryExpression TranslateFirstOrDefault(ShapedQueryExpr /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected override ShapedQueryExpression TranslateGroupBy(ShapedQueryExpression source, LambdaExpression keySelector, LambdaExpression elementSelector, LambdaExpression resultSelector) + protected override ShapedQueryExpression TranslateGroupBy( + ShapedQueryExpression source, LambdaExpression keySelector, LambdaExpression elementSelector, LambdaExpression resultSelector) { - throw new InvalidOperationException(CoreStrings.TranslationFailed( - keySelector.Print() + "; " + elementSelector.Print() + "; " + resultSelector.Print())); + throw new InvalidOperationException( + CoreStrings.TranslationFailed( + keySelector.Print() + "; " + elementSelector.Print() + "; " + resultSelector.Print())); } /// @@ -325,7 +328,9 @@ protected override ShapedQueryExpression TranslateGroupBy(ShapedQueryExpression /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected override ShapedQueryExpression TranslateGroupJoin(ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, LambdaExpression resultSelector) + protected override ShapedQueryExpression TranslateGroupJoin( + ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, + LambdaExpression resultSelector) { return null; } @@ -338,8 +343,9 @@ protected override ShapedQueryExpression TranslateGroupJoin(ShapedQueryExpressio /// protected override ShapedQueryExpression TranslateIntersect(ShapedQueryExpression source1, ShapedQueryExpression source2) { - throw new InvalidOperationException(CoreStrings.TranslationFailed( - source1.Print() + "; " + source2.Print())); + throw new InvalidOperationException( + CoreStrings.TranslationFailed( + source1.Print() + "; " + source2.Print())); } /// @@ -348,10 +354,13 @@ protected override ShapedQueryExpression TranslateIntersect(ShapedQueryExpressio /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected override ShapedQueryExpression TranslateJoin(ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, LambdaExpression resultSelector) + protected override ShapedQueryExpression TranslateJoin( + ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, + LambdaExpression resultSelector) { - throw new InvalidOperationException(CoreStrings.TranslationFailed( - outerKeySelector.Print() + "; " + innerKeySelector.Print() + "; " + resultSelector.Print())); + throw new InvalidOperationException( + CoreStrings.TranslationFailed( + outerKeySelector.Print() + "; " + innerKeySelector.Print() + "; " + resultSelector.Print())); } /// @@ -360,7 +369,8 @@ protected override ShapedQueryExpression TranslateJoin(ShapedQueryExpression out /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected override ShapedQueryExpression TranslateLastOrDefault(ShapedQueryExpression source, LambdaExpression predicate, Type returnType, bool returnDefault) + protected override ShapedQueryExpression TranslateLastOrDefault( + ShapedQueryExpression source, LambdaExpression predicate, Type returnType, bool returnDefault) { if (predicate != null) { @@ -385,10 +395,13 @@ protected override ShapedQueryExpression TranslateLastOrDefault(ShapedQueryExpre /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected override ShapedQueryExpression TranslateLeftJoin(ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, LambdaExpression resultSelector) + protected override ShapedQueryExpression TranslateLeftJoin( + ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, + LambdaExpression resultSelector) { - throw new InvalidOperationException(CoreStrings.TranslationFailed( - outerKeySelector.Print() + "; " + innerKeySelector.Print() + "; " + resultSelector.Print())); + throw new InvalidOperationException( + CoreStrings.TranslationFailed( + outerKeySelector.Print() + "; " + innerKeySelector.Print() + "; " + resultSelector.Print())); } /// @@ -414,10 +427,7 @@ protected override ShapedQueryExpression TranslateLongCount(ShapedQueryExpressio var translation = _sqlExpressionFactory.ApplyDefaultTypeMapping( _sqlExpressionFactory.Function("COUNT", new[] { _sqlExpressionFactory.Constant(1) }, typeof(long))); - var projectionMapping = new Dictionary - { - { new ProjectionMember(), translation } - }; + var projectionMapping = new Dictionary { { new ProjectionMember(), translation } }; selectExpression.ClearOrdering(); selectExpression.ReplaceProjectionMapping(projectionMapping); @@ -499,7 +509,8 @@ protected override ShapedQueryExpression TranslateOfType(ShapedQueryExpression s /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected override ShapedQueryExpression TranslateOrderBy(ShapedQueryExpression source, LambdaExpression keySelector, bool ascending) + protected override ShapedQueryExpression TranslateOrderBy( + ShapedQueryExpression source, LambdaExpression keySelector, bool ascending) { var translation = TranslateLambdaExpression(source, keySelector); if (translation != null) @@ -556,10 +567,12 @@ protected override ShapedQueryExpression TranslateSelect(ShapedQueryExpression s /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected override ShapedQueryExpression TranslateSelectMany(ShapedQueryExpression source, LambdaExpression collectionSelector, LambdaExpression resultSelector) + protected override ShapedQueryExpression TranslateSelectMany( + ShapedQueryExpression source, LambdaExpression collectionSelector, LambdaExpression resultSelector) { - throw new InvalidOperationException(CoreStrings.TranslationFailed( - collectionSelector.Print() + "; " + resultSelector.Print())); + throw new InvalidOperationException( + CoreStrings.TranslationFailed( + collectionSelector.Print() + "; " + resultSelector.Print())); } /// @@ -579,7 +592,8 @@ protected override ShapedQueryExpression TranslateSelectMany(ShapedQueryExpressi /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected override ShapedQueryExpression TranslateSingleOrDefault(ShapedQueryExpression source, LambdaExpression predicate, Type returnType, bool returnDefault) + protected override ShapedQueryExpression TranslateSingleOrDefault( + ShapedQueryExpression source, LambdaExpression predicate, Type returnType, bool returnDefault) { if (predicate != null) { @@ -718,8 +732,9 @@ protected override ShapedQueryExpression TranslateThenBy(ShapedQueryExpression s /// protected override ShapedQueryExpression TranslateUnion(ShapedQueryExpression source1, ShapedQueryExpression source2) { - throw new InvalidOperationException(CoreStrings.TranslationFailed( - source1.Print() + "; " + source2.Print())); + throw new InvalidOperationException( + CoreStrings.TranslationFailed( + source1.Print() + "; " + source2.Print())); } /// @@ -762,10 +777,7 @@ private ShapedQueryExpression AggregateResultShaper( { var selectExpression = (SelectExpression)source.QueryExpression; selectExpression.ReplaceProjectionMapping( - new Dictionary - { - { new ProjectionMember(), projection } - }); + new Dictionary { { new ProjectionMember(), projection } }); selectExpression.ClearOrdering(); diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitorFactory.cs b/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitorFactory.cs index 8681a731a85..393ef1c2bdc 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitorFactory.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitorFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.AsyncQueryingEnumerable.cs b/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.AsyncQueryingEnumerable.cs index 2207f49c9b1..76c31f90bac 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.AsyncQueryingEnumerable.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.AsyncQueryingEnumerable.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -81,14 +81,14 @@ public async ValueTask MoveNextAsync() if (_enumerator == null) { var selectExpression = (SelectExpression)new InExpressionValuesExpandingExpressionVisitor( - _sqlExpressionFactory, _cosmosQueryContext.ParameterValues).Visit(_selectExpression); + _sqlExpressionFactory, _cosmosQueryContext.ParameterValues).Visit(_selectExpression); _enumerator = _cosmosQueryContext.CosmosClient .ExecuteSqlQueryAsync( _selectExpression.Container, - _querySqlGeneratorFactory.Create().GetSqlQuery(selectExpression, _cosmosQueryContext.ParameterValues)) + _querySqlGeneratorFactory.Create().GetSqlQuery( + selectExpression, _cosmosQueryContext.ParameterValues)) .GetAsyncEnumerator(_cancellationToken); - } var hasNext = await _enumerator.MoveNextAsync(); diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.CosmosProjectionBindingRemovingExpressionVisitor.cs b/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.CosmosProjectionBindingRemovingExpressionVisitor.cs index 21a925fbfae..dd0e26c1b99 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.CosmosProjectionBindingRemovingExpressionVisitor.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.CosmosProjectionBindingRemovingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -26,25 +26,32 @@ private class CosmosProjectionBindingRemovingExpressionVisitor : ExpressionVisit private static readonly MethodInfo _selectMethodInfo = typeof(Enumerable).GetTypeInfo().GetDeclaredMethods(nameof(Enumerable.Select)) .Single(mi => mi.GetParameters().Length == 2 && mi.GetParameters()[1].ParameterType.GetGenericArguments().Length == 3); + private static readonly MethodInfo _castMethodInfo = typeof(Enumerable).GetTypeInfo().GetDeclaredMethods(nameof(Enumerable.Cast)) .Single(mi => mi.GetParameters().Length == 1); + private static readonly MethodInfo _getItemMethodInfo = typeof(JObject).GetTypeInfo().GetRuntimeProperties() .Single(pi => pi.Name == "Item" && pi.GetIndexParameters()[0].ParameterType == typeof(string)) .GetMethod; + private static readonly PropertyInfo _jTokenTypePropertyInfo = typeof(JToken).GetTypeInfo().GetRuntimeProperties() .Single(mi => mi.Name == nameof(JToken.Type)); + private static readonly MethodInfo _jTokenToObjectMethodInfo = typeof(JToken).GetTypeInfo().GetRuntimeMethods() .Single(mi => mi.Name == nameof(JToken.ToObject) && mi.GetParameters().Length == 0); + private static readonly MethodInfo _toObjectMethodInfo = typeof(CosmosProjectionBindingRemovingExpressionVisitor).GetTypeInfo().GetRuntimeMethods() .Single(mi => mi.Name == nameof(SafeToObject)); + private static readonly MethodInfo _collectionAccessorAddMethodInfo = typeof(IClrCollectionAccessor).GetTypeInfo() .GetDeclaredMethod(nameof(IClrCollectionAccessor.Add)); + private static readonly MethodInfo _collectionAccessorGetOrCreateMethodInfo = typeof(IClrCollectionAccessor).GetTypeInfo() .GetDeclaredMethod(nameof(IClrCollectionAccessor.GetOrCreate)); @@ -55,10 +62,13 @@ private static readonly MethodInfo _collectionAccessorGetOrCreateMethodInfo private readonly IDictionary _materializationContextBindings = new Dictionary(); + private readonly IDictionary _projectionBindings = new Dictionary(); + private readonly IDictionary _ownerMappings = new Dictionary(); + private (IEntityType EntityType, ParameterExpression JObjectVariable) _ownerInfo; private ParameterExpression _ordinalParameter; @@ -88,7 +98,8 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression) var projection = GetProjection(projectionBindingExpression); projectionExpression = projection.Expression; storeName = projection.Alias; - } else if (projectionExpression is UnaryExpression convertExpression) + } + else if (projectionExpression is UnaryExpression convertExpression) { projectionExpression = ((UnaryExpression)convertExpression.Operand).Operand; } @@ -120,7 +131,8 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression) innerAccessExpression = _jObjectParameter; break; default: - throw new InvalidOperationException(CoreStrings.QueryFailed(binaryExpression.Print(), GetType().Name)); + throw new InvalidOperationException( + CoreStrings.QueryFailed(binaryExpression.Print(), GetType().Name)); } } @@ -147,7 +159,8 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression) _materializationContextBindings[parameterExpression] = entityProjectionExpression.AccessExpression; - var updatedExpression = Expression.New(newExpression.Constructor, + var updatedExpression = Expression.New( + newExpression.Constructor, Expression.Constant(ValueBuffer.Empty), newExpression.Arguments[1]); @@ -234,7 +247,8 @@ protected override Expression VisitExtension(Expression extensionExpression) } else { - _ownerMappings[objectArrayProjection.InnerProjection.AccessExpression] = (objectArrayProjection.Navigation.DeclaringEntityType, objectArrayProjection.AccessExpression); + _ownerMappings[objectArrayProjection.InnerProjection.AccessExpression] = ( + objectArrayProjection.Navigation.DeclaringEntityType, objectArrayProjection.AccessExpression); } var previousOrdinalParameter = _ordinalParameter; @@ -452,7 +466,6 @@ private static Delegate GenerateFixup( inverseNavigation.IsCollection() ? AddToCollectionNavigation(relatedEntityParameter, entityParameter, inverseNavigation) : AssignReferenceNavigation(relatedEntityParameter, entityParameter, inverseNavigation)); - } return Expression.Lambda(Expression.Block(typeof(void), expressions), entityParameter, relatedEntityParameter) @@ -470,7 +483,7 @@ private static Delegate GenerateInitialize( var entityParameter = Expression.Parameter(entityType); - var getOrCreateExpression = Expression.Call( + var getOrCreateExpression = Expression.Call( Expression.Constant(navigation.GetCollectionAccessor()), _collectionAccessorGetOrCreateMethodInfo, entityParameter, @@ -641,12 +654,13 @@ var body } body = Expression.Condition( - Expression.OrElse( - Expression.Equal(jTokenParameter, Expression.Default(typeof(JToken))), - Expression.Equal(Expression.MakeMemberAccess(jTokenParameter, _jTokenTypePropertyInfo), - Expression.Constant(JTokenType.Null))), - Expression.Default(clrType), - body); + Expression.OrElse( + Expression.Equal(jTokenParameter, Expression.Default(typeof(JToken))), + Expression.Equal( + Expression.MakeMemberAccess(jTokenParameter, _jTokenTypePropertyInfo), + Expression.Constant(JTokenType.Null))), + Expression.Default(clrType), + body); valueExpression = Expression.Invoke(Expression.Lambda(body, jTokenParameter), jTokenExpression); } diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.InExpressionValuesExpandingExpressionVisitor.cs b/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.InExpressionValuesExpandingExpressionVisitor.cs index 4ad6ef970db..2ccf613b589 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.InExpressionValuesExpandingExpressionVisitor.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.InExpressionValuesExpandingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections; @@ -47,7 +47,7 @@ public override Expression Visit(Expression expression) inValues.Add(value); } } - break; + break; case SqlParameterExpression sqlParameter: { @@ -64,8 +64,8 @@ public override Expression Visit(Expression expression) inValues.Add(value); } } - break; - } + break; + } var updatedInExpression = inValues.Count > 0 ? _sqlExpressionFactory.In( @@ -78,12 +78,14 @@ public override Expression Visit(Expression expression) ? _sqlExpressionFactory.IsNull(inExpression.Item) : null; - if (updatedInExpression != null && nullCheckExpression != null) + if (updatedInExpression != null + && nullCheckExpression != null) { return _sqlExpressionFactory.OrElse(updatedInExpression, nullCheckExpression); } - if (updatedInExpression == null && nullCheckExpression == null) + if (updatedInExpression == null + && nullCheckExpression == null) { return _sqlExpressionFactory.Equal(_sqlExpressionFactory.Constant(true), _sqlExpressionFactory.Constant(false)); } diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.JObjectInjectingExpressionVisitor.cs b/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.JObjectInjectingExpressionVisitor.cs index 48a776a4936..2b04f84d4ae 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.JObjectInjectingExpressionVisitor.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.JObjectInjectingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; @@ -27,10 +27,7 @@ protected override Expression VisitExtension(Expression extensionExpression) var jObjectVariable = Expression.Variable( typeof(JObject), "jObject" + _currentEntityIndex); - var variables = new List - { - jObjectVariable - }; + var variables = new List { jObjectVariable }; var expressions = new List { @@ -58,10 +55,7 @@ protected override Expression VisitExtension(Expression extensionExpression) var jArrayVariable = Expression.Variable( typeof(JArray), "jArray" + _currentEntityIndex); - var variables = new List - { - jArrayVariable - }; + var variables = new List { jArrayVariable }; var expressions = new List { @@ -70,7 +64,6 @@ protected override Expression VisitExtension(Expression extensionExpression) Expression.TypeAs( collectionShaperExpression.Projection, typeof(JArray))), - Expression.Condition( Expression.Equal(jArrayVariable, Expression.Constant(null, jArrayVariable.Type)), Expression.Constant(null, collectionShaperExpression.Type), @@ -81,7 +74,7 @@ protected override Expression VisitExtension(Expression extensionExpression) collectionShaperExpression.Type, variables, expressions); - } + } } return base.VisitExtension(extensionExpression); diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.QueryingEnumerable.cs b/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.QueryingEnumerable.cs index 6b41c2ef011..ad6ed53eeae 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.QueryingEnumerable.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.QueryingEnumerable.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.cs b/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.cs index 4b6e4658050..8621afd196d 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.cs @@ -1,8 +1,7 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections; using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitorFactory.cs b/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitorFactory.cs index 163e8a8faaf..e65e5ad1ef0 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitorFactory.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitorFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.Query; diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosSqlTranslatingExpressionVisitor.cs b/src/EFCore.Cosmos/Query/Internal/CosmosSqlTranslatingExpressionVisitor.cs index 3a91054a6f3..7f401390790 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosSqlTranslatingExpressionVisitor.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosSqlTranslatingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -118,6 +118,7 @@ private bool TryBindMember(Expression source, MemberIdentity member, out Express { convertedType = unaryExpression.Type; } + source = unaryExpression.Operand; } @@ -199,6 +200,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp { return null; } + arguments[i] = (SqlExpression)argument; } @@ -244,10 +246,11 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression) { if (binaryExpression.NodeType == ExpressionType.Coalesce) { - return Visit(Expression.Condition( - Expression.NotEqual(binaryExpression.Left, Expression.Constant(null, binaryExpression.Left.Type)), - binaryExpression.Left, - binaryExpression.Right)); + return Visit( + Expression.Condition( + Expression.NotEqual(binaryExpression.Left, Expression.Constant(null, binaryExpression.Left.Type)), + binaryExpression.Left, + binaryExpression.Right)); } var left = TryRemoveImplicitConvert(binaryExpression.Left); @@ -315,7 +318,6 @@ protected override Expression VisitUnary(UnaryExpression unaryExpression) switch (unaryExpression.NodeType) { - case ExpressionType.Not: return _sqlExpressionFactory.Not(sqlOperand); @@ -325,7 +327,7 @@ protected override Expression VisitUnary(UnaryExpression unaryExpression) case ExpressionType.Convert: // Object convert needs to be converted to explicit cast when mismatching types if (operand.Type.IsInterface - && unaryExpression.Type.GetInterfaces().Any(e => e == operand.Type) + && unaryExpression.Type.GetInterfaces().Any(e => e == operand.Type) || unaryExpression.Type.UnwrapNullableType() == operand.Type || unaryExpression.Type.UnwrapNullableType() == typeof(Enum)) { @@ -370,8 +372,8 @@ private static bool CanEvaluate(Expression expression) case MemberInitExpression memberInitExpression: return CanEvaluate(memberInitExpression.NewExpression) - && memberInitExpression.Bindings.All( - mb => mb is MemberAssignment memberAssignment && CanEvaluate(memberAssignment.Expression)); + && memberInitExpression.Bindings.All( + mb => mb is MemberAssignment memberAssignment && CanEvaluate(memberAssignment.Expression)); default: return false; diff --git a/src/EFCore.Cosmos/Query/Internal/EntityProjectionExpression.cs b/src/EFCore.Cosmos/Query/Internal/EntityProjectionExpression.cs index e2eadd5b7a6..c753b50a386 100644 --- a/src/EFCore.Cosmos/Query/Internal/EntityProjectionExpression.cs +++ b/src/EFCore.Cosmos/Query/Internal/EntityProjectionExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -21,6 +21,7 @@ public class EntityProjectionExpression : Expression, IPrintableExpression, IAcc { private readonly IDictionary _propertyExpressionsCache = new Dictionary(); + private readonly IDictionary _navigationExpressionsCache = new Dictionary(); diff --git a/src/EFCore.Cosmos/Query/Internal/EqualsTranslator.cs b/src/EFCore.Cosmos/Query/Internal/EqualsTranslator.cs index e0792a15f9e..f24be32ee59 100644 --- a/src/EFCore.Cosmos/Query/Internal/EqualsTranslator.cs +++ b/src/EFCore.Cosmos/Query/Internal/EqualsTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -48,13 +48,14 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method right = RemoveObjectConvert(arguments[0]); } else if (method.Name == nameof(object.Equals) - && arguments.Count == 2) + && arguments.Count == 2) { left = RemoveObjectConvert(arguments[0]); right = RemoveObjectConvert(arguments[1]); } - if (left != null && right != null) + if (left != null + && right != null) { return left.Type.UnwrapNullableType() == right.Type.UnwrapNullableType() ? (SqlExpression)_sqlExpressionFactory.Equal(left, right) diff --git a/src/EFCore.Cosmos/Query/Internal/ExpressionExtensions.cs b/src/EFCore.Cosmos/Query/Internal/ExpressionExtensions.cs index daf1899a62b..3ab2e4d20d2 100644 --- a/src/EFCore.Cosmos/Query/Internal/ExpressionExtensions.cs +++ b/src/EFCore.Cosmos/Query/Internal/ExpressionExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq.Expressions; diff --git a/src/EFCore.Cosmos/Query/Internal/IAccessExpression.cs b/src/EFCore.Cosmos/Query/Internal/IAccessExpression.cs index 2dcaa66d607..ec52fc7c1a6 100644 --- a/src/EFCore.Cosmos/Query/Internal/IAccessExpression.cs +++ b/src/EFCore.Cosmos/Query/Internal/IAccessExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal diff --git a/src/EFCore.Cosmos/Query/Internal/IMemberTranslator.cs b/src/EFCore.Cosmos/Query/Internal/IMemberTranslator.cs index b3de8dbe96f..92754ca5b75 100644 --- a/src/EFCore.Cosmos/Query/Internal/IMemberTranslator.cs +++ b/src/EFCore.Cosmos/Query/Internal/IMemberTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Cosmos/Query/Internal/IMemberTranslatorPlugin.cs b/src/EFCore.Cosmos/Query/Internal/IMemberTranslatorPlugin.cs index f9e1e7ca48c..92c92730b48 100644 --- a/src/EFCore.Cosmos/Query/Internal/IMemberTranslatorPlugin.cs +++ b/src/EFCore.Cosmos/Query/Internal/IMemberTranslatorPlugin.cs @@ -1,8 +1,7 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; -using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal { diff --git a/src/EFCore.Cosmos/Query/Internal/IMemberTranslatorProvider.cs b/src/EFCore.Cosmos/Query/Internal/IMemberTranslatorProvider.cs index 3b922c54185..3a4444fe9ec 100644 --- a/src/EFCore.Cosmos/Query/Internal/IMemberTranslatorProvider.cs +++ b/src/EFCore.Cosmos/Query/Internal/IMemberTranslatorProvider.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Cosmos/Query/Internal/IMethodCallTranslator.cs b/src/EFCore.Cosmos/Query/Internal/IMethodCallTranslator.cs index 52b3d82700f..ba0e1e9223d 100644 --- a/src/EFCore.Cosmos/Query/Internal/IMethodCallTranslator.cs +++ b/src/EFCore.Cosmos/Query/Internal/IMethodCallTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; diff --git a/src/EFCore.Cosmos/Query/Internal/IMethodCallTranslatorPlugin.cs b/src/EFCore.Cosmos/Query/Internal/IMethodCallTranslatorPlugin.cs index 224f4bcc344..0a1c2e2753c 100644 --- a/src/EFCore.Cosmos/Query/Internal/IMethodCallTranslatorPlugin.cs +++ b/src/EFCore.Cosmos/Query/Internal/IMethodCallTranslatorPlugin.cs @@ -1,8 +1,7 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; -using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal { diff --git a/src/EFCore.Cosmos/Query/Internal/IMethodCallTranslatorProvider.cs b/src/EFCore.Cosmos/Query/Internal/IMethodCallTranslatorProvider.cs index 588dcd2a7b1..4f7a88abf6e 100644 --- a/src/EFCore.Cosmos/Query/Internal/IMethodCallTranslatorProvider.cs +++ b/src/EFCore.Cosmos/Query/Internal/IMethodCallTranslatorProvider.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; diff --git a/src/EFCore.Cosmos/Query/Internal/IQuerySqlGeneratorFactory.cs b/src/EFCore.Cosmos/Query/Internal/IQuerySqlGeneratorFactory.cs index 35815651ae6..419a323fce3 100644 --- a/src/EFCore.Cosmos/Query/Internal/IQuerySqlGeneratorFactory.cs +++ b/src/EFCore.Cosmos/Query/Internal/IQuerySqlGeneratorFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal diff --git a/src/EFCore.Cosmos/Query/Internal/ISqlExpressionFactory.cs b/src/EFCore.Cosmos/Query/Internal/ISqlExpressionFactory.cs index 729c99aeb49..4d937fb6344 100644 --- a/src/EFCore.Cosmos/Query/Internal/ISqlExpressionFactory.cs +++ b/src/EFCore.Cosmos/Query/Internal/ISqlExpressionFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Cosmos/Query/Internal/InExpression.cs b/src/EFCore.Cosmos/Query/Internal/InExpression.cs index 82dba8745cd..e58a23497e8 100644 --- a/src/EFCore.Cosmos/Query/Internal/InExpression.cs +++ b/src/EFCore.Cosmos/Query/Internal/InExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -23,7 +23,7 @@ public class InExpression : SqlExpression /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public InExpression(SqlExpression item, bool negated, SqlExpression values, CoreTypeMapping typeMapping) - : base(typeof(bool), typeMapping) + : base(typeof(bool), typeMapping) { Item = item; IsNegated = negated; @@ -110,15 +110,15 @@ public override void Print(ExpressionPrinter expressionPrinter) /// public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is InExpression inExpression - && Equals(inExpression)); + && (ReferenceEquals(this, obj) + || obj is InExpression inExpression + && Equals(inExpression)); private bool Equals(InExpression inExpression) => base.Equals(inExpression) - && Item.Equals(inExpression.Item) - && IsNegated.Equals(inExpression.IsNegated) - && (Values == null ? inExpression.Values == null : Values.Equals(inExpression.Values)); + && Item.Equals(inExpression.Item) + && IsNegated.Equals(inExpression.IsNegated) + && (Values == null ? inExpression.Values == null : Values.Equals(inExpression.Values)); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.Cosmos/Query/Internal/KeyAccessExpression.cs b/src/EFCore.Cosmos/Query/Internal/KeyAccessExpression.cs index aa8a334bf27..3bdf5e7a474 100644 --- a/src/EFCore.Cosmos/Query/Internal/KeyAccessExpression.cs +++ b/src/EFCore.Cosmos/Query/Internal/KeyAccessExpression.cs @@ -44,7 +44,9 @@ public KeyAccessExpression(IProperty property, Expression accessExpression) /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// +#pragma warning disable 109 public new virtual IProperty Property { get; } +#pragma warning restore 109 /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -103,14 +105,14 @@ public override void Print(ExpressionPrinter expressionPrinter) /// public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is KeyAccessExpression keyAccessExpression - && Equals(keyAccessExpression)); + && (ReferenceEquals(this, obj) + || obj is KeyAccessExpression keyAccessExpression + && Equals(keyAccessExpression)); private bool Equals(KeyAccessExpression keyAccessExpression) => base.Equals(keyAccessExpression) - && string.Equals(Name, keyAccessExpression.Name) - && AccessExpression.Equals(keyAccessExpression.AccessExpression); + && string.Equals(Name, keyAccessExpression.Name) + && AccessExpression.Equals(keyAccessExpression.AccessExpression); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.Cosmos/Query/Internal/ObjectAccessExpression.cs b/src/EFCore.Cosmos/Query/Internal/ObjectAccessExpression.cs index 6545f77af3c..1b5c6156589 100644 --- a/src/EFCore.Cosmos/Query/Internal/ObjectAccessExpression.cs +++ b/src/EFCore.Cosmos/Query/Internal/ObjectAccessExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -123,9 +123,9 @@ public virtual ObjectAccessExpression Update(Expression outerExpression) /// public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is ObjectAccessExpression objectAccessExpression - && Equals(objectAccessExpression)); + && (ReferenceEquals(this, obj) + || obj is ObjectAccessExpression objectAccessExpression + && Equals(objectAccessExpression)); private bool Equals(ObjectAccessExpression objectAccessExpression) => Navigation == objectAccessExpression.Navigation diff --git a/src/EFCore.Cosmos/Query/Internal/ObjectArrayProjectionExpression.cs b/src/EFCore.Cosmos/Query/Internal/ObjectArrayProjectionExpression.cs index ee818e1db11..f376df1865d 100644 --- a/src/EFCore.Cosmos/Query/Internal/ObjectArrayProjectionExpression.cs +++ b/src/EFCore.Cosmos/Query/Internal/ObjectArrayProjectionExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Cosmos/Query/Internal/OrderingExpression.cs b/src/EFCore.Cosmos/Query/Internal/OrderingExpression.cs index ed447caa6a1..a2d3309beab 100644 --- a/src/EFCore.Cosmos/Query/Internal/OrderingExpression.cs +++ b/src/EFCore.Cosmos/Query/Internal/OrderingExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -100,13 +100,13 @@ public virtual void Print(ExpressionPrinter expressionPrinter) /// public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is OrderingExpression orderingExpression - && Equals(orderingExpression)); + && (ReferenceEquals(this, obj) + || obj is OrderingExpression orderingExpression + && Equals(orderingExpression)); private bool Equals(OrderingExpression orderingExpression) => Expression.Equals(orderingExpression.Expression) - && IsAscending == orderingExpression.IsAscending; + && IsAscending == orderingExpression.IsAscending; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.Cosmos/Query/Internal/ProjectionExpression.cs b/src/EFCore.Cosmos/Query/Internal/ProjectionExpression.cs index e408558ccd0..9a8ac1a6883 100644 --- a/src/EFCore.Cosmos/Query/Internal/ProjectionExpression.cs +++ b/src/EFCore.Cosmos/Query/Internal/ProjectionExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -112,13 +112,13 @@ public virtual void Print(ExpressionPrinter expressionPrinter) /// public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is ProjectionExpression projectionExpression - && Equals(projectionExpression)); + && (ReferenceEquals(this, obj) + || obj is ProjectionExpression projectionExpression + && Equals(projectionExpression)); private bool Equals(ProjectionExpression projectionExpression) => string.Equals(Alias, projectionExpression.Alias) - && Expression.Equals(projectionExpression.Expression); + && Expression.Equals(projectionExpression.Expression); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.Cosmos/Query/Internal/QuerySqlGenerator.cs b/src/EFCore.Cosmos/Query/Internal/QuerySqlGenerator.cs index 0837ccc860d..f8fae428d19 100644 --- a/src/EFCore.Cosmos/Query/Internal/QuerySqlGenerator.cs +++ b/src/EFCore.Cosmos/Query/Internal/QuerySqlGenerator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -6,7 +6,6 @@ using System.Linq; using System.Linq.Expressions; using System.Text; -using Microsoft.EntityFrameworkCore.Cosmos.Storage; using Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -189,6 +188,7 @@ protected override Expression VisitSelect(SelectExpression selectExpression) { _sqlBuilder.Append("1"); } + _sqlBuilder.AppendLine(); _sqlBuilder.Append("FROM root "); @@ -306,7 +306,6 @@ protected override Expression VisitSqlUnary(SqlUnaryExpression sqlUnaryExpressio return sqlUnaryExpression; } - private void GenerateList( IReadOnlyList items, Action generationAction, diff --git a/src/EFCore.Cosmos/Query/Internal/QuerySqlGeneratorFactory.cs b/src/EFCore.Cosmos/Query/Internal/QuerySqlGeneratorFactory.cs index 43aa16907ed..7d89de2e6c4 100644 --- a/src/EFCore.Cosmos/Query/Internal/QuerySqlGeneratorFactory.cs +++ b/src/EFCore.Cosmos/Query/Internal/QuerySqlGeneratorFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal diff --git a/src/EFCore.Cosmos/Query/Internal/RootReferenceExpression.cs b/src/EFCore.Cosmos/Query/Internal/RootReferenceExpression.cs index cf1f1f36d10..b90b9cc96dd 100644 --- a/src/EFCore.Cosmos/Query/Internal/RootReferenceExpression.cs +++ b/src/EFCore.Cosmos/Query/Internal/RootReferenceExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Cosmos/Query/Internal/SelectExpression.cs b/src/EFCore.Cosmos/Query/Internal/SelectExpression.cs index da95aa09769..62e078c654a 100644 --- a/src/EFCore.Cosmos/Query/Internal/SelectExpression.cs +++ b/src/EFCore.Cosmos/Query/Internal/SelectExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -141,7 +141,8 @@ public virtual void ApplyProjection() var result = new Dictionary(); foreach (var keyValuePair in _projectionMapping) { - result[keyValuePair.Key] = Constant(AddToProjection( + result[keyValuePair.Key] = Constant( + AddToProjection( keyValuePair.Value, keyValuePair.Key.Last?.Name)); } @@ -186,7 +187,8 @@ public virtual void ReplaceProjectionMapping(IDictionary - public virtual int AddToProjection(ObjectArrayProjectionExpression objectArrayProjection) => AddToProjection(objectArrayProjection, null); + public virtual int AddToProjection(ObjectArrayProjectionExpression objectArrayProjection) => + AddToProjection(objectArrayProjection, null); private int AddToProjection(Expression expression, string alias) { @@ -197,8 +199,8 @@ private int AddToProjection(Expression expression, string alias) } var baseAlias = alias - ?? (expression as IAccessExpression)?.Name - ?? "c"; + ?? (expression as IAccessExpression)?.Name + ?? "c"; var currentAlias = baseAlias; var counter = 0; diff --git a/src/EFCore.Cosmos/Query/Internal/SqlBinaryExpression.cs b/src/EFCore.Cosmos/Query/Internal/SqlBinaryExpression.cs index bf8d52f8a45..004140a572e 100644 --- a/src/EFCore.Cosmos/Query/Internal/SqlBinaryExpression.cs +++ b/src/EFCore.Cosmos/Query/Internal/SqlBinaryExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -38,7 +38,7 @@ public class SqlBinaryExpression : SqlExpression ExpressionType.ExclusiveOr, ExpressionType.Coalesce, ExpressionType.RightShift, - ExpressionType.LeftShift, + ExpressionType.LeftShift }; private static ExpressionType VerifyOperator(ExpressionType operatorType) @@ -160,7 +160,7 @@ public override void Print(ExpressionPrinter expressionPrinter) private bool RequiresBrackets(SqlExpression expression) { return expression is SqlBinaryExpression sqlBinary - && sqlBinary.OperatorType != ExpressionType.Coalesce; + && sqlBinary.OperatorType != ExpressionType.Coalesce; } /// @@ -171,15 +171,15 @@ private bool RequiresBrackets(SqlExpression expression) /// public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is SqlBinaryExpression sqlBinaryExpression - && Equals(sqlBinaryExpression)); + && (ReferenceEquals(this, obj) + || obj is SqlBinaryExpression sqlBinaryExpression + && Equals(sqlBinaryExpression)); private bool Equals(SqlBinaryExpression sqlBinaryExpression) => base.Equals(sqlBinaryExpression) - && OperatorType == sqlBinaryExpression.OperatorType - && Left.Equals(sqlBinaryExpression.Left) - && Right.Equals(sqlBinaryExpression.Right); + && OperatorType == sqlBinaryExpression.OperatorType + && Left.Equals(sqlBinaryExpression.Left) + && Right.Equals(sqlBinaryExpression.Right); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.Cosmos/Query/Internal/SqlConditionalExpression.cs b/src/EFCore.Cosmos/Query/Internal/SqlConditionalExpression.cs index b946500c228..ef02c31722e 100644 --- a/src/EFCore.Cosmos/Query/Internal/SqlConditionalExpression.cs +++ b/src/EFCore.Cosmos/Query/Internal/SqlConditionalExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -110,15 +110,15 @@ public override void Print(ExpressionPrinter expressionPrinter) /// public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is SqlConditionalExpression sqlConditionalExpression - && Equals(sqlConditionalExpression)); + && (ReferenceEquals(this, obj) + || obj is SqlConditionalExpression sqlConditionalExpression + && Equals(sqlConditionalExpression)); private bool Equals(SqlConditionalExpression sqlConditionalExpression) => base.Equals(sqlConditionalExpression) - && Test.Equals(sqlConditionalExpression.Test) - && IfTrue.Equals(sqlConditionalExpression.IfTrue) - && IfFalse.Equals(sqlConditionalExpression.IfFalse); + && Test.Equals(sqlConditionalExpression.Test) + && IfTrue.Equals(sqlConditionalExpression.IfTrue) + && IfFalse.Equals(sqlConditionalExpression.IfFalse); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.Cosmos/Query/Internal/SqlConstantExpression.cs b/src/EFCore.Cosmos/Query/Internal/SqlConstantExpression.cs index 9f768b218ba..b8159d212ae 100644 --- a/src/EFCore.Cosmos/Query/Internal/SqlConstantExpression.cs +++ b/src/EFCore.Cosmos/Query/Internal/SqlConstantExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -99,7 +99,7 @@ private JToken GenerateJToken(object value, CoreTypeMapping typeMapping) { var mappingClrType = typeMapping.ClrType.UnwrapNullableType(); if (value?.GetType().IsInteger() == true - && mappingClrType.IsEnum) + && mappingClrType.IsEnum) { value = Enum.ToObject(mappingClrType, value); } @@ -126,15 +126,15 @@ private JToken GenerateJToken(object value, CoreTypeMapping typeMapping) /// public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is SqlConstantExpression sqlConstantExpression - && Equals(sqlConstantExpression)); + && (ReferenceEquals(this, obj) + || obj is SqlConstantExpression sqlConstantExpression + && Equals(sqlConstantExpression)); private bool Equals(SqlConstantExpression sqlConstantExpression) => base.Equals(sqlConstantExpression) - && (Value == null - ? sqlConstantExpression.Value == null - : Value.Equals(sqlConstantExpression.Value)); + && (Value == null + ? sqlConstantExpression.Value == null + : Value.Equals(sqlConstantExpression.Value)); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.Cosmos/Query/Internal/SqlExpression.cs b/src/EFCore.Cosmos/Query/Internal/SqlExpression.cs index 1eb8823517d..4051ab4743f 100644 --- a/src/EFCore.Cosmos/Query/Internal/SqlExpression.cs +++ b/src/EFCore.Cosmos/Query/Internal/SqlExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -77,13 +77,13 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) /// public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is SqlExpression sqlExpression - && Equals(sqlExpression)); + && (ReferenceEquals(this, obj) + || obj is SqlExpression sqlExpression + && Equals(sqlExpression)); private bool Equals(SqlExpression sqlExpression) => Type == sqlExpression.Type - && TypeMapping?.Equals(sqlExpression.TypeMapping) == true; + && TypeMapping?.Equals(sqlExpression.TypeMapping) == true; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.Cosmos/Query/Internal/SqlExpressionFactory.cs b/src/EFCore.Cosmos/Query/Internal/SqlExpressionFactory.cs index d43f38de95d..a7d0eb86eed 100644 --- a/src/EFCore.Cosmos/Query/Internal/SqlExpressionFactory.cs +++ b/src/EFCore.Cosmos/Query/Internal/SqlExpressionFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -6,8 +6,8 @@ using System.Linq; using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Diagnostics; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Storage; @@ -152,11 +152,11 @@ private SqlExpression ApplyTypeMappingOnSqlBinary( case ExpressionType.NotEqual: { inferredTypeMapping = ExpressionExtensions.InferTypeMapping(left, right) - ?? _typeMappingSource.FindMapping(left.Type); + ?? _typeMappingSource.FindMapping(left.Type); resultType = typeof(bool); resultTypeMapping = _boolTypeMapping; } - break; + break; case ExpressionType.AndAlso: case ExpressionType.OrElse: @@ -165,7 +165,7 @@ private SqlExpression ApplyTypeMappingOnSqlBinary( resultType = typeof(bool); resultTypeMapping = _boolTypeMapping; } - break; + break; case ExpressionType.Add: case ExpressionType.Subtract: @@ -182,7 +182,7 @@ private SqlExpression ApplyTypeMappingOnSqlBinary( resultType = left.Type; resultTypeMapping = inferredTypeMapping; } - break; + break; default: throw new InvalidOperationException("Incorrect operatorType for SqlBinaryExpression"); @@ -528,7 +528,9 @@ private void AddDiscriminator(SelectExpression selectExpression, IEntityType ent .BindProperty(concreteEntityTypes[0].GetDiscriminatorProperty(), clientEval: false); selectExpression.ApplyPredicate( - In((SqlExpression)discriminatorColumn, Constant(concreteEntityTypes.Select(et => et.GetDiscriminatorValue()).ToList()), negated: false)); + In( + (SqlExpression)discriminatorColumn, Constant(concreteEntityTypes.Select(et => et.GetDiscriminatorValue()).ToList()), + negated: false)); } } } diff --git a/src/EFCore.Cosmos/Query/Internal/SqlExpressionVisitor.cs b/src/EFCore.Cosmos/Query/Internal/SqlExpressionVisitor.cs index b2ff94c1962..308e6ebabad 100644 --- a/src/EFCore.Cosmos/Query/Internal/SqlExpressionVisitor.cs +++ b/src/EFCore.Cosmos/Query/Internal/SqlExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq.Expressions; diff --git a/src/EFCore.Cosmos/Query/Internal/SqlFunctionExpression.cs b/src/EFCore.Cosmos/Query/Internal/SqlFunctionExpression.cs index ed04c720e9e..22b6c648eb7 100644 --- a/src/EFCore.Cosmos/Query/Internal/SqlFunctionExpression.cs +++ b/src/EFCore.Cosmos/Query/Internal/SqlFunctionExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -116,14 +116,14 @@ public override void Print(ExpressionPrinter expressionPrinter) /// public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is SqlFunctionExpression sqlFunctionExpression - && Equals(sqlFunctionExpression)); + && (ReferenceEquals(this, obj) + || obj is SqlFunctionExpression sqlFunctionExpression + && Equals(sqlFunctionExpression)); private bool Equals(SqlFunctionExpression sqlFunctionExpression) => base.Equals(sqlFunctionExpression) - && string.Equals(Name, sqlFunctionExpression.Name) - && Arguments.SequenceEqual(sqlFunctionExpression.Arguments); + && string.Equals(Name, sqlFunctionExpression.Name) + && Arguments.SequenceEqual(sqlFunctionExpression.Arguments); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -140,6 +140,7 @@ public override int GetHashCode() { hash.Add(Arguments[i]); } + return hash.ToHashCode(); } } diff --git a/src/EFCore.Cosmos/Query/Internal/SqlParameterExpression.cs b/src/EFCore.Cosmos/Query/Internal/SqlParameterExpression.cs index 8ba6ea84d9f..65b8c8b5817 100644 --- a/src/EFCore.Cosmos/Query/Internal/SqlParameterExpression.cs +++ b/src/EFCore.Cosmos/Query/Internal/SqlParameterExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -66,13 +66,13 @@ public override void Print(ExpressionPrinter expressionPrinter) /// public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is SqlParameterExpression sqlParameterExpression - && Equals(sqlParameterExpression)); + && (ReferenceEquals(this, obj) + || obj is SqlParameterExpression sqlParameterExpression + && Equals(sqlParameterExpression)); private bool Equals(SqlParameterExpression sqlParameterExpression) => base.Equals(sqlParameterExpression) - && string.Equals(Name, sqlParameterExpression.Name); + && string.Equals(Name, sqlParameterExpression.Name); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.Cosmos/Query/Internal/SqlUnaryExpression.cs b/src/EFCore.Cosmos/Query/Internal/SqlUnaryExpression.cs index 11f686fc42e..2dd41136502 100644 --- a/src/EFCore.Cosmos/Query/Internal/SqlUnaryExpression.cs +++ b/src/EFCore.Cosmos/Query/Internal/SqlUnaryExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -20,9 +20,7 @@ public class SqlUnaryExpression : SqlExpression { private static readonly ISet _allowedOperators = new HashSet { - ExpressionType.Not, - ExpressionType.Negate, - ExpressionType.UnaryPlus, + ExpressionType.Not, ExpressionType.Negate, ExpressionType.UnaryPlus }; private static ExpressionType VerifyOperator(ExpressionType operatorType) @@ -86,7 +84,6 @@ public virtual SqlUnaryExpression Update(SqlExpression operand) /// public override void Print(ExpressionPrinter expressionPrinter) { - expressionPrinter.Append(OperatorType); expressionPrinter.Append("("); expressionPrinter.Visit(Operand); @@ -101,14 +98,14 @@ public override void Print(ExpressionPrinter expressionPrinter) /// public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is SqlUnaryExpression sqlUnaryExpression - && Equals(sqlUnaryExpression)); + && (ReferenceEquals(this, obj) + || obj is SqlUnaryExpression sqlUnaryExpression + && Equals(sqlUnaryExpression)); private bool Equals(SqlUnaryExpression sqlUnaryExpression) => base.Equals(sqlUnaryExpression) - && OperatorType == sqlUnaryExpression.OperatorType - && Operand.Equals(sqlUnaryExpression.Operand); + && OperatorType == sqlUnaryExpression.OperatorType + && Operand.Equals(sqlUnaryExpression.Operand); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.Cosmos/Storage/Internal/ByteArrayConverter.cs b/src/EFCore.Cosmos/Storage/Internal/ByteArrayConverter.cs index fb165083976..d3ed481f8dd 100644 --- a/src/EFCore.Cosmos/Storage/Internal/ByteArrayConverter.cs +++ b/src/EFCore.Cosmos/Storage/Internal/ByteArrayConverter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Cosmos/Storage/Internal/CosmosClientWrapper.cs b/src/EFCore.Cosmos/Storage/Internal/CosmosClientWrapper.cs index 1d79474c392..a5c646cc5bd 100644 --- a/src/EFCore.Cosmos/Storage/Internal/CosmosClientWrapper.cs +++ b/src/EFCore.Cosmos/Storage/Internal/CosmosClientWrapper.cs @@ -32,8 +32,8 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -222,10 +222,10 @@ private async Task CreateContainerIfNotExistsOnceAsync( CancellationToken cancellationToken = default) { var response = await Client.GetDatabase(_databaseId).CreateContainerIfNotExistsAsync( - new ContainerProperties(parameters.ContainerId, "/" + parameters.PartitionKey) - { - PartitionKeyDefinitionVersion = PartitionKeyDefinitionVersion.V2 - }, cancellationToken: cancellationToken) + new ContainerProperties(parameters.ContainerId, "/" + parameters.PartitionKey) + { + PartitionKeyDefinitionVersion = PartitionKeyDefinitionVersion.V2 + }, cancellationToken: cancellationToken) .ConfigureAwait(false); return response.StatusCode == HttpStatusCode.Created; @@ -333,7 +333,7 @@ private async Task ReplaceItemOnceAsync( var container = Client.GetDatabase(_databaseId).GetContainer(parameters.ContainerId); var partitionKey = CreatePartitionKey(parameters.PartitionKey); using (var response = await container.ReplaceItemStreamAsync( - stream, parameters.ItemId, partitionKey, null, cancellationToken)) + stream, parameters.ItemId, partitionKey, null, cancellationToken)) { return response.StatusCode == HttpStatusCode.OK; } @@ -391,7 +391,8 @@ public virtual async Task DeleteItemOnceAsync( { var items = Client.GetDatabase(_databaseId).GetContainer(parameters.ContainerId); var partitionKey = CreatePartitionKey(parameters.PartitionKey); - using (var response = await items.DeleteItemStreamAsync(parameters.DocumentId, partitionKey, cancellationToken: cancellationToken)) + using (var response = await items.DeleteItemStreamAsync( + parameters.DocumentId, partitionKey, cancellationToken: cancellationToken)) { return response.StatusCode == HttpStatusCode.NoContent; } @@ -399,8 +400,8 @@ public virtual async Task DeleteItemOnceAsync( private PartitionKey CreatePartitionKey(string partitionKey) => partitionKey == null - ? PartitionKey.None - : new PartitionKey(partitionKey); + ? PartitionKey.None + : new PartitionKey(partitionKey); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -521,8 +522,7 @@ public bool MoveNext() } } - ObjectFound: - ; + ObjectFound: ; } while (_jsonReader.Read()) @@ -600,7 +600,6 @@ public AsyncEnumerator(DocumentAsyncEnumerable documentEnumerable, CancellationT public JObject Current { get; private set; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public async ValueTask MoveNextAsync() { @@ -638,8 +637,7 @@ public async ValueTask MoveNextAsync() } } - ObjectFound: - ; + ObjectFound: ; } while (_jsonReader.Read()) diff --git a/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseCreator.cs b/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseCreator.cs index 357ac4fc105..e862542eeaf 100644 --- a/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseCreator.cs +++ b/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseCreator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseWrapper.cs b/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseWrapper.cs index a250aa5aed8..ae6e3627a5d 100644 --- a/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseWrapper.cs +++ b/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseWrapper.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -27,8 +27,8 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -260,9 +260,11 @@ private Task SaveAsync(IUpdateEntry entry, CancellationToken cancellationT } return _cosmosClient.ReplaceItemAsync( - collectionId, documentSource.GetId(entry.SharedIdentityEntry ?? entry), document, GetPartitionKey(entry), cancellationToken); + collectionId, documentSource.GetId(entry.SharedIdentityEntry ?? entry), document, GetPartitionKey(entry), + cancellationToken); case EntityState.Deleted: - return _cosmosClient.DeleteItemAsync(collectionId, documentSource.GetId(entry), GetPartitionKey(entry), cancellationToken); + return _cosmosClient.DeleteItemAsync( + collectionId, documentSource.GetId(entry), GetPartitionKey(entry), cancellationToken); default: return Task.FromResult(false); } diff --git a/src/EFCore.Cosmos/Storage/Internal/CosmosExecutionStrategy.cs b/src/EFCore.Cosmos/Storage/Internal/CosmosExecutionStrategy.cs index 1d2ee4d9c27..6c2400ec568 100644 --- a/src/EFCore.Cosmos/Storage/Internal/CosmosExecutionStrategy.cs +++ b/src/EFCore.Cosmos/Storage/Internal/CosmosExecutionStrategy.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Cosmos/Storage/Internal/CosmosExecutionStrategyFactory.cs b/src/EFCore.Cosmos/Storage/Internal/CosmosExecutionStrategyFactory.cs index 55e93f599b0..1447372a48a 100644 --- a/src/EFCore.Cosmos/Storage/Internal/CosmosExecutionStrategyFactory.cs +++ b/src/EFCore.Cosmos/Storage/Internal/CosmosExecutionStrategyFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -18,8 +18,8 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Cosmos/Storage/Internal/CosmosSqlQuery.cs b/src/EFCore.Cosmos/Storage/Internal/CosmosSqlQuery.cs index d609b7b35bf..fb610db60a9 100644 --- a/src/EFCore.Cosmos/Storage/Internal/CosmosSqlQuery.cs +++ b/src/EFCore.Cosmos/Storage/Internal/CosmosSqlQuery.cs @@ -1,8 +1,7 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; -using Microsoft.EntityFrameworkCore.Storage; namespace Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal { diff --git a/src/EFCore.Cosmos/Storage/Internal/CosmosTransactionManager.cs b/src/EFCore.Cosmos/Storage/Internal/CosmosTransactionManager.cs index aef46426aad..20c74304184 100644 --- a/src/EFCore.Cosmos/Storage/Internal/CosmosTransactionManager.cs +++ b/src/EFCore.Cosmos/Storage/Internal/CosmosTransactionManager.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Cosmos/Storage/Internal/CosmosTypeMapping.cs b/src/EFCore.Cosmos/Storage/Internal/CosmosTypeMapping.cs index 603905b0442..67ffe8e0a98 100644 --- a/src/EFCore.Cosmos/Storage/Internal/CosmosTypeMapping.cs +++ b/src/EFCore.Cosmos/Storage/Internal/CosmosTypeMapping.cs @@ -34,8 +34,7 @@ public CosmosTypeMapping( converter: null, comparer, keyComparer, - structuralComparer, - valueGeneratorFactory: null)) + structuralComparer)) { } diff --git a/src/EFCore.Cosmos/Storage/Internal/HttpException.cs b/src/EFCore.Cosmos/Storage/Internal/HttpException.cs index c14515e99c0..cf412b96d15 100644 --- a/src/EFCore.Cosmos/Storage/Internal/HttpException.cs +++ b/src/EFCore.Cosmos/Storage/Internal/HttpException.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Cosmos/Storage/Internal/SingletonCosmosClientWrapper.cs b/src/EFCore.Cosmos/Storage/Internal/SingletonCosmosClientWrapper.cs index 4d1dd40bb64..67d0fa5a558 100644 --- a/src/EFCore.Cosmos/Storage/Internal/SingletonCosmosClientWrapper.cs +++ b/src/EFCore.Cosmos/Storage/Internal/SingletonCosmosClientWrapper.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -44,8 +44,7 @@ public SingletonCosmosClientWrapper([NotNull] ICosmosSingletonOptions options) _key = options.AccountKey; var configuration = new CosmosClientOptions { - ApplicationName = _userAgent, - ConnectionMode = options.ConnectionMode ?? ConnectionMode.Direct + ApplicationName = _userAgent, ConnectionMode = options.ConnectionMode ?? ConnectionMode.Direct }; if (options.Region != null) diff --git a/src/EFCore.Cosmos/Storage/Internal/SqlParameter.cs b/src/EFCore.Cosmos/Storage/Internal/SqlParameter.cs index a50d8af892f..fcaf8573f84 100644 --- a/src/EFCore.Cosmos/Storage/Internal/SqlParameter.cs +++ b/src/EFCore.Cosmos/Storage/Internal/SqlParameter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. namespace Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal diff --git a/src/EFCore.Cosmos/ValueGeneration/Internal/IdValueGenerator.cs b/src/EFCore.Cosmos/ValueGeneration/Internal/IdValueGenerator.cs index b0c3d7cc17d..5d584049520 100644 --- a/src/EFCore.Cosmos/ValueGeneration/Internal/IdValueGenerator.cs +++ b/src/EFCore.Cosmos/ValueGeneration/Internal/IdValueGenerator.cs @@ -76,6 +76,7 @@ private void AppendString(StringBuilder builder, object propertyValue) builder.Append(item.ToString().Replace("|", "/|")); builder.Append("|"); } + return; default: builder.Append(propertyValue.ToString().Replace("|", "/|")); diff --git a/src/EFCore.Design/Design/DbContextActivator.cs b/src/EFCore.Design/Design/DbContextActivator.cs index 39c19dcbf7f..e41a7f54439 100644 --- a/src/EFCore.Design/Design/DbContextActivator.cs +++ b/src/EFCore.Design/Design/DbContextActivator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Design/Design/DesignTimeServiceCollectionExtensions.cs b/src/EFCore.Design/Design/DesignTimeServiceCollectionExtensions.cs index d780ce4b8b6..e5cd06cdedd 100644 --- a/src/EFCore.Design/Design/DesignTimeServiceCollectionExtensions.cs +++ b/src/EFCore.Design/Design/DesignTimeServiceCollectionExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Design/Design/ICSharpHelper.cs b/src/EFCore.Design/Design/ICSharpHelper.cs index 3cd31c0ec49..fd6d323cac2 100644 --- a/src/EFCore.Design/Design/ICSharpHelper.cs +++ b/src/EFCore.Design/Design/ICSharpHelper.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Design/Design/ILanguageBasedService.cs b/src/EFCore.Design/Design/ILanguageBasedService.cs index 109b4483b1b..8a83475ff74 100644 --- a/src/EFCore.Design/Design/ILanguageBasedService.cs +++ b/src/EFCore.Design/Design/ILanguageBasedService.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. namespace Microsoft.EntityFrameworkCore.Design diff --git a/src/EFCore.Design/Design/IOperationReportHandler.cs b/src/EFCore.Design/Design/IOperationReportHandler.cs index d21634d828f..664db71f0c0 100644 --- a/src/EFCore.Design/Design/IOperationReportHandler.cs +++ b/src/EFCore.Design/Design/IOperationReportHandler.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Design/Design/IOperationResultHandler.cs b/src/EFCore.Design/Design/IOperationResultHandler.cs index eb290728312..5e14819e4d5 100644 --- a/src/EFCore.Design/Design/IOperationResultHandler.cs +++ b/src/EFCore.Design/Design/IOperationResultHandler.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Design/Design/IPluralizer.cs b/src/EFCore.Design/Design/IPluralizer.cs index 7eb8e965e49..6790f85f718 100644 --- a/src/EFCore.Design/Design/IPluralizer.cs +++ b/src/EFCore.Design/Design/IPluralizer.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Design/Design/Internal/AppServiceProviderFactory.cs b/src/EFCore.Design/Design/Internal/AppServiceProviderFactory.cs index 1835972d31f..57b9b0621dc 100644 --- a/src/EFCore.Design/Design/Internal/AppServiceProviderFactory.cs +++ b/src/EFCore.Design/Design/Internal/AppServiceProviderFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Design/Design/Internal/CSharpHelper.cs b/src/EFCore.Design/Design/Internal/CSharpHelper.cs index 39101c1017a..15d7d23566d 100644 --- a/src/EFCore.Design/Design/Internal/CSharpHelper.cs +++ b/src/EFCore.Design/Design/Internal/CSharpHelper.cs @@ -324,7 +324,8 @@ public virtual string Namespace(params string[] name) Check.NotNull(name, nameof(name)); var @namespace = new StringBuilder(); - foreach (var piece in name.Where(p => !string.IsNullOrEmpty(p)).SelectMany(p => p.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries))) + foreach (var piece in name.Where(p => !string.IsNullOrEmpty(p)) + .SelectMany(p => p.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries))) { var identifier = Identifier(piece); if (!string.IsNullOrEmpty(identifier)) @@ -380,16 +381,16 @@ public virtual string Literal(string value) => /// public virtual string Literal(DateTime value) => string.Format( - CultureInfo.InvariantCulture, - "new DateTime({0}, {1}, {2}, {3}, {4}, {5}, {6}, DateTimeKind.{7})", - value.Year, - value.Month, - value.Day, - value.Hour, - value.Minute, - value.Second, - value.Millisecond, - value.Kind) + CultureInfo.InvariantCulture, + "new DateTime({0}, {1}, {2}, {3}, {4}, {5}, {6}, DateTimeKind.{7})", + value.Year, + value.Month, + value.Day, + value.Hour, + value.Minute, + value.Second, + value.Millisecond, + value.Kind) + (value.Ticks % 10000 == 0 ? "" : string.Format( @@ -430,22 +431,22 @@ private static string EnsureDecimalPlaces(double number) { return $"double.{nameof(double.NaN)}"; } - else if (double.IsNegativeInfinity(number)) + + if (double.IsNegativeInfinity(number)) { return $"double.{nameof(double.NegativeInfinity)}"; } - else if (double.IsPositiveInfinity(number)) + + if (double.IsPositiveInfinity(number)) { return $"double.{nameof(double.PositiveInfinity)}"; } - else - { - return !literal.Contains("E") - && !literal.Contains("e") - && !literal.Contains(".") - ? literal + ".0" - : literal; - } + + return !literal.Contains("E") + && !literal.Contains("e") + && !literal.Contains(".") + ? literal + ".0" + : literal; } /// @@ -547,7 +548,8 @@ public virtual string Literal(TimeSpan value) /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual string Literal(BigInteger value) => $"BigInteger.Parse(\"{value.ToString(NumberFormatInfo.InvariantInfo)}\", NumberFormatInfo.InvariantInfo)"; + public virtual string Literal(BigInteger value) => + $"BigInteger.Parse(\"{value.ToString(NumberFormatInfo.InvariantInfo)}\", NumberFormatInfo.InvariantInfo)"; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -740,7 +742,8 @@ protected virtual string GetCompositeEnumValue(Type type, Enum flags) } } - return allValues.Aggregate((string)null, + return allValues.Aggregate( + (string)null, (previous, current) => previous == null ? GetSimpleEnumValue(type, Enum.GetName(type, current)) @@ -982,7 +985,7 @@ private static bool IsIdentifierStartCharacter(char ch) return ch < 'A' ? false : ch <= 'Z' - || ch == '_'; + || ch == '_'; } if (ch <= 'z') @@ -999,9 +1002,9 @@ private static bool IsIdentifierPartCharacter(char ch) { return ch < 'A' ? ch >= '0' - && ch <= '9' + && ch <= '9' : ch <= 'Z' - || ch == '_'; + || ch == '_'; } if (ch <= 'z') diff --git a/src/EFCore.Design/Design/Internal/DatabaseOperations.cs b/src/EFCore.Design/Design/Internal/DatabaseOperations.cs index 75101c3db03..7ce91cb6448 100644 --- a/src/EFCore.Design/Design/Internal/DatabaseOperations.cs +++ b/src/EFCore.Design/Design/Internal/DatabaseOperations.cs @@ -96,10 +96,7 @@ public virtual SavedModelFiles ScaffoldContext( var scaffoldedModel = scaffolder.ScaffoldModel( connectionString, new DatabaseModelFactoryOptions(tables, schemas), - new ModelReverseEngineerOptions - { - UseDatabaseNames = useDatabaseNames - }, + new ModelReverseEngineerOptions { UseDatabaseNames = useDatabaseNames }, new ModelCodeGenerationOptions { UseDataAnnotations = useDataAnnotations, @@ -108,7 +105,7 @@ public virtual SavedModelFiles ScaffoldContext( ContextNamespace = contextNamespace, Language = _language, ContextDir = MakeDirRelative(outputDir, outputContextDir), - ContextName = dbContextClassName, + ContextName = dbContextClassName }); return scaffolder.Save( @@ -138,7 +135,10 @@ private static string SubnamespaceFromOutputPath(string projectDir, string outpu var subPath = outputDir.Substring(projectDir.Length); return !string.IsNullOrWhiteSpace(subPath) - ? string.Join(".", subPath.Split(new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries)) + ? string.Join( + ".", + subPath.Split( + new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries)) : null; } @@ -158,7 +158,7 @@ private static string NormalizeDir(string path) var last = path[path.Length - 1]; return last == Path.DirectorySeparatorChar - || last == Path.AltDirectorySeparatorChar + || last == Path.AltDirectorySeparatorChar ? path : path + Path.DirectorySeparatorChar; } diff --git a/src/EFCore.Design/Design/Internal/DesignTimeConnectionStringResolver.cs b/src/EFCore.Design/Design/Internal/DesignTimeConnectionStringResolver.cs index 1983db2f615..9c0aaedba2e 100644 --- a/src/EFCore.Design/Design/Internal/DesignTimeConnectionStringResolver.cs +++ b/src/EFCore.Design/Design/Internal/DesignTimeConnectionStringResolver.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -16,8 +16,8 @@ namespace Microsoft.EntityFrameworkCore.Design.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Design/Design/Internal/DesignTimeServicesBuilder.cs b/src/EFCore.Design/Design/Internal/DesignTimeServicesBuilder.cs index 732ec4bd568..13bdaf94d21 100644 --- a/src/EFCore.Design/Design/Internal/DesignTimeServicesBuilder.cs +++ b/src/EFCore.Design/Design/Internal/DesignTimeServicesBuilder.cs @@ -112,9 +112,9 @@ private void ConfigureReferencedServices(IServiceCollection services, string pro _reporter.WriteVerbose(DesignStrings.FindingReferencedServices(_startupAssembly.GetName().Name)); var references = _startupAssembly.GetCustomAttributes() - .Concat(_assembly.GetCustomAttributes()) - .Distinct() - .ToList(); + .Concat(_assembly.GetCustomAttributes()) + .Distinct() + .ToList(); if (references.Count == 0) { diff --git a/src/EFCore.Design/Design/Internal/IOperationReporter.cs b/src/EFCore.Design/Design/Internal/IOperationReporter.cs index 47781d83ad4..560f8dfaae3 100644 --- a/src/EFCore.Design/Design/Internal/IOperationReporter.cs +++ b/src/EFCore.Design/Design/Internal/IOperationReporter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Design/Design/Internal/LanguageBasedSelector.cs b/src/EFCore.Design/Design/Internal/LanguageBasedSelector.cs index ad409b7e905..3b9f465c9ea 100644 --- a/src/EFCore.Design/Design/Internal/LanguageBasedSelector.cs +++ b/src/EFCore.Design/Design/Internal/LanguageBasedSelector.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Design/Design/Internal/MigrationsOperations.cs b/src/EFCore.Design/Design/Internal/MigrationsOperations.cs index fc1e39b6c34..b050966ae42 100644 --- a/src/EFCore.Design/Design/Internal/MigrationsOperations.cs +++ b/src/EFCore.Design/Design/Internal/MigrationsOperations.cs @@ -142,11 +142,7 @@ public virtual IEnumerable GetMigrations( var idGenerator = services.GetRequiredService(); return from id in migrationsAssembly.Migrations.Keys - select new MigrationInfo - { - Id = id, - Name = idGenerator.GetName(id) - }; + select new MigrationInfo { Id = id, Name = idGenerator.GetName(id) }; } } diff --git a/src/EFCore.Design/Design/Internal/NamespaceComparer.cs b/src/EFCore.Design/Design/Internal/NamespaceComparer.cs index 41e72f88f82..9d0148b75ba 100644 --- a/src/EFCore.Design/Design/Internal/NamespaceComparer.cs +++ b/src/EFCore.Design/Design/Internal/NamespaceComparer.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; diff --git a/src/EFCore.Design/Design/Internal/NullPluralizer.cs b/src/EFCore.Design/Design/Internal/NullPluralizer.cs index d19555b5383..e4048758b3d 100644 --- a/src/EFCore.Design/Design/Internal/NullPluralizer.cs +++ b/src/EFCore.Design/Design/Internal/NullPluralizer.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. namespace Microsoft.EntityFrameworkCore.Design.Internal diff --git a/src/EFCore.Design/Design/Internal/OperationLogger.cs b/src/EFCore.Design/Design/Internal/OperationLogger.cs index 86decb3bae2..aac42d95afe 100644 --- a/src/EFCore.Design/Design/Internal/OperationLogger.cs +++ b/src/EFCore.Design/Design/Internal/OperationLogger.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Design/Design/Internal/OperationReporter.cs b/src/EFCore.Design/Design/Internal/OperationReporter.cs index 7d0f9bddd6a..99cc06b1986 100644 --- a/src/EFCore.Design/Design/Internal/OperationReporter.cs +++ b/src/EFCore.Design/Design/Internal/OperationReporter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Design/Design/OperationExecutor.cs b/src/EFCore.Design/Design/OperationExecutor.cs index 68c34b80ec8..03918b367cf 100644 --- a/src/EFCore.Design/Design/OperationExecutor.cs +++ b/src/EFCore.Design/Design/OperationExecutor.cs @@ -111,7 +111,6 @@ private MigrationsOperations MigrationsOperations _language, _designArgs); - private DbContextOperations ContextOperations => _contextOperations ??= new DbContextOperations( @@ -180,9 +179,7 @@ private IDictionary AddMigrationImpl( return new Hashtable { - ["MigrationFile"] = files.MigrationFile, - ["MetadataFile"] = files.MetadataFile, - ["SnapshotFile"] = files.SnapshotFile + ["MigrationFile"] = files.MigrationFile, ["MetadataFile"] = files.MetadataFile, ["SnapshotFile"] = files.SnapshotFile }; } @@ -199,7 +196,8 @@ public class GetContextInfo : OperationBase /// The operation executor. /// The . /// The operation arguments. - public GetContextInfo([NotNull] OperationExecutor executor, [NotNull] IOperationResultHandler resultHandler, [NotNull] IDictionary args) + public GetContextInfo( + [NotNull] OperationExecutor executor, [NotNull] IOperationResultHandler resultHandler, [NotNull] IDictionary args) : base(resultHandler) { Check.NotNull(executor, nameof(executor)); @@ -239,7 +237,8 @@ public class UpdateDatabase : OperationBase /// The operation executor. /// The . /// The operation arguments. - public UpdateDatabase([NotNull] OperationExecutor executor, [NotNull] IOperationResultHandler resultHandler, [NotNull] IDictionary args) + public UpdateDatabase( + [NotNull] OperationExecutor executor, [NotNull] IOperationResultHandler resultHandler, [NotNull] IDictionary args) : base(resultHandler) { Check.NotNull(executor, nameof(executor)); @@ -336,9 +335,7 @@ private IDictionary RemoveMigrationImpl([CanBeNull] string contextType, bool for return new Hashtable { - ["MigrationFile"] = files.MigrationFile, - ["MetadataFile"] = files.MetadataFile, - ["SnapshotFile"] = files.SnapshotFile + ["MigrationFile"] = files.MigrationFile, ["MetadataFile"] = files.MetadataFile, ["SnapshotFile"] = files.SnapshotFile }; } @@ -354,7 +351,8 @@ public class GetContextTypes : OperationBase /// The operation executor. /// The . /// The operation arguments. - public GetContextTypes([NotNull] OperationExecutor executor, [NotNull] IOperationResultHandler resultHandler, [NotNull] IDictionary args) + public GetContextTypes( + [NotNull] OperationExecutor executor, [NotNull] IOperationResultHandler resultHandler, [NotNull] IDictionary args) : base(resultHandler) { Check.NotNull(executor, nameof(executor)); @@ -397,7 +395,8 @@ public class GetMigrations : OperationBase /// The operation executor. /// The . /// The operation arguments. - public GetMigrations([NotNull] OperationExecutor executor, [NotNull] IOperationResultHandler resultHandler, [NotNull] IDictionary args) + public GetMigrations( + [NotNull] OperationExecutor executor, [NotNull] IOperationResultHandler resultHandler, [NotNull] IDictionary args) : base(resultHandler) { Check.NotNull(executor, nameof(executor)); @@ -447,7 +446,8 @@ public class ScaffoldContext : OperationBase /// The operation executor. /// The . /// The operation arguments. - public ScaffoldContext([NotNull] OperationExecutor executor, [NotNull] IOperationResultHandler resultHandler, [NotNull] IDictionary args) + public ScaffoldContext( + [NotNull] OperationExecutor executor, [NotNull] IOperationResultHandler resultHandler, [NotNull] IDictionary args) : base(resultHandler) { Check.NotNull(executor, nameof(executor)); @@ -492,11 +492,7 @@ private IDictionary ScaffoldContextImpl( provider, connectionString, outputDir, outputDbContextDir, dbContextClassName, schemaFilters, tableFilters, useDataAnnotations, overwriteFiles, useDatabaseNames); - return new Hashtable - { - ["ContextFile"] = files.ContextFile, - ["EntityTypeFiles"] = files.AdditionalFiles.ToArray() - }; + return new Hashtable { ["ContextFile"] = files.ContextFile, ["EntityTypeFiles"] = files.AdditionalFiles.ToArray() }; } /// diff --git a/src/EFCore.Design/Design/OperationResultHandler.cs b/src/EFCore.Design/Design/OperationResultHandler.cs index 98187243288..8befc020273 100644 --- a/src/EFCore.Design/Design/OperationResultHandler.cs +++ b/src/EFCore.Design/Design/OperationResultHandler.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Design/Metadata/Internal/ScaffoldingModelExtensions.cs b/src/EFCore.Design/Metadata/Internal/ScaffoldingModelExtensions.cs index 8b9dcb64b37..7bd093f278e 100644 --- a/src/EFCore.Design/Metadata/Internal/ScaffoldingModelExtensions.cs +++ b/src/EFCore.Design/Metadata/Internal/ScaffoldingModelExtensions.cs @@ -30,7 +30,6 @@ public static IDictionary GetEntityTypeErrors(this IModel model) } return errors; - } /// diff --git a/src/EFCore.Design/Migrations/Design/CSharpMigrationOperationGeneratorDependencies.cs b/src/EFCore.Design/Migrations/Design/CSharpMigrationOperationGeneratorDependencies.cs index d4a93e7103b..7ee81a6abcb 100644 --- a/src/EFCore.Design/Migrations/Design/CSharpMigrationOperationGeneratorDependencies.cs +++ b/src/EFCore.Design/Migrations/Design/CSharpMigrationOperationGeneratorDependencies.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs b/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs index f793f37f93c..6b1e24f2423 100644 --- a/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs +++ b/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs @@ -73,10 +73,7 @@ public override string GenerateMigration( Check.NotNull(downOperations, nameof(downOperations)); var builder = new IndentedStringBuilder(); - var namespaces = new List - { - "Microsoft.EntityFrameworkCore.Migrations" - }; + var namespaces = new List { "Microsoft.EntityFrameworkCore.Migrations" }; namespaces.AddRange(GetNamespaces(upOperations.Concat(downOperations))); foreach (var n in namespaces.OrderBy(x => x, new NamespaceComparer()).Distinct()) { diff --git a/src/EFCore.Design/Migrations/Design/CSharpMigrationsGeneratorDependencies.cs b/src/EFCore.Design/Migrations/Design/CSharpMigrationsGeneratorDependencies.cs index 16994d34dc4..9517a219310 100644 --- a/src/EFCore.Design/Migrations/Design/CSharpMigrationsGeneratorDependencies.cs +++ b/src/EFCore.Design/Migrations/Design/CSharpMigrationsGeneratorDependencies.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.cs b/src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.cs index 7f4c959b645..848ff5b7e2d 100644 --- a/src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.cs +++ b/src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.cs @@ -60,7 +60,9 @@ public virtual void Generate(string builderName, IModel model, IndentedStringBui using (stringBuilder.Indent()) { - GenerateFluentApiForAnnotation(ref annotations, RelationalAnnotationNames.DefaultSchema, nameof(RelationalModelBuilderExtensions.HasDefaultSchema), stringBuilder); + GenerateFluentApiForAnnotation( + ref annotations, RelationalAnnotationNames.DefaultSchema, nameof(RelationalModelBuilderExtensions.HasDefaultSchema), + stringBuilder); IgnoreAnnotationTypes(annotations, RelationalAnnotationNames.DbFunction); IgnoreAnnotations( @@ -567,7 +569,8 @@ protected virtual void GenerateKey( { var annotations = key.GetAnnotations().ToList(); - GenerateFluentApiForAnnotation(ref annotations, RelationalAnnotationNames.Name, nameof(RelationalKeyBuilderExtensions.HasName), stringBuilder); + GenerateFluentApiForAnnotation( + ref annotations, RelationalAnnotationNames.Name, nameof(RelationalKeyBuilderExtensions.HasName), stringBuilder); GenerateAnnotations(annotations, stringBuilder); } @@ -629,8 +632,10 @@ protected virtual void GenerateIndex( var annotations = index.GetAnnotations().ToList(); - GenerateFluentApiForAnnotation(ref annotations, RelationalAnnotationNames.Name, nameof(RelationalIndexBuilderExtensions.HasName), stringBuilder); - GenerateFluentApiForAnnotation(ref annotations, RelationalAnnotationNames.Filter, nameof(RelationalIndexBuilderExtensions.HasFilter), stringBuilder); + GenerateFluentApiForAnnotation( + ref annotations, RelationalAnnotationNames.Name, nameof(RelationalIndexBuilderExtensions.HasName), stringBuilder); + GenerateFluentApiForAnnotation( + ref annotations, RelationalAnnotationNames.Filter, nameof(RelationalIndexBuilderExtensions.HasFilter), stringBuilder); GenerateAnnotations(annotations, stringBuilder); } @@ -911,7 +916,8 @@ protected virtual void GenerateForeignKey( using (stringBuilder.Indent()) { - if (foreignKey.IsUnique && !foreignKey.IsOwnership) + if (foreignKey.IsUnique + && !foreignKey.IsOwnership) { stringBuilder .Append(".WithOne("); @@ -1005,7 +1011,8 @@ protected virtual void GenerateForeignKey( /// /// The foreign key. /// The builder code is added to. - protected virtual void GenerateForeignKeyAnnotations([NotNull] IForeignKey foreignKey, [NotNull] IndentedStringBuilder stringBuilder) + protected virtual void GenerateForeignKeyAnnotations( + [NotNull] IForeignKey foreignKey, [NotNull] IndentedStringBuilder stringBuilder) { Check.NotNull(foreignKey, nameof(foreignKey)); Check.NotNull(stringBuilder, nameof(stringBuilder)); @@ -1053,7 +1060,8 @@ protected virtual void IgnoreAnnotationTypes( Check.NotNull(annotations, nameof(annotations)); Check.NotNull(annotationPrefixes, nameof(annotationPrefixes)); - foreach (var ignoreAnnotation in annotations.Where(a => annotationPrefixes.Any(pre => a.Name.StartsWith(pre, StringComparison.OrdinalIgnoreCase))).ToList()) + foreach (var ignoreAnnotation in annotations + .Where(a => annotationPrefixes.Any(pre => a.Name.StartsWith(pre, StringComparison.OrdinalIgnoreCase))).ToList()) { annotations.Remove(ignoreAnnotation); } diff --git a/src/EFCore.Design/Migrations/Design/CSharpSnapshotGeneratorDependencies.cs b/src/EFCore.Design/Migrations/Design/CSharpSnapshotGeneratorDependencies.cs index b610fac0429..525217516c6 100644 --- a/src/EFCore.Design/Migrations/Design/CSharpSnapshotGeneratorDependencies.cs +++ b/src/EFCore.Design/Migrations/Design/CSharpSnapshotGeneratorDependencies.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Design/Migrations/Design/IMigrationsCodeGeneratorSelector.cs b/src/EFCore.Design/Migrations/Design/IMigrationsCodeGeneratorSelector.cs index f26cb493eab..92945fd6c43 100644 --- a/src/EFCore.Design/Migrations/Design/IMigrationsCodeGeneratorSelector.cs +++ b/src/EFCore.Design/Migrations/Design/IMigrationsCodeGeneratorSelector.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Design/Migrations/Design/MigrationsCodeGenerator.cs b/src/EFCore.Design/Migrations/Design/MigrationsCodeGenerator.cs index 8aa920f2f5d..73ec9b7dab8 100644 --- a/src/EFCore.Design/Migrations/Design/MigrationsCodeGenerator.cs +++ b/src/EFCore.Design/Migrations/Design/MigrationsCodeGenerator.cs @@ -244,17 +244,12 @@ private IEnumerable GetAnnotationNamespaces(IEnumerable it var ignoredAnnotationTypes = new List { - RelationalAnnotationNames.DbFunction, - RelationalAnnotationNames.SequencePrefix + RelationalAnnotationNames.DbFunction, RelationalAnnotationNames.SequencePrefix }; return items.SelectMany( i => i.GetAnnotations().Select( - a => new - { - Annotatable = i, - Annotation = a - }) + a => new { Annotatable = i, Annotation = a }) .Where( a => a.Annotation.Value != null && !ignoredAnnotations.Contains(a.Annotation.Name) diff --git a/src/EFCore.Design/Migrations/Design/MigrationsCodeGeneratorDependencies.cs b/src/EFCore.Design/Migrations/Design/MigrationsCodeGeneratorDependencies.cs index 91c3b4a8de4..2f9d76a83b5 100644 --- a/src/EFCore.Design/Migrations/Design/MigrationsCodeGeneratorDependencies.cs +++ b/src/EFCore.Design/Migrations/Design/MigrationsCodeGeneratorDependencies.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs b/src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs index ca2dfb88ef1..3560636584c 100644 --- a/src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs +++ b/src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs @@ -245,7 +245,8 @@ public virtual MigrationFiles RemoveMigration( var migration = migrations[migrations.Count - 1]; model = migration.TargetModel; - if (!Dependencies.MigrationsModelDiffer.HasDifferences(model, Dependencies.SnapshotModelProcessor.Process(modelSnapshot.Model))) + if (!Dependencies.MigrationsModelDiffer.HasDifferences( + model, Dependencies.SnapshotModelProcessor.Process(modelSnapshot.Model))) { var applied = false; try @@ -386,9 +387,7 @@ public virtual MigrationFiles Save(string projectDir, ScaffoldedMigration migrat return new MigrationFiles { - MigrationFile = migrationFile, - MetadataFile = migrationMetadataFile, - SnapshotFile = modelSnapshotFile + MigrationFile = migrationFile, MetadataFile = migrationMetadataFile, SnapshotFile = modelSnapshotFile }; } diff --git a/src/EFCore.Design/Migrations/Design/MigrationsScaffolderDependencies.cs b/src/EFCore.Design/Migrations/Design/MigrationsScaffolderDependencies.cs index 99b944224c9..402f9629ff0 100644 --- a/src/EFCore.Design/Migrations/Design/MigrationsScaffolderDependencies.cs +++ b/src/EFCore.Design/Migrations/Design/MigrationsScaffolderDependencies.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Design/Migrations/Internal/MigrationsCodeGeneratorSelector.cs b/src/EFCore.Design/Migrations/Internal/MigrationsCodeGeneratorSelector.cs index 2d945c64fb9..e5e6c7817c1 100644 --- a/src/EFCore.Design/Migrations/Internal/MigrationsCodeGeneratorSelector.cs +++ b/src/EFCore.Design/Migrations/Internal/MigrationsCodeGeneratorSelector.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; diff --git a/src/EFCore.Design/Migrations/Internal/SnapshotModelProcessor.cs b/src/EFCore.Design/Migrations/Internal/SnapshotModelProcessor.cs index 58d11f5e642..6fc5d470eae 100644 --- a/src/EFCore.Design/Migrations/Internal/SnapshotModelProcessor.cs +++ b/src/EFCore.Design/Migrations/Internal/SnapshotModelProcessor.cs @@ -10,7 +10,6 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Metadata.Internal; namespace Microsoft.EntityFrameworkCore.Migrations.Internal { diff --git a/src/EFCore.Design/Scaffolding/IModelCodeGenerator.cs b/src/EFCore.Design/Scaffolding/IModelCodeGenerator.cs index 8d746fd8f3e..d518e19dcef 100644 --- a/src/EFCore.Design/Scaffolding/IModelCodeGenerator.cs +++ b/src/EFCore.Design/Scaffolding/IModelCodeGenerator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Design/Scaffolding/IModelCodeGeneratorSelector.cs b/src/EFCore.Design/Scaffolding/IModelCodeGeneratorSelector.cs index a9f05dc8a15..46de04887fe 100644 --- a/src/EFCore.Design/Scaffolding/IModelCodeGeneratorSelector.cs +++ b/src/EFCore.Design/Scaffolding/IModelCodeGeneratorSelector.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Design/Scaffolding/IReverseEngineerScaffolder.cs b/src/EFCore.Design/Scaffolding/IReverseEngineerScaffolder.cs index 461b0bbff48..6ddccb99c6b 100644 --- a/src/EFCore.Design/Scaffolding/IReverseEngineerScaffolder.cs +++ b/src/EFCore.Design/Scaffolding/IReverseEngineerScaffolder.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Design/Scaffolding/Internal/CSharpDbContextGenerator.cs b/src/EFCore.Design/Scaffolding/Internal/CSharpDbContextGenerator.cs index a7bee33921f..9386c8cf6c3 100644 --- a/src/EFCore.Design/Scaffolding/Internal/CSharpDbContextGenerator.cs +++ b/src/EFCore.Design/Scaffolding/Internal/CSharpDbContextGenerator.cs @@ -448,10 +448,7 @@ private void GenerateKey(IKey key, IEntityType entityType, bool useDataAnnotatio { if (key == null) { - var line = new List - { - $".{nameof(EntityTypeBuilder.HasNoKey)}()" - }; + var line = new List { $".{nameof(EntityTypeBuilder.HasNoKey)}()" }; AppendMultiLineFluentApi(entityType, line); @@ -482,10 +479,7 @@ private void GenerateKey(IKey key, IEntityType entityType, bool useDataAnnotatio } } - var lines = new List - { - $".{nameof(EntityTypeBuilder.HasKey)}(e => {GenerateLambdaToKey(key.Properties, "e")})" - }; + var lines = new List { $".{nameof(EntityTypeBuilder.HasKey)}(e => {GenerateLambdaToKey(key.Properties, "e")})" }; if (explicitName) { @@ -548,10 +542,7 @@ private void GenerateTableName(IEntityType entityType) private void GenerateIndex(IIndex index) { - var lines = new List - { - $".{nameof(EntityTypeBuilder.HasIndex)}(e => {GenerateLambdaToKey(index.Properties, "e")})" - }; + var lines = new List { $".{nameof(EntityTypeBuilder.HasIndex)}(e => {GenerateLambdaToKey(index.Properties, "e")})" }; var annotations = index.GetAnnotations().ToList(); @@ -603,10 +594,7 @@ private void GenerateIndex(IIndex index) private void GenerateProperty(IProperty property, bool useDataAnnotations) { - var lines = new List - { - $".{nameof(EntityTypeBuilder.Property)}(e => e.{property.Name})" - }; + var lines = new List { $".{nameof(EntityTypeBuilder.Property)}(e => e.{property.Name})" }; var annotations = property.GetAnnotations().ToList(); @@ -765,10 +753,7 @@ private void GenerateProperty(IProperty property, bool useDataAnnotations) case 1: return; case 2: - lines = new List - { - lines[0] + lines[1] - }; + lines = new List { lines[0] + lines[1] }; break; } @@ -782,9 +767,10 @@ private void GenerateRelationship(IForeignKey foreignKey, bool useDataAnnotation var lines = new List { - $".{nameof(EntityTypeBuilder.HasOne)}(" + (foreignKey.DependentToPrincipal != null ? $"d => d.{foreignKey.DependentToPrincipal.Name}" : null) + ")", + $".{nameof(EntityTypeBuilder.HasOne)}(" + + (foreignKey.DependentToPrincipal != null ? $"d => d.{foreignKey.DependentToPrincipal.Name}" : null) + ")", $".{(foreignKey.IsUnique ? nameof(ReferenceNavigationBuilder.WithOne) : nameof(ReferenceNavigationBuilder.WithMany))}" - + $"(" + (foreignKey.PrincipalToDependent != null ? $"p => p.{foreignKey.PrincipalToDependent.Name}" : null) + ")" + + "(" + (foreignKey.PrincipalToDependent != null ? $"p => p.{foreignKey.PrincipalToDependent.Name}" : null) + ")" }; if (!foreignKey.PrincipalKey.IsPrimaryKey()) @@ -792,13 +778,13 @@ private void GenerateRelationship(IForeignKey foreignKey, bool useDataAnnotation canUseDataAnnotations = false; lines.Add( $".{nameof(ReferenceReferenceBuilder.HasPrincipalKey)}" - + (foreignKey.IsUnique ? $"<{((ITypeBase)foreignKey.PrincipalEntityType).DisplayName()}>" : "") + + (foreignKey.IsUnique ? $"<{foreignKey.PrincipalEntityType.DisplayName()}>" : "") + $"(p => {GenerateLambdaToKey(foreignKey.PrincipalKey.Properties, "p")})"); } lines.Add( $".{nameof(ReferenceReferenceBuilder.HasForeignKey)}" - + (foreignKey.IsUnique ? $"<{((ITypeBase)foreignKey.DeclaringEntityType).DisplayName()}>" : "") + + (foreignKey.IsUnique ? $"<{foreignKey.DeclaringEntityType.DisplayName()}>" : "") + $"(d => {GenerateLambdaToKey(foreignKey.Properties, "d")})"); var defaultOnDeleteAction = foreignKey.IsRequired @@ -817,7 +803,7 @@ private void GenerateRelationship(IForeignKey foreignKey, bool useDataAnnotation { canUseDataAnnotations = false; lines.Add( - $".HasConstraintName" + + ".HasConstraintName" + $"({_code.Literal(foreignKey.GetConstraintName())})"); RemoveAnnotation(ref annotations, RelationalAnnotationNames.Name); } @@ -869,10 +855,7 @@ private void GenerateSequence(ISequence sequence) parameters += $", {_code.Literal(sequence.Schema)}"; } - var lines = new List - { - $"modelBuilder.{methodName}({parameters})" - }; + var lines = new List { $"modelBuilder.{methodName}({parameters})" }; if (sequence.StartValue != Sequence.DefaultStartValue) { @@ -901,10 +884,7 @@ private void GenerateSequence(ISequence sequence) if (lines.Count == 2) { - lines = new List - { - lines[0] + lines[1] - }; + lines = new List { lines[0] + lines[1] }; } _sb.AppendLine(); @@ -929,8 +909,8 @@ private static string GenerateLambdaToKey( return properties.Count <= 0 ? "" : properties.Count == 1 - ? $"{lambdaIdentifier}.{properties[0].Name}" - : $"new {{ {string.Join(", ", properties.Select(p => lambdaIdentifier + "." + p.Name))} }}"; + ? $"{lambdaIdentifier}.{properties[0].Name}" + : $"new {{ {string.Join(", ", properties.Select(p => lambdaIdentifier + "." + p.Name))} }}"; } private static void RemoveAnnotation(ref List annotations, string annotationName) diff --git a/src/EFCore.Design/Scaffolding/Internal/CSharpEntityTypeGenerator.cs b/src/EFCore.Design/Scaffolding/Internal/CSharpEntityTypeGenerator.cs index 6520e722bc0..b600add47a7 100644 --- a/src/EFCore.Design/Scaffolding/Internal/CSharpEntityTypeGenerator.cs +++ b/src/EFCore.Design/Scaffolding/Internal/CSharpEntityTypeGenerator.cs @@ -341,8 +341,8 @@ private void GenerateForeignKeyAttribute(INavigation navigation) if (navigation.ForeignKey.Properties.Count > 1) { foreignKeyAttribute.AddParameter( - _code.Literal( - string.Join(",", navigation.ForeignKey.Properties.Select(p => p.Name)))); + _code.Literal( + string.Join(",", navigation.ForeignKey.Properties.Select(p => p.Name)))); } else { @@ -400,7 +400,7 @@ public override string ToString() private static string StripAttribute([NotNull] string attributeName) => attributeName.EndsWith("Attribute", StringComparison.Ordinal) - ? attributeName[0..^9] + ? attributeName[..^9] : attributeName; } } diff --git a/src/EFCore.Design/Scaffolding/Internal/CSharpModelGenerator.cs b/src/EFCore.Design/Scaffolding/Internal/CSharpModelGenerator.cs index 2afb9453fce..8217a6bda05 100644 --- a/src/EFCore.Design/Scaffolding/Internal/CSharpModelGenerator.cs +++ b/src/EFCore.Design/Scaffolding/Internal/CSharpModelGenerator.cs @@ -99,13 +99,9 @@ public override ScaffoldedModel GenerateModel( generatedCode = CSharpEntityTypeGenerator.WriteCode(entityType, options.ModelNamespace, options.UseDataAnnotations); // output EntityType poco .cs file - var entityTypeFileName = ((ITypeBase)entityType).DisplayName() + FileExtension; + var entityTypeFileName = entityType.DisplayName() + FileExtension; resultingFiles.AdditionalFiles.Add( - new ScaffoldedFile - { - Path = entityTypeFileName, - Code = generatedCode - }); + new ScaffoldedFile { Path = entityTypeFileName, Code = generatedCode }); } return resultingFiles; diff --git a/src/EFCore.Design/Scaffolding/Internal/CSharpUtilities.cs b/src/EFCore.Design/Scaffolding/Internal/CSharpUtilities.cs index d8ec477450f..2e2fb86ddb5 100644 --- a/src/EFCore.Design/Scaffolding/Internal/CSharpUtilities.cs +++ b/src/EFCore.Design/Scaffolding/Internal/CSharpUtilities.cs @@ -233,7 +233,7 @@ private static bool IsIdentifierStartCharacter(char ch) return ch < 'A' ? false : ch <= 'Z' - || ch == '_'; + || ch == '_'; } if (ch <= 'z') @@ -250,9 +250,9 @@ private static bool IsIdentifierPartCharacter(char ch) { return ch < 'A' ? ch >= '0' - && ch <= '9' + && ch <= '9' : ch <= 'Z' - || ch == '_'; + || ch == '_'; } if (ch <= 'z') diff --git a/src/EFCore.Design/Scaffolding/Internal/CandidateNamingService.cs b/src/EFCore.Design/Scaffolding/Internal/CandidateNamingService.cs index 3147f42ca6d..e8f50874bee 100644 --- a/src/EFCore.Design/Scaffolding/Internal/CandidateNamingService.cs +++ b/src/EFCore.Design/Scaffolding/Internal/CandidateNamingService.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -76,7 +76,7 @@ public virtual string GetPrincipalEndCandidateNavigationPropertyName( return allForeignKeysBetweenDependentAndPrincipal?.Count() > 1 ? foreignKey.DeclaringEntityType.ShortName() - + dependentEndNavigationPropertyName + + dependentEndNavigationPropertyName : foreignKey.DeclaringEntityType.ShortName(); } @@ -157,8 +157,8 @@ private static string FindCommonPrefix(string firstName, IEnumerable pro private static string StripId(string commonPrefix) { return commonPrefix.Length > 2 - && commonPrefix.EndsWith("id", StringComparison.OrdinalIgnoreCase) - ? commonPrefix[0..^2] + && commonPrefix.EndsWith("id", StringComparison.OrdinalIgnoreCase) + ? commonPrefix[..^2] : commonPrefix; } } diff --git a/src/EFCore.Design/Scaffolding/Internal/ICSharpDbContextGenerator.cs b/src/EFCore.Design/Scaffolding/Internal/ICSharpDbContextGenerator.cs index ce6d0d53591..916b049f782 100644 --- a/src/EFCore.Design/Scaffolding/Internal/ICSharpDbContextGenerator.cs +++ b/src/EFCore.Design/Scaffolding/Internal/ICSharpDbContextGenerator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Design/Scaffolding/Internal/ICSharpEntityTypeGenerator.cs b/src/EFCore.Design/Scaffolding/Internal/ICSharpEntityTypeGenerator.cs index 2653c75f286..3bc6ea0fcd8 100644 --- a/src/EFCore.Design/Scaffolding/Internal/ICSharpEntityTypeGenerator.cs +++ b/src/EFCore.Design/Scaffolding/Internal/ICSharpEntityTypeGenerator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Design/Scaffolding/Internal/ICSharpUtilities.cs b/src/EFCore.Design/Scaffolding/Internal/ICSharpUtilities.cs index 21b9d9bdc40..b9c278d543a 100644 --- a/src/EFCore.Design/Scaffolding/Internal/ICSharpUtilities.cs +++ b/src/EFCore.Design/Scaffolding/Internal/ICSharpUtilities.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -21,7 +21,9 @@ public interface ICSharpUtilities /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - string GenerateCSharpIdentifier([NotNull] string identifier, [CanBeNull] ICollection existingIdentifiers, [CanBeNull] Func singularizePluralizer); + string GenerateCSharpIdentifier( + [NotNull] string identifier, [CanBeNull] ICollection existingIdentifiers, + [CanBeNull] Func singularizePluralizer); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -29,7 +31,9 @@ public interface ICSharpUtilities /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - string GenerateCSharpIdentifier([NotNull] string identifier, [CanBeNull] ICollection existingIdentifiers, [CanBeNull] Func singularizePluralizer, [NotNull] Func, string> uniquifier); + string GenerateCSharpIdentifier( + [NotNull] string identifier, [CanBeNull] ICollection existingIdentifiers, + [CanBeNull] Func singularizePluralizer, [NotNull] Func, string> uniquifier); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.Design/Scaffolding/Internal/ICandidateNamingService.cs b/src/EFCore.Design/Scaffolding/Internal/ICandidateNamingService.cs index 59f73da638c..6897c0f62b4 100644 --- a/src/EFCore.Design/Scaffolding/Internal/ICandidateNamingService.cs +++ b/src/EFCore.Design/Scaffolding/Internal/ICandidateNamingService.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Design/Scaffolding/Internal/IScaffoldingTypeMapper.cs b/src/EFCore.Design/Scaffolding/Internal/IScaffoldingTypeMapper.cs index 127194ae8d6..cce7a6eb0c0 100644 --- a/src/EFCore.Design/Scaffolding/Internal/IScaffoldingTypeMapper.cs +++ b/src/EFCore.Design/Scaffolding/Internal/IScaffoldingTypeMapper.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Design/Scaffolding/Internal/ModelCodeGeneratorSelector.cs b/src/EFCore.Design/Scaffolding/Internal/ModelCodeGeneratorSelector.cs index d28b6104b6a..dc01f69a7f3 100644 --- a/src/EFCore.Design/Scaffolding/Internal/ModelCodeGeneratorSelector.cs +++ b/src/EFCore.Design/Scaffolding/Internal/ModelCodeGeneratorSelector.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; diff --git a/src/EFCore.Design/Scaffolding/Internal/RelationalScaffoldingModelFactory.cs b/src/EFCore.Design/Scaffolding/Internal/RelationalScaffoldingModelFactory.cs index c5a0a281c6e..5f43665105a 100644 --- a/src/EFCore.Design/Scaffolding/Internal/RelationalScaffoldingModelFactory.cs +++ b/src/EFCore.Design/Scaffolding/Internal/RelationalScaffoldingModelFactory.cs @@ -208,7 +208,8 @@ protected virtual ModelBuilder VisitDatabaseModel([NotNull] ModelBuilder modelBu /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected virtual ModelBuilder VisitSequences([NotNull] ModelBuilder modelBuilder, [NotNull] ICollection sequences) + protected virtual ModelBuilder VisitSequences( + [NotNull] ModelBuilder modelBuilder, [NotNull] ICollection sequences) { Check.NotNull(modelBuilder, nameof(modelBuilder)); Check.NotNull(sequences, nameof(sequences)); @@ -521,7 +522,6 @@ protected virtual KeyBuilder VisitPrimaryKey([NotNull] EntityTypeBuilder builder var keyBuilder = builder.HasKey(primaryKey.Columns.Select(GetPropertyName).ToArray()); - if (primaryKey.Columns.Count == 1 && primaryKey.Columns[0].ValueGenerated == null && primaryKey.Columns[0].DefaultValueSql == null) @@ -554,7 +554,8 @@ protected virtual KeyBuilder VisitPrimaryKey([NotNull] EntityTypeBuilder builder /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected virtual EntityTypeBuilder VisitUniqueConstraints([NotNull] EntityTypeBuilder builder, [NotNull] ICollection uniqueConstraints) + protected virtual EntityTypeBuilder VisitUniqueConstraints( + [NotNull] EntityTypeBuilder builder, [NotNull] ICollection uniqueConstraints) { Check.NotNull(builder, nameof(builder)); Check.NotNull(uniqueConstraints, nameof(uniqueConstraints)); @@ -573,7 +574,8 @@ protected virtual EntityTypeBuilder VisitUniqueConstraints([NotNull] EntityTypeB /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected virtual IndexBuilder VisitUniqueConstraint([NotNull] EntityTypeBuilder builder, [NotNull] DatabaseUniqueConstraint uniqueConstraint) + protected virtual IndexBuilder VisitUniqueConstraint( + [NotNull] EntityTypeBuilder builder, [NotNull] DatabaseUniqueConstraint uniqueConstraint) { Check.NotNull(builder, nameof(builder)); Check.NotNull(uniqueConstraint, nameof(uniqueConstraint)); @@ -674,7 +676,8 @@ protected virtual IndexBuilder VisitIndex([NotNull] EntityTypeBuilder builder, [ /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected virtual ModelBuilder VisitForeignKeys([NotNull] ModelBuilder modelBuilder, [NotNull] IList foreignKeys) + protected virtual ModelBuilder VisitForeignKeys( + [NotNull] ModelBuilder modelBuilder, [NotNull] IList foreignKeys) { Check.NotNull(modelBuilder, nameof(modelBuilder)); Check.NotNull(foreignKeys, nameof(foreignKeys)); @@ -820,7 +823,7 @@ protected virtual IMutableForeignKey VisitForeignKey([NotNull] ModelBuilder mode var dependentKey = dependentEntityType.FindKey(dependentProperties); var dependentIndex = dependentEntityType.FindIndex(dependentProperties); newForeignKey.IsUnique = dependentKey != null - || dependentIndex?.IsUnique == true; + || dependentIndex?.IsUnique == true; if (!string.IsNullOrEmpty(foreignKey.Name) && foreignKey.Name != newForeignKey.GetDefaultName()) @@ -883,7 +886,8 @@ protected virtual void AddNavigationProperties([NotNull] IMutableForeignKey fore } // Stores the names of the EntityType itself and its Properties, but does not include any Navigation Properties - private readonly Dictionary> _entityTypeAndPropertyIdentifiers = new Dictionary>(); + private readonly Dictionary> _entityTypeAndPropertyIdentifiers = + new Dictionary>(); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -897,10 +901,7 @@ protected virtual List ExistingIdentifiers([NotNull] IEntityType entityT if (!_entityTypeAndPropertyIdentifiers.TryGetValue(entityType, out var existingIdentifiers)) { - existingIdentifiers = new List - { - entityType.Name - }; + existingIdentifiers = new List { entityType.Name }; existingIdentifiers.AddRange(entityType.GetProperties().Select(p => p.Name)); _entityTypeAndPropertyIdentifiers[entityType] = existingIdentifiers; } diff --git a/src/EFCore.Design/Scaffolding/Internal/ReverseEngineerScaffolder.cs b/src/EFCore.Design/Scaffolding/Internal/ReverseEngineerScaffolder.cs index 0cc1a887667..7e7ac66da43 100644 --- a/src/EFCore.Design/Scaffolding/Internal/ReverseEngineerScaffolder.cs +++ b/src/EFCore.Design/Scaffolding/Internal/ReverseEngineerScaffolder.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Design/Scaffolding/Internal/ScaffoldingTypeMapper.cs b/src/EFCore.Design/Scaffolding/Internal/ScaffoldingTypeMapper.cs index 0ee34204cf0..ec7518babff 100644 --- a/src/EFCore.Design/Scaffolding/Internal/ScaffoldingTypeMapper.cs +++ b/src/EFCore.Design/Scaffolding/Internal/ScaffoldingTypeMapper.cs @@ -80,7 +80,9 @@ public virtual TypeScaffoldingInfo FindMapping( size: mapping.Size, fixedLength: false); - scaffoldFixedLength = fixedLengthMapping.IsFixedLength != byteArrayMapping.IsFixedLength ? (bool?)byteArrayMapping.IsFixedLength : null; + scaffoldFixedLength = fixedLengthMapping.IsFixedLength != byteArrayMapping.IsFixedLength + ? (bool?)byteArrayMapping.IsFixedLength + : null; // Check for size var sizedMapping = _typeMappingSource.FindMapping( @@ -128,7 +130,9 @@ public virtual TypeScaffoldingInfo FindMapping( size: mapping.Size, fixedLength: false); - scaffoldFixedLength = fixedLengthMapping.IsFixedLength != stringMapping.IsFixedLength ? (bool?)stringMapping.IsFixedLength : null; + scaffoldFixedLength = fixedLengthMapping.IsFixedLength != stringMapping.IsFixedLength + ? (bool?)stringMapping.IsFixedLength + : null; // Check for size var sizedMapping = _typeMappingSource.FindMapping( diff --git a/src/EFCore.Design/Scaffolding/Metadata/Internal/DatabaseColumnExtensions.cs b/src/EFCore.Design/Scaffolding/Metadata/Internal/DatabaseColumnExtensions.cs index 7047944db3b..1cf7bbe3698 100644 --- a/src/EFCore.Design/Scaffolding/Metadata/Internal/DatabaseColumnExtensions.cs +++ b/src/EFCore.Design/Scaffolding/Metadata/Internal/DatabaseColumnExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq; diff --git a/src/EFCore.Design/Scaffolding/Metadata/Internal/DatabaseForeignKeyExtensions.cs b/src/EFCore.Design/Scaffolding/Metadata/Internal/DatabaseForeignKeyExtensions.cs index 4d8a476ced5..808ae435b46 100644 --- a/src/EFCore.Design/Scaffolding/Metadata/Internal/DatabaseForeignKeyExtensions.cs +++ b/src/EFCore.Design/Scaffolding/Metadata/Internal/DatabaseForeignKeyExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq; diff --git a/src/EFCore.Design/Scaffolding/Metadata/Internal/DatabaseTableExtensions.cs b/src/EFCore.Design/Scaffolding/Metadata/Internal/DatabaseTableExtensions.cs index 69739d50b69..048cef1f1b0 100644 --- a/src/EFCore.Design/Scaffolding/Metadata/Internal/DatabaseTableExtensions.cs +++ b/src/EFCore.Design/Scaffolding/Metadata/Internal/DatabaseTableExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Design/Scaffolding/ModelCodeGenerationOptions.cs b/src/EFCore.Design/Scaffolding/ModelCodeGenerationOptions.cs index 19161cc8f50..0472df26887 100644 --- a/src/EFCore.Design/Scaffolding/ModelCodeGenerationOptions.cs +++ b/src/EFCore.Design/Scaffolding/ModelCodeGenerationOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; @@ -23,7 +23,7 @@ public class ModelCodeGenerationOptions public virtual bool SuppressConnectionStringWarning { get; set; } /// - /// Gets or sets the namespace of the project. + /// Gets or sets the namespace of the project. /// /// The namespace of the project. public virtual string RootNamespace { get; [param: CanBeNull] set; } @@ -35,7 +35,7 @@ public class ModelCodeGenerationOptions public virtual string ModelNamespace { get; [param: CanBeNull] set; } /// - /// Gets or sets the namespace for context class. + /// Gets or sets the namespace for context class. /// /// The namespace for context class. public virtual string ContextNamespace { get; [param: CanBeNull] set; } diff --git a/src/EFCore.Design/Scaffolding/ModelCodeGeneratorDependencies.cs b/src/EFCore.Design/Scaffolding/ModelCodeGeneratorDependencies.cs index d81ec15d060..fd082781cc9 100644 --- a/src/EFCore.Design/Scaffolding/ModelCodeGeneratorDependencies.cs +++ b/src/EFCore.Design/Scaffolding/ModelCodeGeneratorDependencies.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.Infrastructure; diff --git a/src/EFCore.Design/Scaffolding/ModelReverseEngineerOptions.cs b/src/EFCore.Design/Scaffolding/ModelReverseEngineerOptions.cs index b71464f90d2..5d15c60383b 100644 --- a/src/EFCore.Design/Scaffolding/ModelReverseEngineerOptions.cs +++ b/src/EFCore.Design/Scaffolding/ModelReverseEngineerOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. namespace Microsoft.EntityFrameworkCore.Scaffolding diff --git a/src/EFCore.Design/Scaffolding/ScaffoldedFile.cs b/src/EFCore.Design/Scaffolding/ScaffoldedFile.cs index d8e0e650a91..0de071738a2 100644 --- a/src/EFCore.Design/Scaffolding/ScaffoldedFile.cs +++ b/src/EFCore.Design/Scaffolding/ScaffoldedFile.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Design/Scaffolding/ScaffoldedModel.cs b/src/EFCore.Design/Scaffolding/ScaffoldedModel.cs index 2799b2cc985..d8041c17e43 100644 --- a/src/EFCore.Design/Scaffolding/ScaffoldedModel.cs +++ b/src/EFCore.Design/Scaffolding/ScaffoldedModel.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; diff --git a/src/EFCore.InMemory/Extensions/InMemoryServiceCollectionExtensions.cs b/src/EFCore.InMemory/Extensions/InMemoryServiceCollectionExtensions.cs index cf2094c0abd..68013dbe8af 100644 --- a/src/EFCore.InMemory/Extensions/InMemoryServiceCollectionExtensions.cs +++ b/src/EFCore.InMemory/Extensions/InMemoryServiceCollectionExtensions.cs @@ -34,7 +34,7 @@ public static class InMemoryServiceCollectionExtensions /// Calling this method is no longer necessary when building most applications, including those that /// use dependency injection in ASP.NET or elsewhere. /// It is only needed when building the internal service provider for use with - /// the method. + /// the method. /// This is not recommend other than for some advanced scenarios. /// /// @@ -61,7 +61,6 @@ public static IServiceCollection AddEntityFrameworkInMemoryDatabase([NotNull] th .TryAdd() .TryAdd() .TryAdd() - .TryAdd(p => p.GetService()) .TryAddProviderSpecificServices( b => b diff --git a/src/EFCore.InMemory/Infrastructure/Internal/IInMemorySingletonOptions.cs b/src/EFCore.InMemory/Infrastructure/Internal/IInMemorySingletonOptions.cs index 90db70615ed..68f86aa7221 100644 --- a/src/EFCore.InMemory/Infrastructure/Internal/IInMemorySingletonOptions.cs +++ b/src/EFCore.InMemory/Infrastructure/Internal/IInMemorySingletonOptions.cs @@ -15,10 +15,10 @@ namespace Microsoft.EntityFrameworkCore.InMemory.Infrastructure.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is and multiple registrations - /// are allowed. This means a single instance of each service is used by many + /// The service lifetime is and multiple registrations + /// are allowed. This means a single instance of each service is used by many /// instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public interface IInMemorySingletonOptions : ISingletonOptions diff --git a/src/EFCore.InMemory/Infrastructure/Internal/InMemorySingletonOptions.cs b/src/EFCore.InMemory/Infrastructure/Internal/InMemorySingletonOptions.cs index fa74c921922..df96c116fbf 100644 --- a/src/EFCore.InMemory/Infrastructure/Internal/InMemorySingletonOptions.cs +++ b/src/EFCore.InMemory/Infrastructure/Internal/InMemorySingletonOptions.cs @@ -17,10 +17,10 @@ namespace Microsoft.EntityFrameworkCore.InMemory.Infrastructure.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is and multiple registrations - /// are allowed. This means a single instance of each service is used by many + /// The service lifetime is and multiple registrations + /// are allowed. This means a single instance of each service is used by many /// instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public class InMemorySingletonOptions : IInMemorySingletonOptions diff --git a/src/EFCore.InMemory/Metadata/Conventions/InMemoryConventionSetBuilder.cs b/src/EFCore.InMemory/Metadata/Conventions/InMemoryConventionSetBuilder.cs index 060142d8a0d..5815af4899d 100644 --- a/src/EFCore.InMemory/Metadata/Conventions/InMemoryConventionSetBuilder.cs +++ b/src/EFCore.InMemory/Metadata/Conventions/InMemoryConventionSetBuilder.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -14,8 +14,8 @@ namespace Microsoft.EntityFrameworkCore.InMemory.Metadata.Conventions /// A builder for building conventions for th in-memory provider. /// /// - /// The service lifetime is and multiple registrations - /// are allowed. This means that each instance will use its own + /// The service lifetime is and multiple registrations + /// are allowed. This means that each instance will use its own /// set of instances of this service. /// The implementations may depend on other services registered with any lifetime. /// The implementations do not need to be thread-safe. @@ -24,7 +24,7 @@ namespace Microsoft.EntityFrameworkCore.InMemory.Metadata.Conventions public class InMemoryConventionSetBuilder : ProviderConventionSetBuilder { /// - /// Creates a new instance. + /// Creates a new instance. /// /// The core dependencies for this service. public InMemoryConventionSetBuilder( @@ -35,12 +35,12 @@ public InMemoryConventionSetBuilder( /// /// - /// Call this method to build a for the in-memory provider when using - /// the outside of . + /// Call this method to build a for the in-memory provider when using + /// the outside of . /// /// /// Note that it is unusual to use this method. - /// Consider using in the normal way instead. + /// Consider using in the normal way instead. /// /// /// The convention set. @@ -48,9 +48,10 @@ public static ConventionSet Build() { var serviceProvider = new ServiceCollection() .AddEntityFrameworkInMemoryDatabase() - .AddDbContext((p, o) => - o.UseInMemoryDatabase(Guid.NewGuid().ToString()) - .UseInternalServiceProvider(p)) + .AddDbContext( + (p, o) => + o.UseInMemoryDatabase(Guid.NewGuid().ToString()) + .UseInternalServiceProvider(p)) .BuildServiceProvider(); using (var serviceScope = serviceProvider.GetRequiredService().CreateScope()) diff --git a/src/EFCore.InMemory/Query/Internal/EntityProjectionExpression.cs b/src/EFCore.InMemory/Query/Internal/EntityProjectionExpression.cs index e82b8bff9ed..a6c45d45b11 100644 --- a/src/EFCore.InMemory/Query/Internal/EntityProjectionExpression.cs +++ b/src/EFCore.InMemory/Query/Internal/EntityProjectionExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs index 796a422445d..e2b588a1ad7 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -31,6 +31,7 @@ public InMemoryExpressionTranslatingExpressionVisitor( private class EntityProjectionFindingExpressionVisitor : ExpressionVisitor { private bool _found; + public bool Find(Expression expression) { _found = false; @@ -171,35 +172,33 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp ? result : Expression.Convert(result, methodCallExpression.Type); } - else - { - var selector = (LambdaExpression)selectMethod.Arguments[1]; - var readValueExpression = ((NewArrayExpression)((NewExpression)selector.Body).Arguments[0]).Expressions[0]; - if (readValueExpression is UnaryExpression unaryExpression2 - && unaryExpression2.NodeType == ExpressionType.Convert - && unaryExpression2.Type == typeof(object)) - { - readValueExpression = unaryExpression2.Operand; - } - var valueBufferVariable = Expression.Variable(typeof(ValueBuffer)); - var replacedReadExpression = ReplacingExpressionVisitor.Replace( - selector.Parameters[0], - valueBufferVariable, - readValueExpression); - - replacedReadExpression = replacedReadExpression.Type == methodCallExpression.Type - ? replacedReadExpression - : Expression.Convert(replacedReadExpression, methodCallExpression.Type); - - return Expression.Block( - variables: new[] { valueBufferVariable }, - Expression.Assign(valueBufferVariable, resultFunc), - Expression.Condition( - Expression.MakeMemberAccess(valueBufferVariable, _valueBufferIsEmpty), - Expression.Default(methodCallExpression.Type), - replacedReadExpression)); + var selector = (LambdaExpression)selectMethod.Arguments[1]; + var readValueExpression = ((NewArrayExpression)((NewExpression)selector.Body).Arguments[0]).Expressions[0]; + if (readValueExpression is UnaryExpression unaryExpression2 + && unaryExpression2.NodeType == ExpressionType.Convert + && unaryExpression2.Type == typeof(object)) + { + readValueExpression = unaryExpression2.Operand; } + + var valueBufferVariable = Expression.Variable(typeof(ValueBuffer)); + var replacedReadExpression = ReplacingExpressionVisitor.Replace( + selector.Parameters[0], + valueBufferVariable, + readValueExpression); + + replacedReadExpression = replacedReadExpression.Type == methodCallExpression.Type + ? replacedReadExpression + : Expression.Convert(replacedReadExpression, methodCallExpression.Type); + + return Expression.Block( + variables: new[] { valueBufferVariable }, + Expression.Assign(valueBufferVariable, resultFunc), + Expression.Condition( + Expression.MakeMemberAccess(valueBufferVariable, _valueBufferIsEmpty), + Expression.Default(methodCallExpression.Type), + replacedReadExpression)); } // MethodCall translators @@ -217,6 +216,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp { return null; } + arguments[i] = argument; } @@ -330,7 +330,7 @@ protected override Expression VisitUnary(UnaryExpression unaryExpression) result = innerUnary.Operand; } else if (outerMostType == typeof(object) - && intermediateType == innerMostType.UnwrapNullableType()) + && intermediateType == innerMostType.UnwrapNullableType()) { result = Expression.Convert(innerUnary.Operand, typeof(object)); } @@ -343,5 +343,4 @@ protected override Expression VisitUnary(UnaryExpression unaryExpression) private bool TranslationFailed(Expression original, Expression translation) => original != null && (translation == null || translation is EntityProjectionExpression); } - } diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryLinqOperatorProvider.cs b/src/EFCore.InMemory/Query/Internal/InMemoryLinqOperatorProvider.cs index 1123e91f34f..99ce89ff482 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryLinqOperatorProvider.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryLinqOperatorProvider.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -20,14 +20,17 @@ private static IEnumerable GetMethods(string name, int parameterCoun public static MethodInfo Where = GetMethods(nameof(Enumerable.Where), 1) .Single(mi => mi.GetParameters()[1].ParameterType.GetGenericArguments().Length == 2); + public static MethodInfo Select = GetMethods(nameof(Enumerable.Select), 1) .Single(mi => mi.GetParameters()[1].ParameterType.GetGenericArguments().Length == 2); public static MethodInfo Join = GetMethod(nameof(Enumerable.Join), 4); public static MethodInfo GroupJoin = GetMethod(nameof(Enumerable.GroupJoin), 4); public static MethodInfo DefaultIfEmptyWithArg = GetMethod(nameof(Enumerable.DefaultIfEmpty), 1); + public static MethodInfo SelectMany = GetMethods(nameof(Enumerable.SelectMany), 2) .Single(mi => mi.GetParameters()[1].ParameterType.GetGenericArguments().Length == 2); + public static MethodInfo Contains = GetMethod(nameof(Enumerable.Contains), 1); public static MethodInfo OrderBy = GetMethod(nameof(Enumerable.OrderBy), 1); @@ -67,5 +70,4 @@ public static MethodInfo GetAggregateMethod(string methodName, Type elementType, // .MakeGenericMethod(elementType); } } - } diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryProjectionBindingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryProjectionBindingExpressionVisitor.cs index d3978ca5590..a055b118071 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryProjectionBindingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryProjectionBindingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -19,8 +19,10 @@ public class InMemoryProjectionBindingExpressionVisitor : ExpressionVisitor private InMemoryQueryExpression _queryExpression; private bool _clientEval; + private readonly IDictionary _projectionMapping = new Dictionary(); + private readonly Stack _projectionMembers = new Stack(); public InMemoryProjectionBindingExpressionVisitor( @@ -92,7 +94,8 @@ public override Expression Visit(Expression expression) return new ProjectionBindingExpression( _queryExpression, _queryExpression.AddToProjection(translated), - typeof(IEnumerable<>).MakeGenericType(materializeCollectionNavigationExpression.Navigation.GetTargetType().ClrType)); + typeof(IEnumerable<>).MakeGenericType( + materializeCollectionNavigationExpression.Navigation.GetTargetType().ClrType)); case MethodCallExpression methodCallExpression: { @@ -123,7 +126,6 @@ public override Expression Visit(Expression expression) } } - var translation = _expressionTranslatingExpressionVisitor.Translate(expression); return translation == null ? base.Visit(expression) @@ -141,7 +143,6 @@ public override Expression Visit(Expression expression) return new ProjectionBindingExpression(_queryExpression, _projectionMembers.Peek(), expression.Type); } - } return base.Visit(expression); @@ -162,14 +163,12 @@ protected override Expression VisitExtension(Expression extensionExpression) return entityShaperExpression.Update( new ProjectionBindingExpression(_queryExpression, _queryExpression.AddToProjection(entityProjection))); } - else - { - _projectionMapping[_projectionMembers.Peek()] - = _queryExpression.GetMappedProjection(projectionBindingExpression.ProjectionMember); - return entityShaperExpression.Update( - new ProjectionBindingExpression(_queryExpression, _projectionMembers.Peek(), typeof(ValueBuffer))); - } + _projectionMapping[_projectionMembers.Peek()] + = _queryExpression.GetMappedProjection(projectionBindingExpression.ProjectionMember); + + return entityShaperExpression.Update( + new ProjectionBindingExpression(_queryExpression, _projectionMembers.Peek(), typeof(ValueBuffer))); } if (extensionExpression is IncludeExpression includeExpression) @@ -211,6 +210,7 @@ protected override Expression VisitNew(NewExpression newExpression) { return null; } + _projectionMembers.Pop(); } } diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryQueryContext.cs b/src/EFCore.InMemory/Query/Internal/InMemoryQueryContext.cs index 6b6484eca47..037dbeb34b7 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryQueryContext.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryQueryContext.cs @@ -21,7 +21,8 @@ public class InMemoryQueryContext : QueryContext /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public InMemoryQueryContext([NotNull] QueryContextDependencies dependencies, + public InMemoryQueryContext( + [NotNull] QueryContextDependencies dependencies, [NotNull] IInMemoryStore store) : base(dependencies) => Store = store; diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryQueryContextFactory.cs b/src/EFCore.InMemory/Query/Internal/InMemoryQueryContextFactory.cs index 2a8686d1bd6..4bb6a3b5944 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryQueryContextFactory.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryQueryContextFactory.cs @@ -17,8 +17,8 @@ namespace Microsoft.EntityFrameworkCore.InMemory.Query.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs b/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs index 7f95e137800..c63375dc45a 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -23,6 +23,7 @@ private static readonly ConstructorInfo _valueBufferConstructor private IDictionary _projectionMapping = new Dictionary(); public virtual IReadOnlyList Projection => _valueBufferSlots; + private readonly IDictionary> _entityProjectionCache = new Dictionary>(); @@ -77,7 +78,8 @@ void IDisposable.Dispose() } } - private static readonly PropertyInfo _valueBufferCountMemberInfo = typeof(ValueBuffer).GetTypeInfo().GetProperty(nameof(ValueBuffer.Count)); + private static readonly PropertyInfo _valueBufferCountMemberInfo = + typeof(ValueBuffer).GetTypeInfo().GetProperty(nameof(ValueBuffer.Count)); public InMemoryQueryExpression(IEntityType entityType) { @@ -94,7 +96,8 @@ public InMemoryQueryExpression(IEntityType entityType) readExpressionMap[property] = Condition( LessThan( Constant(property.GetIndex()), - MakeMemberAccess(ValueBufferParameter, + MakeMemberAccess( + ValueBufferParameter, _valueBufferCountMemberInfo)), CreateReadValueExpression(typeof(object), property.GetIndex(), property), Default(typeof(object))); @@ -127,11 +130,11 @@ public virtual void ConvertToEnumerable() } ServerQueryExpression = New( - typeof(ResultEnumerable).GetConstructors().Single(), - Lambda>( - New( - _valueBufferConstructor, - NewArrayInit(typeof(object), new[] { ServerQueryExpression })))); + typeof(ResultEnumerable).GetConstructors().Single(), + Lambda>( + New( + _valueBufferConstructor, + NewArrayInit(typeof(object), ServerQueryExpression)))); } else { @@ -194,6 +197,7 @@ public virtual void ApplyPendingSelector() var index = AddToProjection(entityProjection.BindProperty(property)); map[property] = CreateReadValueExpression(property.ClrType, index, property); } + result[keyValuePair.Key] = new EntityProjectionExpression(entityProjection.EntityType, map); } else @@ -260,6 +264,7 @@ public virtual void ApplyServerProjection() { map[property] = AddToProjection(entityProjection.BindProperty(property)); } + result[keyValuePair.Key] = Constant(map); } else @@ -312,11 +317,10 @@ public virtual void AddInnerJoin( var resultValueBufferExpressions = new List(); var projectionMapping = new Dictionary(); var replacingVisitor = new ReplacingExpressionVisitor( - new Dictionary - { - { ValueBufferParameter, outerParameter }, - { innerQueryExpression.ValueBufferParameter, innerParameter } - }); + new Dictionary + { + { ValueBufferParameter, outerParameter }, { innerQueryExpression.ValueBufferParameter, innerParameter } + }); var index = 0; var outerMemberInfo = transparentIdentifierType.GetTypeInfo().GetDeclaredField("Outer"); @@ -330,6 +334,7 @@ public virtual void AddInnerJoin( resultValueBufferExpressions.Add(replacingVisitor.Visit(entityProjection.BindProperty(property))); readExpressionMap[property] = CreateReadValueExpression(property.ClrType, index++, property); } + projectionMapping[projection.Key.Prepend(outerMemberInfo)] = new EntityProjectionExpression(entityProjection.EntityType, readExpressionMap); } @@ -352,6 +357,7 @@ public virtual void AddInnerJoin( resultValueBufferExpressions.Add(replacingVisitor.Visit(entityProjection.BindProperty(property))); readExpressionMap[property] = CreateReadValueExpression(property.ClrType, index++, property); } + projectionMapping[projection.Key.Prepend(innerMemberInfo)] = new EntityProjectionExpression(entityProjection.EntityType, readExpressionMap); } @@ -402,8 +408,7 @@ public virtual void AddLeftJoin( var resultSelector = Lambda( New( groupTransparentIdentifierType.GetTypeInfo().DeclaredConstructors.Single(), - new[] { outerParameter, innerParameter }, - new[] { outerMemberInfo, innerMemberInfo }), + new[] { outerParameter, innerParameter }, outerMemberInfo, innerMemberInfo), outerParameter, innerParameter); @@ -425,11 +430,11 @@ public virtual void AddLeftJoin( var resultValueBufferExpressions = new List(); var projectionMapping = new Dictionary(); var replacingVisitor = new ReplacingExpressionVisitor( - new Dictionary - { - { ValueBufferParameter, MakeMemberAccess(outerParameter, outerMemberInfo) }, - { innerQueryExpression.ValueBufferParameter, innerParameter } - }); + new Dictionary + { + { ValueBufferParameter, MakeMemberAccess(outerParameter, outerMemberInfo) }, + { innerQueryExpression.ValueBufferParameter, innerParameter } + }); var index = 0; outerMemberInfo = transparentIdentifierType.GetTypeInfo().GetDeclaredField("Outer"); @@ -444,6 +449,7 @@ public virtual void AddLeftJoin( resultValueBufferExpressions.Add(replacedExpression); readExpressionMap[property] = CreateReadValueExpression(replacedExpression.Type, index++, property); } + projectionMapping[projection.Key.Prepend(outerMemberInfo)] = new EntityProjectionExpression(entityProjection.EntityType, readExpressionMap); } @@ -471,6 +477,7 @@ public virtual void AddLeftJoin( resultValueBufferExpressions.Add(replacedExpression); readExpressionMap[property] = CreateReadValueExpression(replacedExpression.Type, index++, property); } + projectionMapping[projection.Key.Prepend(innerMemberInfo)] = new EntityProjectionExpression(entityProjection.EntityType, readExpressionMap); } @@ -523,11 +530,10 @@ public virtual void AddCrossJoin(InMemoryQueryExpression innerQueryExpression, T var resultValueBufferExpressions = new List(); var projectionMapping = new Dictionary(); var replacingVisitor = new ReplacingExpressionVisitor( - new Dictionary - { - { ValueBufferParameter, outerParameter }, - { innerQueryExpression.ValueBufferParameter, innerParameter } - }); + new Dictionary + { + { ValueBufferParameter, outerParameter }, { innerQueryExpression.ValueBufferParameter, innerParameter } + }); var index = 0; var outerMemberInfo = transparentIdentifierType.GetTypeInfo().GetDeclaredField("Outer"); @@ -541,6 +547,7 @@ public virtual void AddCrossJoin(InMemoryQueryExpression innerQueryExpression, T resultValueBufferExpressions.Add(replacingVisitor.Visit(entityProjection.BindProperty(property))); readExpressionMap[property] = CreateReadValueExpression(property.ClrType, index++, property); } + projectionMapping[projection.Key.Prepend(outerMemberInfo)] = new EntityProjectionExpression(entityProjection.EntityType, readExpressionMap); } @@ -563,6 +570,7 @@ public virtual void AddCrossJoin(InMemoryQueryExpression innerQueryExpression, T resultValueBufferExpressions.Add(replacingVisitor.Visit(entityProjection.BindProperty(property))); readExpressionMap[property] = CreateReadValueExpression(property.ClrType, index++, property); } + projectionMapping[projection.Key.Prepend(innerMemberInfo)] = new EntityProjectionExpression(entityProjection.EntityType, readExpressionMap); } diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryQueryTranslationPostprocessor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryQueryTranslationPostprocessor.cs index 4de35d5ebe5..9fb2c89adec 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryQueryTranslationPostprocessor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryQueryTranslationPostprocessor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq.Expressions; diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryQueryTranslationPostprocessorFactory.cs b/src/EFCore.InMemory/Query/Internal/InMemoryQueryTranslationPostprocessorFactory.cs index b0c93128773..8c1208ef35b 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryQueryTranslationPostprocessorFactory.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryQueryTranslationPostprocessorFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.Query; diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs index 2323108142e..911d2bc2d81 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -105,7 +105,8 @@ protected override ShapedQueryExpression TranslateCast(ShapedQueryExpression sou return source; } - protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression source1, ShapedQueryExpression source2) => throw new NotImplementedException(); + protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression source1, ShapedQueryExpression source2) => + throw new NotImplementedException(); protected override ShapedQueryExpression TranslateContains(ShapedQueryExpression source, Expression item) { @@ -120,7 +121,8 @@ protected override ShapedQueryExpression TranslateContains(ShapedQueryExpression InMemoryLinqOperatorProvider.Select.MakeGenericMethod(typeof(ValueBuffer), item.Type), inMemoryQueryExpression.ServerQueryExpression, Expression.Lambda( - inMemoryQueryExpression.GetMappedProjection(new ProjectionMember()), inMemoryQueryExpression.ValueBufferParameter)), + inMemoryQueryExpression.GetMappedProjection(new ProjectionMember()), + inMemoryQueryExpression.ValueBufferParameter)), item); source.ShaperExpression = inMemoryQueryExpression.GetSingleScalarProjection(); @@ -169,13 +171,15 @@ protected override ShapedQueryExpression TranslateDistinct(ShapedQueryExpression return source; } - protected override ShapedQueryExpression TranslateElementAtOrDefault(ShapedQueryExpression source, Expression index, bool returnDefault) + protected override ShapedQueryExpression TranslateElementAtOrDefault( + ShapedQueryExpression source, Expression index, bool returnDefault) => null; protected override ShapedQueryExpression TranslateExcept(ShapedQueryExpression source1, ShapedQueryExpression source2) => null; - protected override ShapedQueryExpression TranslateFirstOrDefault(ShapedQueryExpression source, LambdaExpression predicate, Type returnType, bool returnDefault) + protected override ShapedQueryExpression TranslateFirstOrDefault( + ShapedQueryExpression source, LambdaExpression predicate, Type returnType, bool returnDefault) { return TranslateSingleResultOperator( source, @@ -186,16 +190,21 @@ protected override ShapedQueryExpression TranslateFirstOrDefault(ShapedQueryExpr : InMemoryLinqOperatorProvider.FirstPredicate); } - protected override ShapedQueryExpression TranslateGroupBy(ShapedQueryExpression source, LambdaExpression keySelector, LambdaExpression elementSelector, LambdaExpression resultSelector) + protected override ShapedQueryExpression TranslateGroupBy( + ShapedQueryExpression source, LambdaExpression keySelector, LambdaExpression elementSelector, LambdaExpression resultSelector) => null; - protected override ShapedQueryExpression TranslateGroupJoin(ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, LambdaExpression resultSelector) + protected override ShapedQueryExpression TranslateGroupJoin( + ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, + LambdaExpression resultSelector) => null; protected override ShapedQueryExpression TranslateIntersect(ShapedQueryExpression source1, ShapedQueryExpression source2) => null; - protected override ShapedQueryExpression TranslateJoin(ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, LambdaExpression resultSelector) + protected override ShapedQueryExpression TranslateJoin( + ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, + LambdaExpression resultSelector) { outerKeySelector = TranslateLambdaExpression(outer, outerKeySelector); innerKeySelector = TranslateLambdaExpression(inner, innerKeySelector); @@ -217,7 +226,8 @@ protected override ShapedQueryExpression TranslateJoin(ShapedQueryExpression out transparentIdentifierType); } - protected override ShapedQueryExpression TranslateLastOrDefault(ShapedQueryExpression source, LambdaExpression predicate, Type returnType, bool returnDefault) + protected override ShapedQueryExpression TranslateLastOrDefault( + ShapedQueryExpression source, LambdaExpression predicate, Type returnType, bool returnDefault) { return TranslateSingleResultOperator( source, @@ -228,7 +238,9 @@ protected override ShapedQueryExpression TranslateLastOrDefault(ShapedQueryExpre : InMemoryLinqOperatorProvider.LastPredicate); } - protected override ShapedQueryExpression TranslateLeftJoin(ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, LambdaExpression resultSelector) + protected override ShapedQueryExpression TranslateLeftJoin( + ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, + LambdaExpression resultSelector) { outerKeySelector = TranslateLambdaExpression(outer, outerKeySelector); innerKeySelector = TranslateLambdaExpression(inner, innerKeySelector); @@ -284,7 +296,8 @@ protected override ShapedQueryExpression TranslateMin(ShapedQueryExpression sour protected override ShapedQueryExpression TranslateOfType(ShapedQueryExpression source, Type resultType) => null; - protected override ShapedQueryExpression TranslateOrderBy(ShapedQueryExpression source, LambdaExpression keySelector, bool ascending) + protected override ShapedQueryExpression TranslateOrderBy( + ShapedQueryExpression source, LambdaExpression keySelector, bool ascending) { var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression; @@ -293,7 +306,7 @@ protected override ShapedQueryExpression TranslateOrderBy(ShapedQueryExpression inMemoryQueryExpression.ServerQueryExpression = Expression.Call( (ascending ? InMemoryLinqOperatorProvider.OrderBy : InMemoryLinqOperatorProvider.OrderByDescending) - .MakeGenericMethod(typeof(ValueBuffer), keySelector.ReturnType), + .MakeGenericMethod(typeof(ValueBuffer), keySelector.ReturnType), inMemoryQueryExpression.ServerQueryExpression, keySelector); @@ -336,32 +349,31 @@ protected override ShapedQueryExpression TranslateSelectMany( collectionSelectorBody = collectionEndingMethod.Arguments[0]; } - var correlated = new CorrelationFindingExpressionVisitor().IsCorrelated(collectionSelectorBody, collectionSelector.Parameters[0]); + var correlated = new CorrelationFindingExpressionVisitor().IsCorrelated( + collectionSelectorBody, collectionSelector.Parameters[0]); if (correlated) { // TODO visit inner with outer parameter; // See #17236 - throw new InvalidOperationException(CoreStrings.TranslationFailed( - collectionSelector.Print() + "; " + resultSelector.Print())); - + throw new InvalidOperationException( + CoreStrings.TranslationFailed( + collectionSelector.Print() + "; " + resultSelector.Print())); } - else + + if (Visit(collectionSelectorBody) is ShapedQueryExpression inner) { - if (Visit(collectionSelectorBody) is ShapedQueryExpression inner) - { - var transparentIdentifierType = TransparentIdentifierFactory.Create( - resultSelector.Parameters[0].Type, - resultSelector.Parameters[1].Type); - - ((InMemoryQueryExpression)source.QueryExpression).AddCrossJoin( - (InMemoryQueryExpression)inner.QueryExpression, transparentIdentifierType); - - return TranslateResultSelectorForJoin( - source, - resultSelector, - inner.ShaperExpression, - transparentIdentifierType); - } + var transparentIdentifierType = TransparentIdentifierFactory.Create( + resultSelector.Parameters[0].Type, + resultSelector.Parameters[1].Type); + + ((InMemoryQueryExpression)source.QueryExpression).AddCrossJoin( + (InMemoryQueryExpression)inner.QueryExpression, transparentIdentifierType); + + return TranslateResultSelectorForJoin( + source, + resultSelector, + inner.ShaperExpression, + transparentIdentifierType); } return null; @@ -371,6 +383,7 @@ private class CorrelationFindingExpressionVisitor : ExpressionVisitor { private ParameterExpression _outerParameter; private bool _isCorrelated; + public bool IsCorrelated(Expression tree, ParameterExpression outerParameter) { _isCorrelated = false; @@ -395,7 +408,8 @@ protected override Expression VisitParameter(ParameterExpression parameterExpres protected override ShapedQueryExpression TranslateSelectMany(ShapedQueryExpression source, LambdaExpression selector) => null; - protected override ShapedQueryExpression TranslateSingleOrDefault(ShapedQueryExpression source, LambdaExpression predicate, Type returnType, bool returnDefault) + protected override ShapedQueryExpression TranslateSingleOrDefault( + ShapedQueryExpression source, LambdaExpression predicate, Type returnType, bool returnDefault) { return TranslateSingleResultOperator( source, @@ -450,7 +464,7 @@ protected override ShapedQueryExpression TranslateThenBy(ShapedQueryExpression s inMemoryQueryExpression.ServerQueryExpression = Expression.Call( (ascending ? InMemoryLinqOperatorProvider.ThenBy : InMemoryLinqOperatorProvider.ThenByDescending) - .MakeGenericMethod(typeof(ValueBuffer), keySelector.ReturnType), + .MakeGenericMethod(typeof(ValueBuffer), keySelector.ReturnType), inMemoryQueryExpression.ServerQueryExpression, keySelector); @@ -482,7 +496,8 @@ private LambdaExpression TranslateLambdaExpression( var lambdaBody = ReplacingExpressionVisitor.Replace( lambdaExpression.Parameters.Single(), shapedQueryExpression.ShaperExpression, lambdaExpression.Body); - return Expression.Lambda(TranslateExpression(lambdaBody), + return Expression.Lambda( + TranslateExpression(lambdaBody), ((InMemoryQueryExpression)shapedQueryExpression.QueryExpression).ValueBufferParameter); } @@ -492,7 +507,7 @@ private ShapedQueryExpression TranslateScalarAggregate( var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression; selector = selector == null - || selector.Body == selector.Parameters[0] + || selector.Body == selector.Parameters[0] ? Expression.Lambda( inMemoryQueryExpression.GetMappedProjection(new ProjectionMember()), inMemoryQueryExpression.ValueBufferParameter) @@ -500,11 +515,11 @@ private ShapedQueryExpression TranslateScalarAggregate( inMemoryQueryExpression.ServerQueryExpression = Expression.Call( - InMemoryLinqOperatorProvider - .GetAggregateMethod(methodName, selector.ReturnType, parameterCount: 1) - .MakeGenericMethod(typeof(ValueBuffer)), - inMemoryQueryExpression.ServerQueryExpression, - selector); + InMemoryLinqOperatorProvider + .GetAggregateMethod(methodName, selector.ReturnType, parameterCount: 1) + .MakeGenericMethod(typeof(ValueBuffer)), + inMemoryQueryExpression.ServerQueryExpression, + selector); source.ShaperExpression = inMemoryQueryExpression.GetSingleScalarProjection(); diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitorFactory.cs b/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitorFactory.cs index 05eb6f8713e..c97f6520f3d 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitorFactory.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitorFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.CustomShaperCompilingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.CustomShaperCompilingExpressionVisitor.cs index b62b854557c..aae852ab5e9 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.CustomShaperCompilingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.CustomShaperCompilingExpressionVisitor.cs @@ -188,7 +188,6 @@ private static LambdaExpression GenerateFixup( inverseNavigation.IsCollection() ? AddToCollectionNavigation(relatedEntityParameter, entityParameter, inverseNavigation) : AssignReferenceNavigation(relatedEntityParameter, entityParameter, inverseNavigation)); - } return Expression.Lambda(Expression.Block(typeof(void), expressions), entityParameter, relatedEntityParameter); diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.InMemoryProjectionBindingRemovingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.InMemoryProjectionBindingRemovingExpressionVisitor.cs index 614b01f0b2b..65005090f0d 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.InMemoryProjectionBindingRemovingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.InMemoryProjectionBindingRemovingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.QueryingEnumerable.cs b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.QueryingEnumerable.cs index 5d5cdaaea61..22873738574 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.QueryingEnumerable.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.QueryingEnumerable.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.cs index 8c0a6c587c9..a65b8d2153e 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryExpressionVisitorFactory.cs b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryExpressionVisitorFactory.cs index 9d4cfa45bc8..da199a92852 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryExpressionVisitorFactory.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryExpressionVisitorFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.Query; @@ -17,5 +17,4 @@ public InMemoryShapedQueryCompilingExpressionVisitorFactory(ShapedQueryCompiling public virtual ShapedQueryCompilingExpressionVisitor Create(QueryCompilationContext queryCompilationContext) => new InMemoryShapedQueryCompilingExpressionVisitor(_dependencies, queryCompilationContext); } - } diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryTableExpression.cs b/src/EFCore.InMemory/Query/Internal/InMemoryTableExpression.cs index 07f37fb029c..9abdb313e71 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryTableExpression.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryTableExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -27,5 +27,4 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) return this; } } - } diff --git a/src/EFCore.InMemory/Query/Internal/ShaperExpressionProcessingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/ShaperExpressionProcessingExpressionVisitor.cs index 000bf5d72dc..7915584538f 100644 --- a/src/EFCore.InMemory/Query/Internal/ShaperExpressionProcessingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/ShaperExpressionProcessingExpressionVisitor.cs @@ -28,8 +28,9 @@ public virtual Expression Inject(Expression expression) if (_expressions.All(e => e.NodeType == ExpressionType.Assign)) { - result = new ReplacingExpressionVisitor(_expressions.Cast() - .ToDictionary(e => e.Left, e => e.Right)).Visit(result); + result = new ReplacingExpressionVisitor( + _expressions.Cast() + .ToDictionary(e => e.Left, e => e.Right)).Visit(result); } else { diff --git a/src/EFCore.InMemory/Storage/Internal/IInMemoryDatabase.cs b/src/EFCore.InMemory/Storage/Internal/IInMemoryDatabase.cs index 6969c373623..76fbec53062 100644 --- a/src/EFCore.InMemory/Storage/Internal/IInMemoryDatabase.cs +++ b/src/EFCore.InMemory/Storage/Internal/IInMemoryDatabase.cs @@ -14,8 +14,8 @@ namespace Microsoft.EntityFrameworkCore.InMemory.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.InMemory/Storage/Internal/InMemoryDatabase.cs b/src/EFCore.InMemory/Storage/Internal/InMemoryDatabase.cs index 75725150a1b..19d6e50395b 100644 --- a/src/EFCore.InMemory/Storage/Internal/InMemoryDatabase.cs +++ b/src/EFCore.InMemory/Storage/Internal/InMemoryDatabase.cs @@ -22,8 +22,8 @@ namespace Microsoft.EntityFrameworkCore.InMemory.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.InMemory/Storage/Internal/InMemoryDatabaseCreator.cs b/src/EFCore.InMemory/Storage/Internal/InMemoryDatabaseCreator.cs index 1ec74324311..e3b4a7fa2e3 100644 --- a/src/EFCore.InMemory/Storage/Internal/InMemoryDatabaseCreator.cs +++ b/src/EFCore.InMemory/Storage/Internal/InMemoryDatabaseCreator.cs @@ -18,8 +18,8 @@ namespace Microsoft.EntityFrameworkCore.InMemory.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.InMemory/Storage/Internal/InMemoryTable.cs b/src/EFCore.InMemory/Storage/Internal/InMemoryTable.cs index 0c786610b3f..569262075d8 100644 --- a/src/EFCore.InMemory/Storage/Internal/InMemoryTable.cs +++ b/src/EFCore.InMemory/Storage/Internal/InMemoryTable.cs @@ -8,6 +8,7 @@ using System.Linq; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.ChangeTracking; +using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; using Microsoft.EntityFrameworkCore.InMemory.Internal; using Microsoft.EntityFrameworkCore.InMemory.ValueGeneration.Internal; using Microsoft.EntityFrameworkCore.Metadata; @@ -25,7 +26,7 @@ namespace Microsoft.EntityFrameworkCore.InMemory.Storage.Internal public class InMemoryTable : IInMemoryTable { // WARNING: The in-memory provider is using EF internal code here. This should not be copied by other providers. See #15096 - private readonly ChangeTracking.Internal.IPrincipalKeyValueFactory _keyValueFactory; + private readonly IPrincipalKeyValueFactory _keyValueFactory; private readonly bool _sensitiveLoggingEnabled; private readonly Dictionary _rows; @@ -39,7 +40,7 @@ public class InMemoryTable : IInMemoryTable /// public InMemoryTable( // WARNING: The in-memory provider is using EF internal code here. This should not be copied by other providers. See #15096 - [NotNull] ChangeTracking.Internal.IPrincipalKeyValueFactory keyValueFactory, + [NotNull] IPrincipalKeyValueFactory keyValueFactory, bool sensitiveLoggingEnabled) { _keyValueFactory = keyValueFactory; @@ -217,7 +218,7 @@ private void BumpValueGenerators(object[] row) // WARNING: The in-memory provider is using EF internal code here. This should not be copied by other providers. See #15096 private TKey CreateKey(IUpdateEntry entry) - => _keyValueFactory.CreateFromCurrentValues((ChangeTracking.Internal.InternalEntityEntry)entry); + => _keyValueFactory.CreateFromCurrentValues((InternalEntityEntry)entry); private static object SnapshotValue(IProperty property, ValueComparer comparer, IUpdateEntry entry) => SnapshotValue(comparer, entry.GetCurrentValue(property)); @@ -230,7 +231,8 @@ private static object SnapshotValue(ValueComparer comparer, object value) /// /// The update entry which resulted in the conflict(s). /// The conflicting properties with their associated database values. - protected virtual void ThrowUpdateConcurrencyException([NotNull] IUpdateEntry entry, [NotNull] Dictionary concurrencyConflicts) + protected virtual void ThrowUpdateConcurrencyException( + [NotNull] IUpdateEntry entry, [NotNull] Dictionary concurrencyConflicts) { Check.NotNull(entry, nameof(entry)); Check.NotNull(concurrencyConflicts, nameof(concurrencyConflicts)); @@ -242,7 +244,11 @@ protected virtual void ThrowUpdateConcurrencyException([NotNull] IUpdateEntry en entry.EntityType.DisplayName(), entry.BuildCurrentValuesString(entry.EntityType.FindPrimaryKey().Properties), entry.BuildOriginalValuesString(concurrencyConflicts.Keys), - "{" + string.Join(", ", concurrencyConflicts.Select(c => c.Key.Name + ": " + Convert.ToString(c.Value, CultureInfo.InvariantCulture))) + "}"), + "{" + string.Join( + ", ", + concurrencyConflicts.Select( + c => c.Key.Name + ": " + Convert.ToString(c.Value, CultureInfo.InvariantCulture))) + + "}"), new[] { entry }); } diff --git a/src/EFCore.InMemory/Storage/Internal/InMemoryTableFactory.cs b/src/EFCore.InMemory/Storage/Internal/InMemoryTableFactory.cs index d3b3c29af9b..3ce6ca92ae2 100644 --- a/src/EFCore.InMemory/Storage/Internal/InMemoryTableFactory.cs +++ b/src/EFCore.InMemory/Storage/Internal/InMemoryTableFactory.cs @@ -5,6 +5,7 @@ using System.Collections.Concurrent; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Utilities; @@ -19,7 +20,7 @@ namespace Microsoft.EntityFrameworkCore.InMemory.Storage.Internal /// public class InMemoryTableFactory // WARNING: The in-memory provider is using EF internal code here. This should not be copied by other providers. See #15096 - : ChangeTracking.Internal.IdentityMapFactoryFactoryBase, IInMemoryTableFactory + : IdentityMapFactoryFactoryBase, IInMemoryTableFactory { private readonly bool _sensitiveLoggingEnabled; diff --git a/src/EFCore.InMemory/Storage/Internal/InMemoryTransactionManager.cs b/src/EFCore.InMemory/Storage/Internal/InMemoryTransactionManager.cs index e8d13937caa..d865d3487cf 100644 --- a/src/EFCore.InMemory/Storage/Internal/InMemoryTransactionManager.cs +++ b/src/EFCore.InMemory/Storage/Internal/InMemoryTransactionManager.cs @@ -21,8 +21,8 @@ namespace Microsoft.EntityFrameworkCore.InMemory.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.InMemory/Storage/Internal/InMemoryTypeMapping.cs b/src/EFCore.InMemory/Storage/Internal/InMemoryTypeMapping.cs index bb00fe53a3d..14ab259b8cf 100644 --- a/src/EFCore.InMemory/Storage/Internal/InMemoryTypeMapping.cs +++ b/src/EFCore.InMemory/Storage/Internal/InMemoryTypeMapping.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -34,8 +34,7 @@ public InMemoryTypeMapping( converter: null, comparer, keyComparer, - structuralComparer, - valueGeneratorFactory: null)) + structuralComparer)) { } diff --git a/src/EFCore.InMemory/Storage/Internal/InMemoryTypeMappingSource.cs b/src/EFCore.InMemory/Storage/Internal/InMemoryTypeMappingSource.cs index 0159af82638..a21e7a7c6ee 100644 --- a/src/EFCore.InMemory/Storage/Internal/InMemoryTypeMappingSource.cs +++ b/src/EFCore.InMemory/Storage/Internal/InMemoryTypeMappingSource.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -19,9 +19,9 @@ namespace Microsoft.EntityFrameworkCore.InMemory.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class InMemoryTypeMappingSource : TypeMappingSource diff --git a/src/EFCore.InMemory/ValueGeneration/Internal/InMemoryValueGeneratorSelector.cs b/src/EFCore.InMemory/ValueGeneration/Internal/InMemoryValueGeneratorSelector.cs index 307cdeb0d24..175a22a006f 100644 --- a/src/EFCore.InMemory/ValueGeneration/Internal/InMemoryValueGeneratorSelector.cs +++ b/src/EFCore.InMemory/ValueGeneration/Internal/InMemoryValueGeneratorSelector.cs @@ -20,8 +20,8 @@ namespace Microsoft.EntityFrameworkCore.InMemory.ValueGeneration.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Proxies/Proxies/Internal/ProxiesConventionSetPlugin.cs b/src/EFCore.Proxies/Proxies/Internal/ProxiesConventionSetPlugin.cs index 2a0f7eb9650..20a0a1c1af4 100644 --- a/src/EFCore.Proxies/Proxies/Internal/ProxiesConventionSetPlugin.cs +++ b/src/EFCore.Proxies/Proxies/Internal/ProxiesConventionSetPlugin.cs @@ -18,8 +18,8 @@ namespace Microsoft.EntityFrameworkCore.Proxies.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is and multiple registrations - /// are allowed. This means that each instance will use its own + /// The service lifetime is and multiple registrations + /// are allowed. This means that each instance will use its own /// set of instances of this service. /// The implementations may depend on other services registered with any lifetime. /// The implementations do not need to be thread-safe. diff --git a/src/EFCore.Proxies/Proxies/Internal/ProxyBindingRewriter.cs b/src/EFCore.Proxies/Proxies/Internal/ProxyBindingRewriter.cs index 34ecac697d3..87afd943839 100644 --- a/src/EFCore.Proxies/Proxies/Internal/ProxyBindingRewriter.cs +++ b/src/EFCore.Proxies/Proxies/Internal/ProxyBindingRewriter.cs @@ -85,11 +85,12 @@ public virtual void ProcessModelFinalized(IConventionModelBuilder modelBuilder, { serviceProperty = entityType.AddServiceProperty(_lazyLoaderProperty); serviceProperty.SetParameterBinding( - (ServiceParameterBinding)new LazyLoaderParameterBindingFactory(_lazyLoaderParameterBindingFactoryDependencies) + (ServiceParameterBinding)new LazyLoaderParameterBindingFactory( + _lazyLoaderParameterBindingFactoryDependencies) .Bind( - entityType, - typeof(ILazyLoader), - nameof(IProxyLazyLoader.LazyLoader))); + entityType, + typeof(ILazyLoader), + nameof(IProxyLazyLoader.LazyLoader))); } // WARNING: This code is EF internal; it should not be copied. See #10789 #14554 diff --git a/src/EFCore.Relational/Design/AnnotationCodeGenerator.cs b/src/EFCore.Relational/Design/AnnotationCodeGenerator.cs index 1218d81a033..3b8c0231532 100644 --- a/src/EFCore.Relational/Design/AnnotationCodeGenerator.cs +++ b/src/EFCore.Relational/Design/AnnotationCodeGenerator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Relational/Design/AnnotationCodeGeneratorDependencies.cs b/src/EFCore.Relational/Design/AnnotationCodeGeneratorDependencies.cs index f2fc01dc66b..7638de44317 100644 --- a/src/EFCore.Relational/Design/AnnotationCodeGeneratorDependencies.cs +++ b/src/EFCore.Relational/Design/AnnotationCodeGeneratorDependencies.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.Infrastructure; diff --git a/src/EFCore.Relational/Design/IAnnotationCodeGenerator.cs b/src/EFCore.Relational/Design/IAnnotationCodeGenerator.cs index 95e1e74ee12..3d1f01105c0 100644 --- a/src/EFCore.Relational/Design/IAnnotationCodeGenerator.cs +++ b/src/EFCore.Relational/Design/IAnnotationCodeGenerator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Relational/Design/MethodCallCodeFragment.cs b/src/EFCore.Relational/Design/MethodCallCodeFragment.cs index 91687dc4493..2dc86438887 100644 --- a/src/EFCore.Relational/Design/MethodCallCodeFragment.cs +++ b/src/EFCore.Relational/Design/MethodCallCodeFragment.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; diff --git a/src/EFCore.Relational/Design/NestedClosureCodeFragment.cs b/src/EFCore.Relational/Design/NestedClosureCodeFragment.cs index 599ea3cc114..fe25877ee34 100644 --- a/src/EFCore.Relational/Design/NestedClosureCodeFragment.cs +++ b/src/EFCore.Relational/Design/NestedClosureCodeFragment.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Relational/Diagnostics/CommandCorrelatedEventData.cs b/src/EFCore.Relational/Diagnostics/CommandCorrelatedEventData.cs index 9b50ee59e61..563ebab5347 100644 --- a/src/EFCore.Relational/Diagnostics/CommandCorrelatedEventData.cs +++ b/src/EFCore.Relational/Diagnostics/CommandCorrelatedEventData.cs @@ -9,7 +9,7 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics { /// - /// The event payload for events correlated with a . + /// The event payload for events correlated with a . /// public class CommandCorrelatedEventData : DbContextEventData { @@ -18,7 +18,7 @@ public class CommandCorrelatedEventData : DbContextEventData /// /// The event definition. /// A delegate that generates a log message for this event. - /// The being used. + /// The being used. /// The currently being used, to null if not known. /// The method. /// A correlation ID that identifies the instance being used. diff --git a/src/EFCore.Relational/Diagnostics/CommandEndEventData.cs b/src/EFCore.Relational/Diagnostics/CommandEndEventData.cs index 0983148fd2d..6007aaf1e42 100644 --- a/src/EFCore.Relational/Diagnostics/CommandEndEventData.cs +++ b/src/EFCore.Relational/Diagnostics/CommandEndEventData.cs @@ -19,7 +19,7 @@ public class CommandEndEventData : CommandEventData /// /// The event definition. /// A delegate that generates a log message for this event. - /// The being used. + /// The being used. /// The . /// The currently being used, to null if not known. /// The method. diff --git a/src/EFCore.Relational/Diagnostics/CommandErrorEventData.cs b/src/EFCore.Relational/Diagnostics/CommandErrorEventData.cs index 1016bd65ee2..ec69f1ef48a 100644 --- a/src/EFCore.Relational/Diagnostics/CommandErrorEventData.cs +++ b/src/EFCore.Relational/Diagnostics/CommandErrorEventData.cs @@ -18,7 +18,7 @@ public class CommandErrorEventData : CommandEndEventData, IErrorEventData /// /// The event definition. /// A delegate that generates a log message for this event. - /// The being used. + /// The being used. /// The that was executing when it failed. /// The currently being used, to null if not known. /// The method that was used to execute the command. diff --git a/src/EFCore.Relational/Diagnostics/CommandEventData.cs b/src/EFCore.Relational/Diagnostics/CommandEventData.cs index 1b9bb9fda9b..7d82ea6aa01 100644 --- a/src/EFCore.Relational/Diagnostics/CommandEventData.cs +++ b/src/EFCore.Relational/Diagnostics/CommandEventData.cs @@ -19,7 +19,7 @@ public class CommandEventData : CommandCorrelatedEventData /// /// The event definition. /// A delegate that generates a log message for this event. - /// The being used. + /// The being used. /// The . /// The currently being used, to null if not known. /// The method. diff --git a/src/EFCore.Relational/Diagnostics/CommandExecutedEventData.cs b/src/EFCore.Relational/Diagnostics/CommandExecutedEventData.cs index 7eaf143a5ed..3347cc85862 100644 --- a/src/EFCore.Relational/Diagnostics/CommandExecutedEventData.cs +++ b/src/EFCore.Relational/Diagnostics/CommandExecutedEventData.cs @@ -18,7 +18,7 @@ public class CommandExecutedEventData : CommandEndEventData /// /// The event definition. /// A delegate that generates a log message for this event. - /// The being used. + /// The being used. /// The that was executing when it failed. /// The currently being used, to null if not known. /// The method that was used to execute the command. diff --git a/src/EFCore.Relational/Diagnostics/DbCommandInterceptor.cs b/src/EFCore.Relational/Diagnostics/DbCommandInterceptor.cs index 4fb959494f8..bd307b005ec 100644 --- a/src/EFCore.Relational/Diagnostics/DbCommandInterceptor.cs +++ b/src/EFCore.Relational/Diagnostics/DbCommandInterceptor.cs @@ -16,31 +16,33 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics public abstract class DbCommandInterceptor : IDbCommandInterceptor { /// - /// Called just before EF intends to call . + /// Called just before EF intends to call . /// /// Contextual information about the command and execution. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation it + /// was about to perform and use instead. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in. /// - public virtual InterceptionResult CommandCreating(CommandCorrelatedEventData eventData, InterceptionResult result) + public virtual InterceptionResult CommandCreating( + CommandCorrelatedEventData eventData, InterceptionResult result) => result; /// /// - /// Called immediately after EF calls . + /// Called immediately after EF calls . /// /// - /// This method is still called if an interceptor suppressed creation of a command in . + /// This method is still called if an interceptor suppressed creation of a command in + /// . /// In this case, is the result returned by . /// /// @@ -64,14 +66,14 @@ public virtual DbCommand CommandCreated(CommandEndEventData eventData, DbCommand /// Contextual information about the command and execution. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation it + /// was about to perform and use instead. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in, often using /// @@ -88,14 +90,14 @@ public virtual InterceptionResult ReaderExecuting( /// Contextual information about the command and execution. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation it + /// was about to perform and use instead. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in, often using /// @@ -112,14 +114,14 @@ public virtual InterceptionResult ScalarExecuting( /// Contextual information about the command and execution. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation it + /// was about to perform and use instead. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in, often using /// @@ -136,15 +138,15 @@ public virtual InterceptionResult NonQueryExecuting( /// Contextual information about the command and execution. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// The cancellation token. /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation it + /// was about to perform and use instead. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in, often using /// @@ -162,15 +164,15 @@ public virtual Task> ReaderExecutingAsync( /// Contextual information about the command and execution. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// The cancellation token. /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation it + /// was about to perform and use instead. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in, often using /// @@ -188,15 +190,15 @@ public virtual Task> ScalarExecutingAsync( /// Contextual information about the command and execution. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// The cancellation token. /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation it + /// was about to perform and use instead. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in, often using /// @@ -386,7 +388,7 @@ public virtual void CommandFailed( /// The command. /// Contextual information about the command and execution. /// The cancellation token. - /// A representing the asynchronous operation. + /// A representing the asynchronous operation. public virtual Task CommandFailedAsync( DbCommand command, CommandErrorEventData eventData, @@ -394,19 +396,19 @@ public virtual Task CommandFailedAsync( => Task.CompletedTask; /// - /// Called when execution of a is about to be disposed. />. + /// Called when execution of a is about to be disposed. />. /// /// The command. /// Contextual information about the command and reader. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation /// it was about to perform. /// A normal implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. diff --git a/src/EFCore.Relational/Diagnostics/DbConnectionInterceptor.cs b/src/EFCore.Relational/Diagnostics/DbConnectionInterceptor.cs index 1657ed921ab..22328842d6c 100644 --- a/src/EFCore.Relational/Diagnostics/DbConnectionInterceptor.cs +++ b/src/EFCore.Relational/Diagnostics/DbConnectionInterceptor.cs @@ -22,13 +22,13 @@ public abstract class DbConnectionInterceptor : IDbConnectionInterceptor /// Contextual information about the connection. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation /// it was about to perform. /// A normal implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -46,14 +46,14 @@ public virtual InterceptionResult ConnectionOpening( /// Contextual information about the connection. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// The cancellation token. /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation /// it was about to perform. /// A normal implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -80,7 +80,7 @@ public virtual void ConnectionOpened(DbConnection connection, ConnectionEndEvent /// The connection. /// Contextual information about the connection. /// The cancellation token. - /// A representing the asynchronous operation. + /// A representing the asynchronous operation. public virtual Task ConnectionOpenedAsync( DbConnection connection, ConnectionEndEventData eventData, @@ -94,13 +94,13 @@ public virtual Task ConnectionOpenedAsync( /// Contextual information about the connection. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation /// it was about to perform. /// A normal implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -118,13 +118,13 @@ public virtual InterceptionResult ConnectionClosing( /// Contextual information about the connection. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation /// it was about to perform. /// A normal implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -151,7 +151,7 @@ public virtual void ConnectionClosed( /// /// The connection. /// Contextual information about the connection. - /// A representing the asynchronous operation. + /// A representing the asynchronous operation. public virtual Task ConnectionClosedAsync( DbConnection connection, ConnectionEndEventData eventData) @@ -174,7 +174,7 @@ public virtual void ConnectionFailed( /// The connection. /// Contextual information about the connection. /// The cancellation token. - /// A representing the asynchronous operation. + /// A representing the asynchronous operation. public virtual Task ConnectionFailedAsync( DbConnection connection, ConnectionErrorEventData eventData, diff --git a/src/EFCore.Relational/Diagnostics/DbTransactionInterceptor.cs b/src/EFCore.Relational/Diagnostics/DbTransactionInterceptor.cs index e231bc47bee..02a815a1157 100644 --- a/src/EFCore.Relational/Diagnostics/DbTransactionInterceptor.cs +++ b/src/EFCore.Relational/Diagnostics/DbTransactionInterceptor.cs @@ -23,14 +23,14 @@ public abstract class DbTransactionInterceptor : IDbTransactionInterceptor /// Contextual information about connection and transaction. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation it + /// was about to perform and use instead. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in, often using /// @@ -73,15 +73,15 @@ public virtual DbTransaction TransactionStarted( /// Contextual information about connection and transaction. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// The cancellation token. /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation it + /// was about to perform and use instead. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in, often using /// @@ -169,13 +169,13 @@ public virtual Task TransactionUsedAsync( /// Contextual information about connection and transaction. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation /// it was about to perform. /// A normal implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -204,14 +204,14 @@ public virtual void TransactionCommitted( /// Contextual information about connection and transaction. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// The cancellation token. /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation /// it was about to perform. /// A normal implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -243,13 +243,13 @@ public virtual Task TransactionCommittedAsync( /// Contextual information about connection and transaction. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation /// it was about to perform. /// A normal implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -278,14 +278,14 @@ public virtual void TransactionRolledBack( /// Contextual information about connection and transaction. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// The cancellation token. /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation /// it was about to perform. /// A normal implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -311,7 +311,7 @@ public virtual Task TransactionRolledBackAsync( => Task.CompletedTask; /// - /// Called when use of a has failed with an exception. />. + /// Called when use of a has failed with an exception. />. /// /// The transaction. /// Contextual information about connection and transaction. @@ -322,12 +322,12 @@ public virtual void TransactionFailed( } /// - /// Called when use of a has failed with an exception. />. + /// Called when use of a has failed with an exception. />. /// /// The transaction. /// Contextual information about connection and transaction. /// The cancellation token. - /// A representing the asynchronous operation. + /// A representing the asynchronous operation. public virtual Task TransactionFailedAsync( DbTransaction transaction, TransactionErrorEventData eventData, diff --git a/src/EFCore.Relational/Diagnostics/IDbCommandInterceptor.cs b/src/EFCore.Relational/Diagnostics/IDbCommandInterceptor.cs index cf96351434b..502d2bcfc8e 100644 --- a/src/EFCore.Relational/Diagnostics/IDbCommandInterceptor.cs +++ b/src/EFCore.Relational/Diagnostics/IDbCommandInterceptor.cs @@ -32,19 +32,19 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics public interface IDbCommandInterceptor : IInterceptor { /// - /// Called just before EF intends to call . + /// Called just before EF intends to call . /// /// Contextual information about the command and execution. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation it + /// was about to perform and use instead. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in. /// @@ -54,7 +54,7 @@ InterceptionResult CommandCreating( /// /// - /// Called immediately after EF calls . + /// Called immediately after EF calls . /// /// /// This method is still called if an interceptor suppressed creation of a command in . @@ -82,14 +82,14 @@ DbCommand CommandCreated( /// Contextual information about the command and execution. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation it + /// was about to perform and use instead. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in. /// @@ -105,14 +105,14 @@ InterceptionResult ReaderExecuting( /// Contextual information about the command and execution. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation it + /// was about to perform and use instead. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in. /// @@ -128,14 +128,14 @@ InterceptionResult ScalarExecuting( /// Contextual information about the command and execution. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation it + /// was about to perform and use instead. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in. /// @@ -151,15 +151,15 @@ InterceptionResult NonQueryExecuting( /// Contextual information about the command and execution. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// The cancellation token. /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation it + /// was about to perform and use instead. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in, often using /// @@ -176,15 +176,15 @@ Task> ReaderExecutingAsync( /// Contextual information about the command and execution. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// The cancellation token. /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation it + /// was about to perform and use instead. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in, often using /// @@ -201,15 +201,15 @@ Task> ScalarExecutingAsync( /// Contextual information about the command and execution. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// The cancellation token. /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation it + /// was about to perform and use instead. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in, often using /// @@ -311,7 +311,7 @@ int NonQueryExecuted( /// /// The cancellation token. /// - /// A providing the result that EF will use. + /// A providing the result that EF will use. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in, often using /// @@ -338,7 +338,7 @@ Task ReaderExecutedAsync( /// /// The cancellation token. /// - /// A providing the result that EF will use. + /// A providing the result that EF will use. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in, often using /// @@ -365,7 +365,7 @@ Task ScalarExecutedAsync( /// /// The cancellation token. /// - /// A providing the result that EF will use. + /// A providing the result that EF will use. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in, often using /// @@ -390,26 +390,26 @@ void CommandFailed( /// The command. /// Contextual information about the command and execution. /// The cancellation token. - /// A representing the asynchronous operation. + /// A representing the asynchronous operation. Task CommandFailedAsync( [NotNull] DbCommand command, [NotNull] CommandErrorEventData eventData, CancellationToken cancellationToken = default); /// - /// Called when execution of a is about to be disposed. />. + /// Called when execution of a is about to be disposed. />. /// /// The command. /// Contextual information about the command and reader. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation /// it was about to perform. /// A normal implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. diff --git a/src/EFCore.Relational/Diagnostics/IDbConnectionInterceptor.cs b/src/EFCore.Relational/Diagnostics/IDbConnectionInterceptor.cs index 69bfbfc5575..2096bf14925 100644 --- a/src/EFCore.Relational/Diagnostics/IDbConnectionInterceptor.cs +++ b/src/EFCore.Relational/Diagnostics/IDbConnectionInterceptor.cs @@ -10,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics { /// /// - /// Allows interception of operations on . + /// Allows interception of operations on . /// /// /// Connection interceptors can be used to view, change, or suppress the operation on , and @@ -38,13 +38,13 @@ public interface IDbConnectionInterceptor : IInterceptor /// Contextual information about the connection. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation /// it was about to perform. /// A normal implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -61,14 +61,14 @@ InterceptionResult ConnectionOpening( /// Contextual information about the connection. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// The cancellation token. /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation /// it was about to perform. /// A normal implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -94,7 +94,7 @@ void ConnectionOpened( /// The connection. /// Contextual information about the connection. /// The cancellation token. - /// A representing the asynchronous operation. + /// A representing the asynchronous operation. Task ConnectionOpenedAsync( [NotNull] DbConnection connection, [NotNull] ConnectionEndEventData eventData, @@ -107,13 +107,13 @@ Task ConnectionOpenedAsync( /// Contextual information about the connection. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation /// it was about to perform. /// A normal implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -130,13 +130,13 @@ InterceptionResult ConnectionClosing( /// Contextual information about the connection. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation /// it was about to perform. /// A normal implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -160,7 +160,7 @@ void ConnectionClosed( /// /// The connection. /// Contextual information about the connection. - /// A representing the asynchronous operation. + /// A representing the asynchronous operation. Task ConnectionClosedAsync( [NotNull] DbConnection connection, [NotNull] ConnectionEndEventData eventData); @@ -180,7 +180,7 @@ void ConnectionFailed( /// The connection. /// Contextual information about the connection. /// The cancellation token. - /// A representing the asynchronous operation. + /// A representing the asynchronous operation. Task ConnectionFailedAsync( [NotNull] DbConnection connection, [NotNull] ConnectionErrorEventData eventData, diff --git a/src/EFCore.Relational/Diagnostics/IDbTransactionInterceptor.cs b/src/EFCore.Relational/Diagnostics/IDbTransactionInterceptor.cs index 262d2e72fb4..cde0de7552f 100644 --- a/src/EFCore.Relational/Diagnostics/IDbTransactionInterceptor.cs +++ b/src/EFCore.Relational/Diagnostics/IDbTransactionInterceptor.cs @@ -6,13 +6,12 @@ using System.Threading; using System.Threading.Tasks; using JetBrains.Annotations; -using Microsoft.EntityFrameworkCore.Infrastructure; namespace Microsoft.EntityFrameworkCore.Diagnostics { /// /// - /// Allows interception of operations related to a . + /// Allows interception of operations related to a . /// /// /// Transaction interceptors can be used to view, change, or suppress operations on , and @@ -40,14 +39,14 @@ public interface IDbTransactionInterceptor : IInterceptor /// Contextual information about connection and transaction. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation it + /// was about to perform and use instead. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in, often using /// @@ -88,15 +87,15 @@ DbTransaction TransactionStarted( /// Contextual information about connection and transaction. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// The cancellation token. /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation it - /// was about to perform and use instead. + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation it + /// was about to perform and use instead. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in, often using /// @@ -123,7 +122,7 @@ Task> TransactionStartingAsync( /// /// The cancellation token. /// - /// A providing the result that EF will use. + /// A providing the result that EF will use. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in, often using /// @@ -141,7 +140,7 @@ Task TransactionStartedAsync( /// The connection. /// Contextual information about connection and transaction. /// - /// The that was passed to . + /// The that was passed to . /// This value is typically used as the return value for the implementation of this method. /// /// @@ -162,12 +161,12 @@ DbTransaction TransactionUsed( /// The connection. /// Contextual information about connection and transaction. /// - /// The that was passed to . + /// The that was passed to . /// This value is typically used as the return value for the implementation of this method. /// /// The cancellation token. /// - /// A containing the value that will be used as the effective value passed + /// A containing the value that will be used as the effective value passed /// to /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the value passed in, often using @@ -185,13 +184,13 @@ Task TransactionUsedAsync( /// Contextual information about connection and transaction. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation /// it was about to perform. /// A normal implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -217,14 +216,14 @@ void TransactionCommitted( /// Contextual information about connection and transaction. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// The cancellation token. /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation /// it was about to perform. /// A normal implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -241,7 +240,7 @@ Task TransactionCommittingAsync( /// The transaction. /// Contextual information about connection and transaction. /// The cancellation token. - /// A representing the asynchronous operation. + /// A representing the asynchronous operation. Task TransactionCommittedAsync( [NotNull] DbTransaction transaction, [NotNull] TransactionEndEventData eventData, @@ -254,13 +253,13 @@ Task TransactionCommittedAsync( /// Contextual information about connection and transaction. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation /// it was about to perform. /// A normal implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -286,14 +285,14 @@ void TransactionRolledBack( /// Contextual information about connection and transaction. /// /// Represents the current result if one exists. - /// This value will have set to true if some previous - /// interceptor suppressed execution by calling . + /// This value will have set to true if some previous + /// interceptor suppressed execution by calling . /// This value is typically used as the return value for the implementation of this method. /// /// The cancellation token. /// - /// If is false, the EF will continue as normal. - /// If is true, then EF will suppress the operation + /// If is false, the EF will continue as normal. + /// If is true, then EF will suppress the operation /// it was about to perform. /// A normal implementation of this method for any interceptor that is not attempting to suppress /// the operation is to return the value passed in. @@ -310,14 +309,14 @@ Task TransactionRollingBackAsync( /// The transaction. /// Contextual information about connection and transaction. /// The cancellation token. - /// A representing the asynchronous operation. + /// A representing the asynchronous operation. Task TransactionRolledBackAsync( [NotNull] DbTransaction transaction, [NotNull] TransactionEndEventData eventData, CancellationToken cancellationToken = default); /// - /// Called when use of a has failed with an exception. />. + /// Called when use of a has failed with an exception. />. /// /// The transaction. /// Contextual information about connection and transaction. @@ -326,12 +325,12 @@ void TransactionFailed( [NotNull] TransactionErrorEventData eventData); /// - /// Called when use of a has failed with an exception. />. + /// Called when use of a has failed with an exception. />. /// /// The transaction. /// Contextual information about connection and transaction. /// The cancellation token. - /// A representing the asynchronous operation. + /// A representing the asynchronous operation. Task TransactionFailedAsync( [NotNull] DbTransaction transaction, [NotNull] TransactionErrorEventData eventData, diff --git a/src/EFCore.Relational/Diagnostics/MigrationAssemblyEventData.cs b/src/EFCore.Relational/Diagnostics/MigrationAssemblyEventData.cs index 7595b1c0fc1..a6d953d8cc0 100644 --- a/src/EFCore.Relational/Diagnostics/MigrationAssemblyEventData.cs +++ b/src/EFCore.Relational/Diagnostics/MigrationAssemblyEventData.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Relational/Diagnostics/RelationalEventId.cs b/src/EFCore.Relational/Diagnostics/RelationalEventId.cs index b9aa1ea731b..4e5e507ce03 100644 --- a/src/EFCore.Relational/Diagnostics/RelationalEventId.cs +++ b/src/EFCore.Relational/Diagnostics/RelationalEventId.cs @@ -155,7 +155,7 @@ private enum Id /// /// - /// A is being created. + /// A is being created. /// /// /// This event is in the category. @@ -168,7 +168,7 @@ private enum Id /// /// - /// A has been created. + /// A has been created. /// /// /// This event is in the category. @@ -522,7 +522,8 @@ private enum Id /// This event uses the payload when used with a . /// /// - public static readonly EventId QueryPossibleUnintendedUseOfEqualsWarning = MakeQueryId(Id.QueryPossibleUnintendedUseOfEqualsWarning); + public static readonly EventId QueryPossibleUnintendedUseOfEqualsWarning = + MakeQueryId(Id.QueryPossibleUnintendedUseOfEqualsWarning); /// /// @@ -532,7 +533,8 @@ private enum Id /// This event is in the category. /// /// - public static readonly EventId QueryPossibleExceptionWithAggregateOperatorWarning = MakeQueryId(Id.QueryPossibleExceptionWithAggregateOperatorWarning); + public static readonly EventId QueryPossibleExceptionWithAggregateOperatorWarning = + MakeQueryId(Id.QueryPossibleExceptionWithAggregateOperatorWarning); private static readonly string _validationPrefix = DbLoggerCategory.Model.Validation.Name + "."; private static EventId MakeValidationId(Id id) => new EventId((int)id, _validationPrefix + id); diff --git a/src/EFCore.Relational/Diagnostics/RelationalLoggerExtensions.cs b/src/EFCore.Relational/Diagnostics/RelationalLoggerExtensions.cs index 551d641b13f..4744dcb57b1 100644 --- a/src/EFCore.Relational/Diagnostics/RelationalLoggerExtensions.cs +++ b/src/EFCore.Relational/Diagnostics/RelationalLoggerExtensions.cs @@ -1160,7 +1160,7 @@ private static void LogCommandError( /// The time that execution began. /// The amount of time that passed until the exception was raised. /// The cancellation token. - /// A representing the async operation. + /// A representing the async operation. public static Task CommandErrorAsync( [NotNull] this IDiagnosticsLogger diagnostics, [NotNull] IRelationalConnection connection, @@ -1293,7 +1293,7 @@ public static InterceptionResult ConnectionOpening( if (interceptor != null) { - return interceptor.ConnectionOpening(connection.DbConnection, eventData,default); + return interceptor.ConnectionOpening(connection.DbConnection, eventData, default); } } @@ -1307,7 +1307,7 @@ public static InterceptionResult ConnectionOpening( /// The connection. /// The time that the operation was started. /// The cancellation token. - /// A representing the async operation. + /// A representing the async operation. public static Task ConnectionOpeningAsync( [NotNull] this IDiagnosticsLogger diagnostics, [NotNull] IRelationalConnection connection, @@ -1356,7 +1356,6 @@ private static void LogConnectionOpening( } } - private static ConnectionEventData BroadcastConnectionOpening( IDiagnosticsLogger diagnostics, IRelationalConnection connection, @@ -1435,7 +1434,7 @@ public static void ConnectionOpened( /// The time that the operation was started. /// The amount of time before the connection was opened. /// The cancellation token. - /// A representing the async operation. + /// A representing the async operation. public static Task ConnectionOpenedAsync( [NotNull] this IDiagnosticsLogger diagnostics, [NotNull] IRelationalConnection connection, @@ -1567,7 +1566,7 @@ public static InterceptionResult ConnectionClosing( /// The diagnostics logger to use. /// The connection. /// The time that the operation was started. - /// A representing the async operation. + /// A representing the async operation. public static Task ConnectionClosingAsync( [NotNull] this IDiagnosticsLogger diagnostics, [NotNull] IRelationalConnection connection, @@ -1692,7 +1691,7 @@ public static void ConnectionClosed( /// The connection. /// The time that the operation was started. /// The amount of time before the connection was closed. - /// A representing the async operation. + /// A representing the async operation. public static Task ConnectionClosedAsync( [NotNull] this IDiagnosticsLogger diagnostics, [NotNull] IRelationalConnection connection, @@ -1831,7 +1830,7 @@ public static void ConnectionError( /// The elapsed time before the operation failed. /// A flag indicating the exception is being handled and so it should be logged at Debug level. /// The cancellation token. - /// A representing the async operation. + /// A representing the async operation. public static Task ConnectionErrorAsync( [NotNull] this IDiagnosticsLogger diagnostics, [NotNull] IRelationalConnection connection, @@ -2047,7 +2046,7 @@ private static TransactionStartingEventData BroadcastTransactionStarting( private static void LogTransactionStarting( IDiagnosticsLogger diagnostics, - System.Data.IsolationLevel isolationLevel, + IsolationLevel isolationLevel, EventDefinition definition) { var warningBehavior = definition.GetLogBehavior(diagnostics); @@ -2415,7 +2414,7 @@ public static InterceptionResult TransactionCommitting( /// The correlation ID associated with the . /// The time that the operation was started. /// The cancellation token. - /// A representing the async operation. + /// A representing the async operation. public static Task TransactionCommittingAsync( [NotNull] this IDiagnosticsLogger diagnostics, [NotNull] IRelationalConnection connection, @@ -2544,7 +2543,7 @@ public static void TransactionCommitted( /// The time that the operation was started. /// The elapsed time from when the operation was started. /// The cancellation token. - /// A representing the async operation. + /// A representing the async operation. public static Task TransactionCommittedAsync( [NotNull] this IDiagnosticsLogger diagnostics, [NotNull] IRelationalConnection connection, @@ -2677,7 +2676,7 @@ public static void TransactionRolledBack( /// The time that the operation was started. /// The elapsed time from when the operation was started. /// The cancellation token. - /// A representing the async operation. + /// A representing the async operation. public static Task TransactionRolledBackAsync( [NotNull] this IDiagnosticsLogger diagnostics, [NotNull] IRelationalConnection connection, @@ -2735,7 +2734,7 @@ private static TransactionEndEventData BroadcastTransactionRolledBack( connection.Context, transactionId, connection.ConnectionId, - @async, + async, startTime, duration); @@ -2812,7 +2811,7 @@ public static InterceptionResult TransactionRollingBack( /// The correlation ID associated with the . /// The time that the operation was started. /// The cancellation token. - /// A representing the async operation. + /// A representing the async operation. public static Task TransactionRollingBackAsync( [NotNull] this IDiagnosticsLogger diagnostics, [NotNull] IRelationalConnection connection, @@ -2867,7 +2866,7 @@ private static TransactionEventData BroadcastTransactionRollingBack( connection.Context, transactionId, connection.ConnectionId, - @async, + async, startTime); if (diagnosticSourceEnabled) @@ -2988,7 +2987,7 @@ public static void TransactionError( /// The time that the operation was started. /// The elapsed time from when the operation was started. /// The cancellation token. - /// A representing the async operation. + /// A representing the async operation. public static Task TransactionErrorAsync( [NotNull] this IDiagnosticsLogger diagnostics, [NotNull] IRelationalConnection connection, diff --git a/src/EFCore.Relational/Diagnostics/RelationalLoggingDefinitions.cs b/src/EFCore.Relational/Diagnostics/RelationalLoggingDefinitions.cs index c70ebffc523..e561e55352a 100644 --- a/src/EFCore.Relational/Diagnostics/RelationalLoggingDefinitions.cs +++ b/src/EFCore.Relational/Diagnostics/RelationalLoggingDefinitions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.Infrastructure; diff --git a/src/EFCore.Relational/Diagnostics/TransactionEndEventData.cs b/src/EFCore.Relational/Diagnostics/TransactionEndEventData.cs index c53bf7c4515..621856dfc2f 100644 --- a/src/EFCore.Relational/Diagnostics/TransactionEndEventData.cs +++ b/src/EFCore.Relational/Diagnostics/TransactionEndEventData.cs @@ -20,7 +20,7 @@ public class TransactionEndEventData : TransactionEventData /// The event definition. /// A delegate that generates a log message for this event. /// The . - /// The currently being used, or null if not known. + /// The currently being used, or null if not known. /// A correlation ID that identifies the Entity Framework transaction being used. /// A correlation ID that identifies the instance being used. /// Indicates whether or not the transaction is being used asynchronously. diff --git a/src/EFCore.Relational/Diagnostics/TransactionEnlistedEventData.cs b/src/EFCore.Relational/Diagnostics/TransactionEnlistedEventData.cs index ac7f687afaf..0fc4b577151 100644 --- a/src/EFCore.Relational/Diagnostics/TransactionEnlistedEventData.cs +++ b/src/EFCore.Relational/Diagnostics/TransactionEnlistedEventData.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Relational/Diagnostics/TransactionErrorEventData.cs b/src/EFCore.Relational/Diagnostics/TransactionErrorEventData.cs index ed7047d2d52..5838191b96a 100644 --- a/src/EFCore.Relational/Diagnostics/TransactionErrorEventData.cs +++ b/src/EFCore.Relational/Diagnostics/TransactionErrorEventData.cs @@ -20,7 +20,7 @@ public class TransactionErrorEventData : TransactionEndEventData, IErrorEventDat /// The event definition. /// A delegate that generates a log message for this event. /// The . - /// The currently being used, or null if not known. + /// The currently being used, or null if not known. /// A correlation ID that identifies the Entity Framework transaction being used. /// A correlation ID that identifies the instance being used. /// Indicates whether or not the transaction is being used asynchronously. diff --git a/src/EFCore.Relational/Diagnostics/TransactionStartingEventData.cs b/src/EFCore.Relational/Diagnostics/TransactionStartingEventData.cs index 56f0cb37cb0..ce413dbbcf8 100644 --- a/src/EFCore.Relational/Diagnostics/TransactionStartingEventData.cs +++ b/src/EFCore.Relational/Diagnostics/TransactionStartingEventData.cs @@ -20,7 +20,7 @@ public class TransactionStartingEventData : DbContextEventData /// /// The event definition. /// A delegate that generates a log message for this event. - /// The currently in use, or null if not known. + /// The currently in use, or null if not known. /// The transaction isolation level. /// A correlation ID that identifies the Entity Framework transaction being used. /// A correlation ID that identifies the instance being used. @@ -45,7 +45,7 @@ public TransactionStartingEventData( } /// - /// The transaction isolation level. + /// The transaction isolation level. /// public virtual IsolationLevel IsolationLevel { get; } diff --git a/src/EFCore.Relational/Extensions/Internal/MethodInfoExtensions.cs b/src/EFCore.Relational/Extensions/Internal/MethodInfoExtensions.cs index 53959c3d61c..854265da170 100644 --- a/src/EFCore.Relational/Extensions/Internal/MethodInfoExtensions.cs +++ b/src/EFCore.Relational/Extensions/Internal/MethodInfoExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Reflection; diff --git a/src/EFCore.Relational/Extensions/RelationalDatabaseFacadeExtensions.cs b/src/EFCore.Relational/Extensions/RelationalDatabaseFacadeExtensions.cs index 9470ea9f4e0..b85fe09aa52 100644 --- a/src/EFCore.Relational/Extensions/RelationalDatabaseFacadeExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalDatabaseFacadeExtensions.cs @@ -773,7 +773,7 @@ public static IDbContextTransaction UseTransaction( /// The for the context. /// The to use. /// A token to observe while waiting for the task to complete. - /// A containing the for the given transaction. + /// A containing the for the given transaction. public static Task UseTransactionAsync( [NotNull] this DatabaseFacade databaseFacade, [CanBeNull] DbTransaction transaction, diff --git a/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs b/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs index 80b7f3c0d37..ecd03d40624 100644 --- a/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs @@ -415,7 +415,7 @@ public static IConventionEntityTypeBuilder HasCheckConstraint( if (constraint.Sql == sql) { ((CheckConstraint)constraint).UpdateConfigurationSource( - fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); + fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); return entityTypeBuilder; } @@ -533,6 +533,5 @@ public static bool CanSetComment( RelationalAnnotationNames.Comment, comment, fromDataAnnotation); - } } diff --git a/src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs b/src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs index 9217155db99..0bf18909b86 100644 --- a/src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs @@ -292,7 +292,7 @@ public static bool IsIgnoredByMigrations([NotNull] this IEntityType entityType) var viewDefinition = entityType.FindAnnotation(RelationalAnnotationNames.ViewDefinition); return (viewDefinition != null && viewDefinition.Value == null) - || entityType.GetDefiningQuery() != null; + || entityType.GetDefiningQuery() != null; } } } diff --git a/src/EFCore.Relational/Extensions/RelationalKeyExtensions.cs b/src/EFCore.Relational/Extensions/RelationalKeyExtensions.cs index e7581d6978b..8f50bbfe5c3 100644 --- a/src/EFCore.Relational/Extensions/RelationalKeyExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalKeyExtensions.cs @@ -6,7 +6,6 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; // ReSharper disable once CheckNamespace diff --git a/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs b/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs index d899ce962fc..113cd591cdd 100644 --- a/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reflection; diff --git a/src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs b/src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs index 08f2333fdd5..18a2192105d 100644 --- a/src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs @@ -463,10 +463,7 @@ public static IProperty FindSharedTableRootPrimaryKeyProperty([NotNull] this IPr if (visitedTypes == null) { - visitedTypes = new HashSet - { - linkingRelationship.DeclaringEntityType - }; + visitedTypes = new HashSet { linkingRelationship.DeclaringEntityType }; } if (!visitedTypes.Add(linkingRelationship.PrincipalEntityType)) @@ -519,6 +516,5 @@ public static void SetComment([NotNull] this IMutableProperty property, [CanBeNu public static void SetComment( [NotNull] this IConventionProperty property, [CanBeNull] string comment, bool fromDataAnnotation = false) => property.SetOrRemoveAnnotation(RelationalAnnotationNames.Comment, comment, fromDataAnnotation); - } } diff --git a/src/EFCore.Relational/Extensions/RelationalQueryableExtensions.cs b/src/EFCore.Relational/Extensions/RelationalQueryableExtensions.cs index a260da00004..7b76d3fd1ff 100644 --- a/src/EFCore.Relational/Extensions/RelationalQueryableExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalQueryableExtensions.cs @@ -6,7 +6,6 @@ using System.Linq.Expressions; using System.Reflection; using JetBrains.Annotations; -using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Utilities; @@ -56,7 +55,8 @@ internal static readonly MethodInfo FromSqlOnQueryableMethodInfo [StringFormatMethod("sql")] [Obsolete( "For returning objects from SQL queries using plain strings, use FromSqlRaw instead. " + - "For returning objects from SQL queries using interpolated string syntax to create parameters, use FromSqlInterpolated instead. " + + "For returning objects from SQL queries using interpolated string syntax to create parameters, use FromSqlInterpolated instead. " + + "Call either new method directly on the DbSet at the root of the query.", error: true)] public static IQueryable FromSql( @@ -101,7 +101,8 @@ public static IQueryable FromSql( /// An representing the interpolated string SQL query. [Obsolete( "For returning objects from SQL queries using plain strings, use FromSqlRaw instead. " + - "For returning objects from SQL queries using interpolated string syntax to create parameters, use FromSqlInterpolated instead. " + + "For returning objects from SQL queries using interpolated string syntax to create parameters, use FromSqlInterpolated instead. " + + "Call either new method directly on the DbSet at the root of the query.", error: true)] public static IQueryable FromSql( @@ -216,6 +217,6 @@ internal static IQueryable FromSqlOnQueryable( [NotParameterized] string sql, [NotNull] params object[] parameters) where TEntity : class - => throw new NotImplementedException(); + => throw new NotImplementedException(); } } diff --git a/src/EFCore.Relational/Infrastructure/IRelationalDbContextOptionsBuilderInfrastructure.cs b/src/EFCore.Relational/Infrastructure/IRelationalDbContextOptionsBuilderInfrastructure.cs index abb574f57ad..ffb2ba5a9ce 100644 --- a/src/EFCore.Relational/Infrastructure/IRelationalDbContextOptionsBuilderInfrastructure.cs +++ b/src/EFCore.Relational/Infrastructure/IRelationalDbContextOptionsBuilderInfrastructure.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. namespace Microsoft.EntityFrameworkCore.Infrastructure diff --git a/src/EFCore.Relational/Infrastructure/RelationalDbContextOptionsBuilder.cs b/src/EFCore.Relational/Infrastructure/RelationalDbContextOptionsBuilder.cs index 0ae25f53545..32f20e8a8e6 100644 --- a/src/EFCore.Relational/Infrastructure/RelationalDbContextOptionsBuilder.cs +++ b/src/EFCore.Relational/Infrastructure/RelationalDbContextOptionsBuilder.cs @@ -4,7 +4,6 @@ using System; using System.ComponentModel; using JetBrains.Annotations; -using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Utilities; diff --git a/src/EFCore.Relational/Infrastructure/RelationalModelCustomizer.cs b/src/EFCore.Relational/Infrastructure/RelationalModelCustomizer.cs index 1767977204b..57138aaae07 100644 --- a/src/EFCore.Relational/Infrastructure/RelationalModelCustomizer.cs +++ b/src/EFCore.Relational/Infrastructure/RelationalModelCustomizer.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; @@ -15,9 +15,9 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure /// not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class RelationalModelCustomizer : ModelCustomizer diff --git a/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs b/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs index 347f46b2003..4ecf4e383be 100644 --- a/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs +++ b/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -20,9 +20,9 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure /// The validator that enforces rules common for all relational providers. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class RelationalModelValidator : ModelValidator @@ -68,7 +68,8 @@ public override void Validate(IModel model, IDiagnosticsLogger /// The model to validate. /// The logger to use. - protected virtual void ValidateDbFunctions([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void ValidateDbFunctions( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { foreach (var dbFunction in model.GetDbFunctions()) { @@ -103,11 +104,12 @@ protected virtual void ValidateDbFunctions([NotNull] IModel model, [NotNull] IDi } /// - /// Validates the mapping/configuration of properties in the model. + /// Validates the mapping/configuration of properties in the model. /// /// The model to validate. /// The logger to use. - protected virtual void ValidateBoolsWithDefaults([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void ValidateBoolsWithDefaults( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { Check.NotNull(model, nameof(model)); @@ -132,7 +134,8 @@ private static bool IsNotNullAndFalse(object value) /// /// The model to validate. /// The logger to use. - protected virtual void ValidateDefaultValuesOnKeys([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void ValidateDefaultValuesOnKeys( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { foreach (var property in model.GetEntityTypes().SelectMany( t => t.GetDeclaredKeys().SelectMany(k => k.Properties)) @@ -184,7 +187,8 @@ protected virtual void ValidateSharedTableCompatibility( /// The table name. /// The logger to use. protected virtual void ValidateSharedTableCompatibility( - [NotNull] IReadOnlyList mappedTypes, [NotNull] string tableName, [NotNull] IDiagnosticsLogger logger) + [NotNull] IReadOnlyList mappedTypes, [NotNull] string tableName, + [NotNull] IDiagnosticsLogger logger) { if (mappedTypes.Count == 1) { @@ -197,10 +201,10 @@ protected virtual void ValidateSharedTableCompatibility( { if (mappedType.BaseType != null || (mappedType.FindPrimaryKey() != null && mappedType.FindForeignKeys(mappedType.FindPrimaryKey().Properties) - .Any( - fk => fk.PrincipalKey.IsPrimaryKey() - && fk.PrincipalEntityType.GetRootType() != mappedType - && unvalidatedTypes.Contains(fk.PrincipalEntityType)))) + .Any( + fk => fk.PrincipalKey.IsPrimaryKey() + && fk.PrincipalEntityType.GetRootType() != mappedType + && unvalidatedTypes.Contains(fk.PrincipalEntityType)))) { continue; } @@ -295,7 +299,8 @@ protected virtual void ValidateSharedTableCompatibility( private static bool IsIdentifyingPrincipal(IEntityType dependentEntityType, IEntityType principalEntityType) => dependentEntityType.FindForeignKeys(dependentEntityType.FindPrimaryKey().Properties) - .Any(fk => fk.PrincipalKey.IsPrimaryKey() + .Any( + fk => fk.PrincipalKey.IsPrimaryKey() && fk.PrincipalEntityType == principalEntityType); /// @@ -472,7 +477,8 @@ protected virtual void ValidateSharedColumnsCompatibility( /// The table name. /// The logger to use. protected virtual void ValidateSharedForeignKeysCompatibility( - [NotNull] IReadOnlyList mappedTypes, [NotNull] string tableName, [NotNull] IDiagnosticsLogger logger) + [NotNull] IReadOnlyList mappedTypes, [NotNull] string tableName, + [NotNull] IDiagnosticsLogger logger) { var foreignKeyMappings = new Dictionary(); @@ -496,7 +502,8 @@ protected virtual void ValidateSharedForeignKeysCompatibility( /// The table name. /// The logger to use. protected virtual void ValidateSharedIndexesCompatibility( - [NotNull] IReadOnlyList mappedTypes, [NotNull] string tableName, [NotNull] IDiagnosticsLogger logger) + [NotNull] IReadOnlyList mappedTypes, [NotNull] string tableName, + [NotNull] IDiagnosticsLogger logger) { var indexMappings = new Dictionary(); @@ -558,14 +565,15 @@ protected virtual void ValidateSharedKeysCompatibility( /// /// The model to validate. /// The logger to use. - protected virtual void ValidateInheritanceMapping([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void ValidateInheritanceMapping( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { foreach (var entityType in model.GetEntityTypes()) { if (entityType.BaseType != null && entityType[RelationalAnnotationNames.TableName] != null && ((EntityType)entityType).FindAnnotation(RelationalAnnotationNames.TableName).GetConfigurationSource() - == ConfigurationSource.Explicit) + == ConfigurationSource.Explicit) { throw new InvalidOperationException( RelationalStrings.DerivedTypeTable(entityType.DisplayName(), entityType.BaseType.DisplayName())); diff --git a/src/EFCore.Relational/Infrastructure/RelationalModelValidatorDependencies.cs b/src/EFCore.Relational/Infrastructure/RelationalModelValidatorDependencies.cs index a0acb96148d..13b4cb5664d 100644 --- a/src/EFCore.Relational/Infrastructure/RelationalModelValidatorDependencies.cs +++ b/src/EFCore.Relational/Infrastructure/RelationalModelValidatorDependencies.cs @@ -25,10 +25,10 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . - /// This means a single instance of each service is used by many instances. + /// The service lifetime is . + /// This means a single instance of each service is used by many instances. /// The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public sealed class RelationalModelValidatorDependencies diff --git a/src/EFCore.Relational/Infrastructure/RelationalOptionsExtension.cs b/src/EFCore.Relational/Infrastructure/RelationalOptionsExtension.cs index f0ddc14b698..9ff32159442 100644 --- a/src/EFCore.Relational/Infrastructure/RelationalOptionsExtension.cs +++ b/src/EFCore.Relational/Infrastructure/RelationalOptionsExtension.cs @@ -67,7 +67,7 @@ protected RelationalOptionsExtension([NotNull] RelationalOptionsExtension copyFr } /// - /// Information/metadata about the extension. + /// Information/metadata about the extension. /// public abstract DbContextOptionsExtensionInfo Info { get; } @@ -356,7 +356,7 @@ public virtual void Validate(IDbContextOptions options) } /// - /// Information/metadata for a . + /// Information/metadata for a . /// protected abstract class RelationalExtensionInfo : DbContextOptionsExtensionInfo { diff --git a/src/EFCore.Relational/Internal/IRelationalDatabaseFacadeDependencies.cs b/src/EFCore.Relational/Internal/IRelationalDatabaseFacadeDependencies.cs index 50a0462c029..8f7010a7608 100644 --- a/src/EFCore.Relational/Internal/IRelationalDatabaseFacadeDependencies.cs +++ b/src/EFCore.Relational/Internal/IRelationalDatabaseFacadeDependencies.cs @@ -14,8 +14,8 @@ namespace Microsoft.EntityFrameworkCore.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Relational/Metadata/Builders/DbFunctionBuilder.cs b/src/EFCore.Relational/Metadata/Builders/DbFunctionBuilder.cs index a15042090a9..79bbe0a5f19 100644 --- a/src/EFCore.Relational/Metadata/Builders/DbFunctionBuilder.cs +++ b/src/EFCore.Relational/Metadata/Builders/DbFunctionBuilder.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -7,12 +7,12 @@ using System.Linq; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Diagnostics; -using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.EntityFrameworkCore.Storage; +using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Builders { @@ -188,7 +188,7 @@ IConventionDbFunctionBuilder IConventionDbFunctionBuilder.HasTranslation( } /// - /// Creates a for a parameter with the given name. + /// Creates a for a parameter with the given name. /// /// The parameter name. /// The builder to use for further parameter configuration. diff --git a/src/EFCore.Relational/Metadata/Builders/DbFunctionParameterBuilder.cs b/src/EFCore.Relational/Metadata/Builders/DbFunctionParameterBuilder.cs index a76daba7e0b..f17c429d226 100644 --- a/src/EFCore.Relational/Metadata/Builders/DbFunctionParameterBuilder.cs +++ b/src/EFCore.Relational/Metadata/Builders/DbFunctionParameterBuilder.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.ComponentModel; @@ -71,10 +71,8 @@ IConventionDbFunctionParameterBuilder IConventionDbFunctionParameterBuilder.HasS /// bool IConventionDbFunctionParameterBuilder.CanSetStoreType(string storeType, bool fromDataAnnotation) - { - return Overrides(fromDataAnnotation, _parameter.GetStoreTypeConfigurationSource()) - || _parameter.StoreType == storeType; - } + => Overrides(fromDataAnnotation, _parameter.GetStoreTypeConfigurationSource()) + || _parameter.StoreType == storeType; /// IConventionDbFunctionParameterBuilder IConventionDbFunctionParameterBuilder.HasTypeMapping( @@ -91,10 +89,8 @@ IConventionDbFunctionParameterBuilder IConventionDbFunctionParameterBuilder.HasT /// bool IConventionDbFunctionParameterBuilder.CanSetTypeMapping(RelationalTypeMapping typeMapping, bool fromDataAnnotation) - { - return Overrides(fromDataAnnotation, _parameter.GetTypeMappingConfigurationSource()) - || _parameter.TypeMapping == typeMapping; - } + => Overrides(fromDataAnnotation, _parameter.GetTypeMappingConfigurationSource()) + || _parameter.TypeMapping == typeMapping; private bool Overrides(bool fromDataAnnotation, ConfigurationSource? configurationSource) => (fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention) diff --git a/src/EFCore.Relational/Metadata/Builders/IConventionDbFunctionParameterBuilder.cs b/src/EFCore.Relational/Metadata/Builders/IConventionDbFunctionParameterBuilder.cs index dd6681f15b2..8c3a04c8783 100644 --- a/src/EFCore.Relational/Metadata/Builders/IConventionDbFunctionParameterBuilder.cs +++ b/src/EFCore.Relational/Metadata/Builders/IConventionDbFunctionParameterBuilder.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Relational/Metadata/Conventions/DbFunctionTypeMappingConvention.cs b/src/EFCore.Relational/Metadata/Conventions/DbFunctionTypeMappingConvention.cs index 296e94e49de..bba5633a780 100644 --- a/src/EFCore.Relational/Metadata/Conventions/DbFunctionTypeMappingConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/DbFunctionTypeMappingConvention.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; @@ -10,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// - /// A convention configure type mapping for instances. + /// A convention configure type mapping for instances. /// public class DbFunctionTypeMappingConvention : IModelFinalizedConvention { diff --git a/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilder.cs b/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilder.cs index aef97f135e0..bc0d373f90f 100644 --- a/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilder.cs +++ b/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilder.cs @@ -59,7 +59,8 @@ public override ConventionSet CreateConventionSet() { var conventionSet = base.CreateConventionSet(); - ValueGenerationConvention valueGenerationConvention = new RelationalValueGenerationConvention(Dependencies, RelationalDependencies); + ValueGenerationConvention valueGenerationConvention = + new RelationalValueGenerationConvention(Dependencies, RelationalDependencies); ReplaceConvention(conventionSet.EntityTypeBaseTypeChangedConventions, valueGenerationConvention); ReplaceConvention(conventionSet.EntityTypePrimaryKeyChangedConventions, valueGenerationConvention); @@ -103,7 +104,8 @@ public override ConventionSet CreateConventionSet() ReplaceConvention( conventionSet.ModelFinalizedConventions, - (QueryFilterDefiningQueryRewritingConvention)new RelationalQueryFilterDefiningQueryRewritingConvention(Dependencies, RelationalDependencies)); + (QueryFilterDefiningQueryRewritingConvention)new RelationalQueryFilterDefiningQueryRewritingConvention( + Dependencies, RelationalDependencies)); return conventionSet; } diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalColumnAttributeConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalColumnAttributeConvention.cs index 7e301737fe9..a7275a67ae0 100644 --- a/src/EFCore.Relational/Metadata/Conventions/RelationalColumnAttributeConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/RelationalColumnAttributeConvention.cs @@ -10,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// - /// A convention that configures column name and type for a property based on the applied . + /// A convention that configures column name and type for a property based on the applied . /// public class RelationalColumnAttributeConvention : PropertyAttributeConventionBase { diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalDbFunctionAttributeConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalDbFunctionAttributeConvention.cs index 9cb329b1c39..ac14f5ace1c 100644 --- a/src/EFCore.Relational/Metadata/Conventions/RelationalDbFunctionAttributeConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/RelationalDbFunctionAttributeConvention.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -13,7 +13,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// /// A convention that configures model function mappings based on public static methods on the context marked with - /// . + /// . /// public class RelationalDbFunctionAttributeConvention : IModelInitializedConvention, IModelAnnotationChangedConvention { @@ -39,7 +39,8 @@ public RelationalDbFunctionAttributeConvention( /// /// The builder for the model. /// Additional information associated with convention execution. - public virtual void ProcessModelInitialized(IConventionModelBuilder modelBuilder, IConventionContext context) + public virtual void ProcessModelInitialized( + IConventionModelBuilder modelBuilder, IConventionContext context) { var contextType = Dependencies.ContextType; while (contextType != null @@ -86,9 +87,9 @@ public virtual void ProcessModelAnnotationChanged( } /// - /// Called when an is added to the model. + /// Called when an is added to the model. /// - /// The builder for the . + /// The builder for the . /// Additional information associated with convention execution. protected virtual void ProcessDbFunctionAdded( [NotNull] IConventionDbFunctionBuilder dbFunctionBuilder, [NotNull] IConventionContext context) diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalQueryFilterDefiningQueryRewritingConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalQueryFilterDefiningQueryRewritingConvention.cs index 8f65a63d06b..a08e0f542b4 100644 --- a/src/EFCore.Relational/Metadata/Conventions/RelationalQueryFilterDefiningQueryRewritingConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/RelationalQueryFilterDefiningQueryRewritingConvention.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -38,7 +38,9 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp || methodCallExpression.Method.Name == nameof(RelationalQueryableExtensions.FromSqlInterpolated))) { var newSource = Visit(methodCallExpression.Arguments[0]); - var fromSqlOnQueryableMethod = RelationalQueryableExtensions.FromSqlOnQueryableMethodInfo.MakeGenericMethod(newSource.Type.GetGenericArguments()[0]); + var fromSqlOnQueryableMethod = + RelationalQueryableExtensions.FromSqlOnQueryableMethodInfo.MakeGenericMethod( + newSource.Type.GetGenericArguments()[0]); switch (methodCallExpression.Method.Name) { @@ -52,7 +54,8 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp case nameof(RelationalQueryableExtensions.FromSqlInterpolated): case nameof(RelationalQueryableExtensions.FromSql) when methodCallExpression.Arguments.Count == 2: - var formattableString = Expression.Lambda>(Expression.Convert(methodCallExpression.Arguments[1], typeof(FormattableString))).Compile().Invoke(); + var formattableString = Expression.Lambda>( + Expression.Convert(methodCallExpression.Arguments[1], typeof(FormattableString))).Compile().Invoke(); return Expression.Call( null, @@ -63,7 +66,9 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp case nameof(RelationalQueryableExtensions.FromSql) when methodCallExpression.Arguments.Count == 3: #pragma warning disable CS0618 // Type or member is obsolete - var rawSqlStringString = Expression.Lambda>(Expression.Convert(methodCallExpression.Arguments[1], typeof(RawSqlString))).Compile().Invoke(); + var rawSqlStringString = Expression + .Lambda>(Expression.Convert(methodCallExpression.Arguments[1], typeof(RawSqlString))) + .Compile().Invoke(); #pragma warning restore CS0618 // Type or member is obsolete return Expression.Call( diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalTableAttributeConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalTableAttributeConvention.cs index e0f8d9c3966..c32c7214ebc 100644 --- a/src/EFCore.Relational/Metadata/Conventions/RelationalTableAttributeConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/RelationalTableAttributeConvention.cs @@ -9,7 +9,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// - /// A convention that configures the table name and schema for entity types based on the applied . + /// A convention that configures the table name and schema for entity types based on the applied . /// public class RelationalTableAttributeConvention : EntityTypeAttributeConventionBase { diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalValueGenerationConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalValueGenerationConvention.cs index d26f9fdcada..deff963a2da 100644 --- a/src/EFCore.Relational/Metadata/Conventions/RelationalValueGenerationConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/RelationalValueGenerationConvention.cs @@ -8,9 +8,9 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// - /// A convention that configures store value generation as on properties that are + /// A convention that configures store value generation as on properties that are /// part of the primary key and not part of any foreign keys or were configured to have a database default value. - /// It also configures properties as if they were configured as computed columns. + /// It also configures properties as if they were configured as computed columns. /// public class RelationalValueGenerationConvention : ValueGenerationConvention, IPropertyAnnotationChangedConvention { diff --git a/src/EFCore.Relational/Metadata/Conventions/SharedTableConvention.cs b/src/EFCore.Relational/Metadata/Conventions/SharedTableConvention.cs index 5fcb095005a..346f7b5649a 100644 --- a/src/EFCore.Relational/Metadata/Conventions/SharedTableConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/SharedTableConvention.cs @@ -91,10 +91,7 @@ private static void TryUniquifyTableNames( tableName.TableName, tables, n => (tableName.Schema, n), maxLength); if (entityType.Builder.ToTable(uniqueName) != null) { - tables[(tableName.Schema, uniqueName)] = new List - { - entityType - }; + tables[(tableName.Schema, uniqueName)] = new List { entityType }; continue; } } @@ -109,10 +106,7 @@ private static void TryUniquifyTableNames( if (otherEntityType.Builder.ToTable(uniqueName) != null) { entityTypes.Remove(otherEntityType); - tables[(tableName.Schema, uniqueName)] = new List - { - otherEntityType - }; + tables[(tableName.Schema, uniqueName)] = new List { otherEntityType }; } } } @@ -150,7 +144,8 @@ private static bool ShouldUniquify(IConventionEntityType entityType, ICollection return true; } - private static void TryUniquifyColumnNames(IConventionEntityType entityType, Dictionary properties, int maxLength) + private static void TryUniquifyColumnNames( + IConventionEntityType entityType, Dictionary properties, int maxLength) { foreach (var property in entityType.GetDeclaredProperties()) { @@ -194,7 +189,8 @@ private static void TryUniquifyColumnNames(IConventionEntityType entityType, Dic } private static string TryUniquify( - IConventionProperty property, string columnName, Dictionary properties, bool usePrefix, int maxLength) + IConventionProperty property, string columnName, Dictionary properties, bool usePrefix, + int maxLength) { if (property.Builder.CanSetColumnName(null)) { @@ -262,7 +258,8 @@ private static string TryUniquify( return null; } - private static void TryUniquifyIndexNames(IConventionEntityType entityType, Dictionary indexes, int maxLength) + private static void TryUniquifyIndexNames( + IConventionEntityType entityType, Dictionary indexes, int maxLength) { foreach (var index in entityType.GetDeclaredIndexes()) { diff --git a/src/EFCore.Relational/Metadata/Conventions/TableNameFromDbSetConvention.cs b/src/EFCore.Relational/Metadata/Conventions/TableNameFromDbSetConvention.cs index bae5c258aae..2944d2c324a 100644 --- a/src/EFCore.Relational/Metadata/Conventions/TableNameFromDbSetConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/TableNameFromDbSetConvention.cs @@ -11,7 +11,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// - /// A convention that configures the table name based on the property name. + /// A convention that configures the table name based on the property name. /// public class TableNameFromDbSetConvention : IEntityTypeAddedConvention, IEntityTypeBaseTypeChangedConvention { diff --git a/src/EFCore.Relational/Metadata/IConventionCheckConstraint.cs b/src/EFCore.Relational/Metadata/IConventionCheckConstraint.cs index 64bbeb0eef1..38b24e854ed 100644 --- a/src/EFCore.Relational/Metadata/IConventionCheckConstraint.cs +++ b/src/EFCore.Relational/Metadata/IConventionCheckConstraint.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. namespace Microsoft.EntityFrameworkCore.Metadata diff --git a/src/EFCore.Relational/Metadata/IConventionDbFunction.cs b/src/EFCore.Relational/Metadata/IConventionDbFunction.cs index b198fc36087..6df4afb0dd7 100644 --- a/src/EFCore.Relational/Metadata/IConventionDbFunction.cs +++ b/src/EFCore.Relational/Metadata/IConventionDbFunction.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -91,7 +91,8 @@ public interface IConventionDbFunction : IDbFunction /// The translation callback for performing custom translation of the method call into a SQL expression fragment. /// /// Indicates whether the configuration was specified using a data annotation. - void SetTranslation([CanBeNull] Func, SqlExpression> translation, bool fromDataAnnotation = false); + void SetTranslation( + [CanBeNull] Func, SqlExpression> translation, bool fromDataAnnotation = false); /// /// Returns the configuration source for . diff --git a/src/EFCore.Relational/Metadata/IConventionDbFunctionParameter.cs b/src/EFCore.Relational/Metadata/IConventionDbFunctionParameter.cs index 0ffeda84323..0952f16b345 100644 --- a/src/EFCore.Relational/Metadata/IConventionDbFunctionParameter.cs +++ b/src/EFCore.Relational/Metadata/IConventionDbFunctionParameter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; @@ -17,7 +17,7 @@ public interface IConventionDbFunctionParameter : IDbFunctionParameter new IConventionDbFunction Function { get; } /// - /// The for building a by-convention function parameter. + /// The for building a by-convention function parameter. /// IConventionDbFunctionParameterBuilder Builder { get; } diff --git a/src/EFCore.Relational/Metadata/IDbFunction.cs b/src/EFCore.Relational/Metadata/IDbFunction.cs index e509da8198a..af3d76d90d2 100644 --- a/src/EFCore.Relational/Metadata/IDbFunction.cs +++ b/src/EFCore.Relational/Metadata/IDbFunction.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Relational/Metadata/IDbFunctionParameter.cs b/src/EFCore.Relational/Metadata/IDbFunctionParameter.cs index eedf6bce319..b0a3bd22c8b 100644 --- a/src/EFCore.Relational/Metadata/IDbFunctionParameter.cs +++ b/src/EFCore.Relational/Metadata/IDbFunctionParameter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Relational/Metadata/IMutableDbFunction.cs b/src/EFCore.Relational/Metadata/IMutableDbFunction.cs index 2d24a3aa864..9eb02838932 100644 --- a/src/EFCore.Relational/Metadata/IMutableDbFunction.cs +++ b/src/EFCore.Relational/Metadata/IMutableDbFunction.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Relational/Metadata/IMutableDbFunctionParameter.cs b/src/EFCore.Relational/Metadata/IMutableDbFunctionParameter.cs index 24be4f0c517..ae8623245e1 100644 --- a/src/EFCore.Relational/Metadata/IMutableDbFunctionParameter.cs +++ b/src/EFCore.Relational/Metadata/IMutableDbFunctionParameter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Relational/Metadata/Internal/CheckConstraint.cs b/src/EFCore.Relational/Metadata/Internal/CheckConstraint.cs index 151a64556c5..1b51accb3f4 100644 --- a/src/EFCore.Relational/Metadata/Internal/CheckConstraint.cs +++ b/src/EFCore.Relational/Metadata/Internal/CheckConstraint.cs @@ -52,10 +52,8 @@ public CheckConstraint( { throw new InvalidOperationException(RelationalStrings.DuplicateCheckConstraint(Name, EntityType.DisplayName())); } - else - { - dataDictionary.Add(name, this); - } + + dataDictionary.Add(name, this); } /// diff --git a/src/EFCore.Relational/Metadata/Internal/DbFunctionParameter.cs b/src/EFCore.Relational/Metadata/Internal/DbFunctionParameter.cs index 482e0066c73..9e2ee4f50df 100644 --- a/src/EFCore.Relational/Metadata/Internal/DbFunctionParameter.cs +++ b/src/EFCore.Relational/Metadata/Internal/DbFunctionParameter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Relational/Metadata/Internal/RelationalForeignKeyExtensions.cs b/src/EFCore.Relational/Metadata/Internal/RelationalForeignKeyExtensions.cs index abf3aa04de4..9fef82c4a31 100644 --- a/src/EFCore.Relational/Metadata/Internal/RelationalForeignKeyExtensions.cs +++ b/src/EFCore.Relational/Metadata/Internal/RelationalForeignKeyExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -6,7 +6,6 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Internal; namespace Microsoft.EntityFrameworkCore.Metadata.Internal { diff --git a/src/EFCore.Relational/Metadata/Internal/RelationalIndexExtensions.cs b/src/EFCore.Relational/Metadata/Internal/RelationalIndexExtensions.cs index f950bae8385..84cff5d0420 100644 --- a/src/EFCore.Relational/Metadata/Internal/RelationalIndexExtensions.cs +++ b/src/EFCore.Relational/Metadata/Internal/RelationalIndexExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Relational/Metadata/Internal/Sequence.cs b/src/EFCore.Relational/Metadata/Internal/Sequence.cs index a99e145ddd8..df7ae0cb3f1 100644 --- a/src/EFCore.Relational/Metadata/Internal/Sequence.cs +++ b/src/EFCore.Relational/Metadata/Internal/Sequence.cs @@ -318,10 +318,7 @@ public virtual void SetMaxValue(long? maxValue, ConfigurationSource configuratio /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public static IReadOnlyCollection SupportedTypes { get; } - = new[] - { - typeof(byte), typeof(long), typeof(int), typeof(short), typeof(decimal) - }; + = new[] { typeof(byte), typeof(long), typeof(int), typeof(short), typeof(decimal) }; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.Relational/Metadata/Internal/TableMapping.cs b/src/EFCore.Relational/Metadata/Internal/TableMapping.cs index d9609810e9e..f2c02844205 100644 --- a/src/EFCore.Relational/Metadata/Internal/TableMapping.cs +++ b/src/EFCore.Relational/Metadata/Internal/TableMapping.cs @@ -67,11 +67,11 @@ public virtual IEntityType GetRootType() => EntityTypes.SingleOrDefault( t => t.BaseType == null && (t.FindDeclaredPrimaryKey() == null || t.FindForeignKeys(t.FindDeclaredPrimaryKey().Properties) - .All( - fk => !fk.PrincipalKey.IsPrimaryKey() - || fk.PrincipalEntityType.GetRootType() == t - || t.GetTableName() != fk.PrincipalEntityType.GetTableName() - || t.GetSchema() != fk.PrincipalEntityType.GetSchema()))); + .All( + fk => !fk.PrincipalKey.IsPrimaryKey() + || fk.PrincipalEntityType.GetRootType() == t + || t.GetTableName() != fk.PrincipalEntityType.GetTableName() + || t.GetSchema() != fk.PrincipalEntityType.GetSchema()))); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -203,6 +203,5 @@ public static TableMapping GetTableMapping([NotNull] IModel model, [NotNull] str /// public virtual string GetComment() => EntityTypes.Select(e => e.GetComment()).FirstOrDefault(c => c != null); - } } diff --git a/src/EFCore.Relational/Migrations/HistoryRepository.cs b/src/EFCore.Relational/Migrations/HistoryRepository.cs index 6904ef1b6da..72e8709e924 100644 --- a/src/EFCore.Relational/Migrations/HistoryRepository.cs +++ b/src/EFCore.Relational/Migrations/HistoryRepository.cs @@ -26,8 +26,8 @@ namespace Microsoft.EntityFrameworkCore.Migrations /// Database providers must inherit from this class to implement provider-specific functionality. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -247,7 +247,7 @@ public virtual async Task> GetAppliedMigrationsAsync( { var command = Dependencies.RawSqlCommandBuilder.Build(GetAppliedMigrationsSql); - await using(var reader = await command.ExecuteReaderAsync( + await using (var reader = await command.ExecuteReaderAsync( new RelationalCommandParameterObject( Dependencies.Connection, null, diff --git a/src/EFCore.Relational/Migrations/HistoryRepositoryDependencies.cs b/src/EFCore.Relational/Migrations/HistoryRepositoryDependencies.cs index c00198d26b5..37a8cfcf083 100644 --- a/src/EFCore.Relational/Migrations/HistoryRepositoryDependencies.cs +++ b/src/EFCore.Relational/Migrations/HistoryRepositoryDependencies.cs @@ -36,8 +36,8 @@ namespace Microsoft.EntityFrameworkCore.Migrations /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -157,7 +157,7 @@ public HistoryRepositoryDependencies( public IRelationalTypeMappingSource TypeMappingSource { get; } /// - /// Contains the currently in use. + /// Contains the currently in use. /// public ICurrentDbContext CurrentContext { get; } diff --git a/src/EFCore.Relational/Migrations/IHistoryRepository.cs b/src/EFCore.Relational/Migrations/IHistoryRepository.cs index 20daad94945..f809c63e013 100644 --- a/src/EFCore.Relational/Migrations/IHistoryRepository.cs +++ b/src/EFCore.Relational/Migrations/IHistoryRepository.cs @@ -18,8 +18,8 @@ namespace Microsoft.EntityFrameworkCore.Migrations /// Database providers typically implement this service by inheriting from . /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Relational/Migrations/IMigrationCommandExecutor.cs b/src/EFCore.Relational/Migrations/IMigrationCommandExecutor.cs index 5c8d02753fe..8941bcf65ec 100644 --- a/src/EFCore.Relational/Migrations/IMigrationCommandExecutor.cs +++ b/src/EFCore.Relational/Migrations/IMigrationCommandExecutor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; @@ -15,9 +15,9 @@ namespace Microsoft.EntityFrameworkCore.Migrations /// A service for executing migration commands against a database. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IMigrationCommandExecutor diff --git a/src/EFCore.Relational/Migrations/IMigrationsAnnotationProvider.cs b/src/EFCore.Relational/Migrations/IMigrationsAnnotationProvider.cs index e5f4c496764..dc6607212e6 100644 --- a/src/EFCore.Relational/Migrations/IMigrationsAnnotationProvider.cs +++ b/src/EFCore.Relational/Migrations/IMigrationsAnnotationProvider.cs @@ -15,9 +15,9 @@ namespace Microsoft.EntityFrameworkCore.Migrations /// used by EF Core Migrations on various elements of the . /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IMigrationsAnnotationProvider diff --git a/src/EFCore.Relational/Migrations/IMigrationsAssembly.cs b/src/EFCore.Relational/Migrations/IMigrationsAssembly.cs index b628afd3b9d..eb28f6c4344 100644 --- a/src/EFCore.Relational/Migrations/IMigrationsAssembly.cs +++ b/src/EFCore.Relational/Migrations/IMigrationsAssembly.cs @@ -15,8 +15,8 @@ namespace Microsoft.EntityFrameworkCore.Migrations /// A service representing an assembly containing EF Core Migrations. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Relational/Migrations/IMigrationsIdGenerator.cs b/src/EFCore.Relational/Migrations/IMigrationsIdGenerator.cs index b836ad8ac50..9f83139f404 100644 --- a/src/EFCore.Relational/Migrations/IMigrationsIdGenerator.cs +++ b/src/EFCore.Relational/Migrations/IMigrationsIdGenerator.cs @@ -11,9 +11,9 @@ namespace Microsoft.EntityFrameworkCore.Migrations /// A service for generating migration identifiers from names and names from identifiers. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IMigrationsIdGenerator diff --git a/src/EFCore.Relational/Migrations/IMigrationsModelDiffer.cs b/src/EFCore.Relational/Migrations/IMigrationsModelDiffer.cs index 29dd53a893c..682a606c7d1 100644 --- a/src/EFCore.Relational/Migrations/IMigrationsModelDiffer.cs +++ b/src/EFCore.Relational/Migrations/IMigrationsModelDiffer.cs @@ -16,8 +16,8 @@ namespace Microsoft.EntityFrameworkCore.Migrations /// update the database. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Relational/Migrations/IMigrationsSqlGenerator.cs b/src/EFCore.Relational/Migrations/IMigrationsSqlGenerator.cs index c88d5cb1356..131da60148e 100644 --- a/src/EFCore.Relational/Migrations/IMigrationsSqlGenerator.cs +++ b/src/EFCore.Relational/Migrations/IMigrationsSqlGenerator.cs @@ -15,8 +15,8 @@ namespace Microsoft.EntityFrameworkCore.Migrations /// then be executed or scripted from a list of s. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Relational/Migrations/IMigrator.cs b/src/EFCore.Relational/Migrations/IMigrator.cs index e7e54b7413a..a60ad8356ee 100644 --- a/src/EFCore.Relational/Migrations/IMigrator.cs +++ b/src/EFCore.Relational/Migrations/IMigrator.cs @@ -14,8 +14,8 @@ namespace Microsoft.EntityFrameworkCore.Migrations /// migrate a database directly. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Relational/Migrations/Internal/MigrationCommandExecutor.cs b/src/EFCore.Relational/Migrations/Internal/MigrationCommandExecutor.cs index d179d8d6611..32dc3b2fe6a 100644 --- a/src/EFCore.Relational/Migrations/Internal/MigrationCommandExecutor.cs +++ b/src/EFCore.Relational/Migrations/Internal/MigrationCommandExecutor.cs @@ -1,11 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using System.Transactions; -using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; @@ -20,9 +19,9 @@ namespace Microsoft.EntityFrameworkCore.Migrations.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class MigrationCommandExecutor : IMigrationCommandExecutor diff --git a/src/EFCore.Relational/Migrations/Internal/MigrationsAssembly.cs b/src/EFCore.Relational/Migrations/Internal/MigrationsAssembly.cs index 0370b9f0128..ac12700c408 100644 --- a/src/EFCore.Relational/Migrations/Internal/MigrationsAssembly.cs +++ b/src/EFCore.Relational/Migrations/Internal/MigrationsAssembly.cs @@ -21,8 +21,8 @@ namespace Microsoft.EntityFrameworkCore.Migrations.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Relational/Migrations/Internal/MigrationsIdGenerator.cs b/src/EFCore.Relational/Migrations/Internal/MigrationsIdGenerator.cs index 9500d932fe2..fb9d13d847d 100644 --- a/src/EFCore.Relational/Migrations/Internal/MigrationsIdGenerator.cs +++ b/src/EFCore.Relational/Migrations/Internal/MigrationsIdGenerator.cs @@ -16,9 +16,9 @@ namespace Microsoft.EntityFrameworkCore.Migrations.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class MigrationsIdGenerator : IMigrationsIdGenerator diff --git a/src/EFCore.Relational/Migrations/Internal/Migrator.cs b/src/EFCore.Relational/Migrations/Internal/Migrator.cs index d443285e24c..9593c458905 100644 --- a/src/EFCore.Relational/Migrations/Internal/Migrator.cs +++ b/src/EFCore.Relational/Migrations/Internal/Migrator.cs @@ -25,8 +25,8 @@ namespace Microsoft.EntityFrameworkCore.Migrations.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Relational/Migrations/MigrationBuilder.cs b/src/EFCore.Relational/Migrations/MigrationBuilder.cs index 28d63a50801..8760dbe983a 100644 --- a/src/EFCore.Relational/Migrations/MigrationBuilder.cs +++ b/src/EFCore.Relational/Migrations/MigrationBuilder.cs @@ -229,13 +229,7 @@ public virtual OperationBuilder AddPrimaryKey( Check.NotEmpty(table, nameof(table)); Check.NotEmpty(columns, nameof(columns)); - var operation = new AddPrimaryKeyOperation - { - Schema = schema, - Table = table, - Name = name, - Columns = columns - }; + var operation = new AddPrimaryKeyOperation { Schema = schema, Table = table, Name = name, Columns = columns }; Operations.Add(operation); return new OperationBuilder(operation); @@ -278,13 +272,7 @@ public virtual OperationBuilder AddUniqueConstrain Check.NotEmpty(table, nameof(table)); Check.NotEmpty(columns, nameof(columns)); - var operation = new AddUniqueConstraintOperation - { - Schema = schema, - Table = table, - Name = name, - Columns = columns - }; + var operation = new AddUniqueConstraintOperation { Schema = schema, Table = table, Name = name, Columns = columns }; Operations.Add(operation); return new OperationBuilder(operation); @@ -463,10 +451,7 @@ public virtual AlterOperationBuilder AlterSequence( IsCyclic = cyclic, OldSequence = new SequenceOperation { - IncrementBy = oldIncrementBy, - MinValue = oldMinValue, - MaxValue = oldMaxValue, - IsCyclic = oldCyclic + IncrementBy = oldIncrementBy, MinValue = oldMinValue, MaxValue = oldMaxValue, IsCyclic = oldCyclic } }; Operations.Add(operation); @@ -492,13 +477,7 @@ public virtual AlterOperationBuilder AlterTable( var operation = new AlterTableOperation { - Schema = schema, - Name = name, - Comment = comment, - OldTable = new TableOperation - { - Comment = oldComment - } + Schema = schema, Name = name, Comment = comment, OldTable = new TableOperation { Comment = oldComment } }; Operations.Add(operation); @@ -576,10 +555,7 @@ public virtual OperationBuilder EnsureSchema( { Check.NotEmpty(name, nameof(name)); - var operation = new EnsureSchemaOperation - { - Name = name - }; + var operation = new EnsureSchemaOperation { Name = name }; Operations.Add(operation); return new OperationBuilder(operation); @@ -661,13 +637,7 @@ public virtual OperationBuilder CreateCheckConst { Check.NotEmpty(name, nameof(name)); - var operation = new CreateCheckConstraintOperation - { - Schema = schema, - Name = name, - Table = table, - Sql = sql - }; + var operation = new CreateCheckConstraintOperation { Schema = schema, Name = name, Table = table, Sql = sql }; Operations.Add(operation); return new OperationBuilder(operation); @@ -697,12 +667,7 @@ public virtual CreateTableBuilder CreateTable( Check.NotEmpty(name, nameof(name)); Check.NotNull(columns, nameof(columns)); - var createTableOperation = new CreateTableOperation - { - Schema = schema, - Name = name, - Comment = comment - }; + var createTableOperation = new CreateTableOperation { Schema = schema, Name = name, Comment = comment }; var columnsBuilder = new ColumnsBuilder(createTableOperation); var columnsObject = columns(columnsBuilder); @@ -741,12 +706,7 @@ public virtual OperationBuilder DropColumn( Check.NotEmpty(name, nameof(name)); Check.NotEmpty(table, nameof(table)); - var operation = new DropColumnOperation - { - Schema = schema, - Table = table, - Name = name - }; + var operation = new DropColumnOperation { Schema = schema, Table = table, Name = name }; Operations.Add(operation); return new OperationBuilder(operation); @@ -767,12 +727,7 @@ public virtual OperationBuilder DropForeignKey( Check.NotEmpty(name, nameof(name)); Check.NotEmpty(table, nameof(table)); - var operation = new DropForeignKeyOperation - { - Schema = schema, - Table = table, - Name = name - }; + var operation = new DropForeignKeyOperation { Schema = schema, Table = table, Name = name }; Operations.Add(operation); return new OperationBuilder(operation); @@ -792,12 +747,7 @@ public virtual OperationBuilder DropIndex( { Check.NotEmpty(name, nameof(name)); - var operation = new DropIndexOperation - { - Schema = schema, - Table = table, - Name = name - }; + var operation = new DropIndexOperation { Schema = schema, Table = table, Name = name }; Operations.Add(operation); return new OperationBuilder(operation); @@ -818,12 +768,7 @@ public virtual OperationBuilder DropPrimaryKey( Check.NotEmpty(name, nameof(name)); Check.NotEmpty(table, nameof(table)); - var operation = new DropPrimaryKeyOperation - { - Schema = schema, - Table = table, - Name = name - }; + var operation = new DropPrimaryKeyOperation { Schema = schema, Table = table, Name = name }; Operations.Add(operation); return new OperationBuilder(operation); @@ -839,10 +784,7 @@ public virtual OperationBuilder DropSchema( { Check.NotEmpty(name, nameof(name)); - var operation = new DropSchemaOperation - { - Name = name - }; + var operation = new DropSchemaOperation { Name = name }; Operations.Add(operation); return new OperationBuilder(operation); @@ -860,11 +802,7 @@ public virtual OperationBuilder DropSequence( { Check.NotEmpty(name, nameof(name)); - var operation = new DropSequenceOperation - { - Schema = schema, - Name = name - }; + var operation = new DropSequenceOperation { Schema = schema, Name = name }; Operations.Add(operation); return new OperationBuilder(operation); @@ -884,12 +822,7 @@ public virtual OperationBuilder DropCheckConstrain { Check.NotEmpty(name, nameof(name)); - var operation = new DropCheckConstraintOperation - { - Name = name, - Table = table, - Schema = schema - }; + var operation = new DropCheckConstraintOperation { Name = name, Table = table, Schema = schema }; Operations.Add(operation); return new OperationBuilder(operation); @@ -907,11 +840,7 @@ public virtual OperationBuilder DropTable( { Check.NotEmpty(name, nameof(name)); - var operation = new DropTableOperation - { - Schema = schema, - Name = name - }; + var operation = new DropTableOperation { Schema = schema, Name = name }; Operations.Add(operation); return new OperationBuilder(operation); @@ -932,12 +861,7 @@ public virtual OperationBuilder DropUniqueConstra Check.NotEmpty(name, nameof(name)); Check.NotEmpty(table, nameof(table)); - var operation = new DropUniqueConstraintOperation - { - Schema = schema, - Table = table, - Name = name - }; + var operation = new DropUniqueConstraintOperation { Schema = schema, Table = table, Name = name }; Operations.Add(operation); return new OperationBuilder(operation); @@ -961,13 +885,7 @@ public virtual OperationBuilder RenameColumn( Check.NotEmpty(table, nameof(table)); Check.NotEmpty(newName, nameof(newName)); - var operation = new RenameColumnOperation - { - Name = name, - Schema = schema, - Table = table, - NewName = newName - }; + var operation = new RenameColumnOperation { Name = name, Schema = schema, Table = table, NewName = newName }; Operations.Add(operation); return new OperationBuilder(operation); @@ -990,13 +908,7 @@ public virtual OperationBuilder RenameIndex( Check.NotEmpty(name, nameof(name)); Check.NotEmpty(newName, nameof(newName)); - var operation = new RenameIndexOperation - { - Schema = schema, - Table = table, - Name = name, - NewName = newName - }; + var operation = new RenameIndexOperation { Schema = schema, Table = table, Name = name, NewName = newName }; Operations.Add(operation); return new OperationBuilder(operation); @@ -1018,13 +930,7 @@ public virtual OperationBuilder RenameSequence( { Check.NotEmpty(name, nameof(name)); - var operation = new RenameSequenceOperation - { - Name = name, - Schema = schema, - NewName = newName, - NewSchema = newSchema - }; + var operation = new RenameSequenceOperation { Name = name, Schema = schema, NewName = newName, NewSchema = newSchema }; Operations.Add(operation); return new OperationBuilder(operation); @@ -1046,13 +952,7 @@ public virtual OperationBuilder RenameTable( { Check.NotEmpty(name, nameof(name)); - var operation = new RenameTableOperation - { - Schema = schema, - Name = name, - NewName = newName, - NewSchema = newSchema - }; + var operation = new RenameTableOperation { Schema = schema, Name = name, NewName = newName, NewSchema = newSchema }; Operations.Add(operation); return new OperationBuilder(operation); @@ -1072,12 +972,7 @@ public virtual OperationBuilder RestartSequence( { Check.NotEmpty(name, nameof(name)); - var operation = new RestartSequenceOperation - { - Name = name, - Schema = schema, - StartValue = startValue - }; + var operation = new RestartSequenceOperation { Name = name, Schema = schema, StartValue = startValue }; Operations.Add(operation); return new OperationBuilder(operation); @@ -1097,11 +992,7 @@ public virtual OperationBuilder Sql( { Check.NotEmpty(sql, nameof(sql)); - var operation = new SqlOperation - { - Sql = sql, - SuppressTransaction = suppressTransaction - }; + var operation = new SqlOperation { Sql = sql, SuppressTransaction = suppressTransaction }; Operations.Add(operation); return new OperationBuilder(operation); @@ -1177,13 +1068,7 @@ public virtual OperationBuilder InsertData( Check.NotNull(columns, nameof(columns)); Check.NotNull(values, nameof(values)); - var operation = new InsertDataOperation - { - Table = table, - Schema = schema, - Columns = columns, - Values = values - }; + var operation = new InsertDataOperation { Table = table, Schema = schema, Columns = columns, Values = values }; Operations.Add(operation); return new OperationBuilder(operation); @@ -1265,13 +1150,7 @@ public virtual OperationBuilder DeleteData( Check.NotNull(keyColumns, nameof(keyColumns)); Check.NotNull(keyValues, nameof(keyValues)); - var operation = new DeleteDataOperation - { - Table = table, - Schema = schema, - KeyColumns = keyColumns, - KeyValues = keyValues - }; + var operation = new DeleteDataOperation { Table = table, Schema = schema, KeyColumns = keyColumns, KeyValues = keyValues }; Operations.Add(operation); return new OperationBuilder(operation); diff --git a/src/EFCore.Relational/Migrations/MigrationCommand.cs b/src/EFCore.Relational/Migrations/MigrationCommand.cs index 752414b149e..ddd4a65dfc2 100644 --- a/src/EFCore.Relational/Migrations/MigrationCommand.cs +++ b/src/EFCore.Relational/Migrations/MigrationCommand.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; @@ -24,7 +24,7 @@ public class MigrationCommand /// Creates a new instance of the command. /// /// The underlying that will be used to execute the command. - /// The current or null if not known. + /// The current or null if not known. /// The command logger. /// Indicates whether or not transactions should be suppressed while executing the command. public MigrationCommand( diff --git a/src/EFCore.Relational/Migrations/MigrationsAnnotationProvider.cs b/src/EFCore.Relational/Migrations/MigrationsAnnotationProvider.cs index 2f4ea41f4e7..c4e7850697d 100644 --- a/src/EFCore.Relational/Migrations/MigrationsAnnotationProvider.cs +++ b/src/EFCore.Relational/Migrations/MigrationsAnnotationProvider.cs @@ -17,9 +17,9 @@ namespace Microsoft.EntityFrameworkCore.Migrations /// used by EF Core Migrations on various elements of the . /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class MigrationsAnnotationProvider : IMigrationsAnnotationProvider diff --git a/src/EFCore.Relational/Migrations/MigrationsAnnotationProviderDependencies.cs b/src/EFCore.Relational/Migrations/MigrationsAnnotationProviderDependencies.cs index fec4e1ae5f2..ff879f8bdfc 100644 --- a/src/EFCore.Relational/Migrations/MigrationsAnnotationProviderDependencies.cs +++ b/src/EFCore.Relational/Migrations/MigrationsAnnotationProviderDependencies.cs @@ -23,10 +23,10 @@ namespace Microsoft.EntityFrameworkCore.Migrations /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . - /// This means a single instance of each service is used by many instances. + /// The service lifetime is . + /// This means a single instance of each service is used by many instances. /// The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs b/src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs index dd86a654a96..5fafe0b60f0 100644 --- a/src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs +++ b/src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs @@ -29,52 +29,54 @@ namespace Microsoft.EntityFrameworkCore.Migrations /// This class is typically inherited by database providers to customize the SQL generation. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// /// public class MigrationsSqlGenerator : IMigrationsSqlGenerator { - private static readonly IReadOnlyDictionary> _generateActions = - new Dictionary> - { - { typeof(AddColumnOperation), (g, o, m, b) => g.Generate((AddColumnOperation)o, m, b) }, - { typeof(AddForeignKeyOperation), (g, o, m, b) => g.Generate((AddForeignKeyOperation)o, m, b) }, - { typeof(AddPrimaryKeyOperation), (g, o, m, b) => g.Generate((AddPrimaryKeyOperation)o, m, b) }, - { typeof(AddUniqueConstraintOperation), (g, o, m, b) => g.Generate((AddUniqueConstraintOperation)o, m, b) }, - { typeof(AlterColumnOperation), (g, o, m, b) => g.Generate((AlterColumnOperation)o, m, b) }, - { typeof(AlterDatabaseOperation), (g, o, m, b) => g.Generate((AlterDatabaseOperation)o, m, b) }, - { typeof(AlterSequenceOperation), (g, o, m, b) => g.Generate((AlterSequenceOperation)o, m, b) }, - { typeof(AlterTableOperation), (g, o, m, b) => g.Generate((AlterTableOperation)o, m, b) }, - { typeof(CreateCheckConstraintOperation), (g, o, m, b) => g.Generate((CreateCheckConstraintOperation)o, m, b) }, - { typeof(CreateIndexOperation), (g, o, m, b) => g.Generate((CreateIndexOperation)o, m, b) }, - { typeof(CreateSequenceOperation), (g, o, m, b) => g.Generate((CreateSequenceOperation)o, m, b) }, - { typeof(CreateTableOperation), (g, o, m, b) => g.Generate((CreateTableOperation)o, m, b) }, - { typeof(DropColumnOperation), (g, o, m, b) => g.Generate((DropColumnOperation)o, m, b) }, - { typeof(DropForeignKeyOperation), (g, o, m, b) => g.Generate((DropForeignKeyOperation)o, m, b) }, - { typeof(DropIndexOperation), (g, o, m, b) => g.Generate((DropIndexOperation)o, m, b) }, - { typeof(DropPrimaryKeyOperation), (g, o, m, b) => g.Generate((DropPrimaryKeyOperation)o, m, b) }, - { typeof(DropSchemaOperation), (g, o, m, b) => g.Generate((DropSchemaOperation)o, m, b) }, - { typeof(DropSequenceOperation), (g, o, m, b) => g.Generate((DropSequenceOperation)o, m, b) }, - { typeof(DropTableOperation), (g, o, m, b) => g.Generate((DropTableOperation)o, m, b) }, - { typeof(DropUniqueConstraintOperation), (g, o, m, b) => g.Generate((DropUniqueConstraintOperation)o, m, b) }, - { typeof(DropCheckConstraintOperation), (g, o, m, b) => g.Generate((DropCheckConstraintOperation)o, m, b) }, - { typeof(EnsureSchemaOperation), (g, o, m, b) => g.Generate((EnsureSchemaOperation)o, m, b) }, - { typeof(RenameColumnOperation), (g, o, m, b) => g.Generate((RenameColumnOperation)o, m, b) }, - { typeof(RenameIndexOperation), (g, o, m, b) => g.Generate((RenameIndexOperation)o, m, b) }, - { typeof(RenameSequenceOperation), (g, o, m, b) => g.Generate((RenameSequenceOperation)o, m, b) }, - { typeof(RenameTableOperation), (g, o, m, b) => g.Generate((RenameTableOperation)o, m, b) }, - { typeof(RestartSequenceOperation), (g, o, m, b) => g.Generate((RestartSequenceOperation)o, m, b) }, - { typeof(SqlOperation), (g, o, m, b) => g.Generate((SqlOperation)o, m, b) }, - { typeof(InsertDataOperation), (g, o, m, b) => g.Generate((InsertDataOperation)o, m, b) }, - { typeof(DeleteDataOperation), (g, o, m, b) => g.Generate((DeleteDataOperation)o, m, b) }, - { typeof(UpdateDataOperation), (g, o, m, b) => g.Generate((UpdateDataOperation)o, m, b) } - }; - - /// - /// Creates a new instance using the given dependencies. + private static readonly + IReadOnlyDictionary> + _generateActions = + new Dictionary> + { + { typeof(AddColumnOperation), (g, o, m, b) => g.Generate((AddColumnOperation)o, m, b) }, + { typeof(AddForeignKeyOperation), (g, o, m, b) => g.Generate((AddForeignKeyOperation)o, m, b) }, + { typeof(AddPrimaryKeyOperation), (g, o, m, b) => g.Generate((AddPrimaryKeyOperation)o, m, b) }, + { typeof(AddUniqueConstraintOperation), (g, o, m, b) => g.Generate((AddUniqueConstraintOperation)o, m, b) }, + { typeof(AlterColumnOperation), (g, o, m, b) => g.Generate((AlterColumnOperation)o, m, b) }, + { typeof(AlterDatabaseOperation), (g, o, m, b) => g.Generate((AlterDatabaseOperation)o, m, b) }, + { typeof(AlterSequenceOperation), (g, o, m, b) => g.Generate((AlterSequenceOperation)o, m, b) }, + { typeof(AlterTableOperation), (g, o, m, b) => g.Generate((AlterTableOperation)o, m, b) }, + { typeof(CreateCheckConstraintOperation), (g, o, m, b) => g.Generate((CreateCheckConstraintOperation)o, m, b) }, + { typeof(CreateIndexOperation), (g, o, m, b) => g.Generate((CreateIndexOperation)o, m, b) }, + { typeof(CreateSequenceOperation), (g, o, m, b) => g.Generate((CreateSequenceOperation)o, m, b) }, + { typeof(CreateTableOperation), (g, o, m, b) => g.Generate((CreateTableOperation)o, m, b) }, + { typeof(DropColumnOperation), (g, o, m, b) => g.Generate((DropColumnOperation)o, m, b) }, + { typeof(DropForeignKeyOperation), (g, o, m, b) => g.Generate((DropForeignKeyOperation)o, m, b) }, + { typeof(DropIndexOperation), (g, o, m, b) => g.Generate((DropIndexOperation)o, m, b) }, + { typeof(DropPrimaryKeyOperation), (g, o, m, b) => g.Generate((DropPrimaryKeyOperation)o, m, b) }, + { typeof(DropSchemaOperation), (g, o, m, b) => g.Generate((DropSchemaOperation)o, m, b) }, + { typeof(DropSequenceOperation), (g, o, m, b) => g.Generate((DropSequenceOperation)o, m, b) }, + { typeof(DropTableOperation), (g, o, m, b) => g.Generate((DropTableOperation)o, m, b) }, + { typeof(DropUniqueConstraintOperation), (g, o, m, b) => g.Generate((DropUniqueConstraintOperation)o, m, b) }, + { typeof(DropCheckConstraintOperation), (g, o, m, b) => g.Generate((DropCheckConstraintOperation)o, m, b) }, + { typeof(EnsureSchemaOperation), (g, o, m, b) => g.Generate((EnsureSchemaOperation)o, m, b) }, + { typeof(RenameColumnOperation), (g, o, m, b) => g.Generate((RenameColumnOperation)o, m, b) }, + { typeof(RenameIndexOperation), (g, o, m, b) => g.Generate((RenameIndexOperation)o, m, b) }, + { typeof(RenameSequenceOperation), (g, o, m, b) => g.Generate((RenameSequenceOperation)o, m, b) }, + { typeof(RenameTableOperation), (g, o, m, b) => g.Generate((RenameTableOperation)o, m, b) }, + { typeof(RestartSequenceOperation), (g, o, m, b) => g.Generate((RestartSequenceOperation)o, m, b) }, + { typeof(SqlOperation), (g, o, m, b) => g.Generate((SqlOperation)o, m, b) }, + { typeof(InsertDataOperation), (g, o, m, b) => g.Generate((InsertDataOperation)o, m, b) }, + { typeof(DeleteDataOperation), (g, o, m, b) => g.Generate((DeleteDataOperation)o, m, b) }, + { typeof(UpdateDataOperation), (g, o, m, b) => g.Generate((UpdateDataOperation)o, m, b) } + }; + + /// + /// Creates a new instance using the given dependencies. /// /// Parameter object containing dependencies for this service. public MigrationsSqlGenerator([NotNull] MigrationsSqlGeneratorDependencies dependencies) @@ -1243,7 +1245,9 @@ protected virtual void DefaultValue( } else if (defaultValue != null) { - var typeMapping = columnType != null ? Dependencies.TypeMappingSource.FindMapping(defaultValue.GetType(), columnType) : null; + var typeMapping = columnType != null + ? Dependencies.TypeMappingSource.FindMapping(defaultValue.GetType(), columnType) + : null; if (typeMapping == null) { typeMapping = Dependencies.TypeMappingSource.GetMappingForValue(defaultValue); diff --git a/src/EFCore.Relational/Migrations/MigrationsSqlGeneratorDependencies.cs b/src/EFCore.Relational/Migrations/MigrationsSqlGeneratorDependencies.cs index 1e5716e0eea..edbec001b71 100644 --- a/src/EFCore.Relational/Migrations/MigrationsSqlGeneratorDependencies.cs +++ b/src/EFCore.Relational/Migrations/MigrationsSqlGeneratorDependencies.cs @@ -28,8 +28,8 @@ namespace Microsoft.EntityFrameworkCore.Migrations /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -100,7 +100,7 @@ public MigrationsSqlGeneratorDependencies( public IRelationalTypeMappingSource TypeMappingSource { get; } /// - /// Contains the currently in use. + /// Contains the currently in use. /// public ICurrentDbContext CurrentContext { get; } diff --git a/src/EFCore.Relational/Migrations/Operations/AlterTableOperation.cs b/src/EFCore.Relational/Migrations/Operations/AlterTableOperation.cs index 533fe5ac285..61323393a5b 100644 --- a/src/EFCore.Relational/Migrations/Operations/AlterTableOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/AlterTableOperation.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; -using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; namespace Microsoft.EntityFrameworkCore.Migrations.Operations diff --git a/src/EFCore.Relational/Migrations/Operations/Builders/CreateTableBuilder.cs b/src/EFCore.Relational/Migrations/Operations/Builders/CreateTableBuilder.cs index 47ff13ea456..7ee444e859c 100644 --- a/src/EFCore.Relational/Migrations/Operations/Builders/CreateTableBuilder.cs +++ b/src/EFCore.Relational/Migrations/Operations/Builders/CreateTableBuilder.cs @@ -120,10 +120,7 @@ public virtual OperationBuilder PrimaryKey( var operation = new AddPrimaryKeyOperation { - Schema = Operation.Schema, - Table = Operation.Name, - Name = name, - Columns = Map(columns) + Schema = Operation.Schema, Table = Operation.Name, Name = name, Columns = Map(columns) }; // TODO: Throw if already set? Operation.PrimaryKey = operation; @@ -146,10 +143,7 @@ public virtual OperationBuilder UniqueConstraint( var operation = new AddUniqueConstraintOperation { - Schema = Operation.Schema, - Table = Operation.Name, - Name = name, - Columns = Map(columns) + Schema = Operation.Schema, Table = Operation.Name, Name = name, Columns = Map(columns) }; Operation.UniqueConstraints.Add(operation); @@ -171,10 +165,7 @@ public virtual OperationBuilder CheckConstraint( var operation = new CreateCheckConstraintOperation { - Schema = Operation.Schema, - Table = Operation.Name, - Name = name, - Sql = sql + Schema = Operation.Schema, Table = Operation.Name, Name = name, Sql = sql }; Operation.CheckConstraints.Add(operation); diff --git a/src/EFCore.Relational/Migrations/Operations/CreateCheckConstraintOperation.cs b/src/EFCore.Relational/Migrations/Operations/CreateCheckConstraintOperation.cs index 248174bb7cd..06820738d26 100644 --- a/src/EFCore.Relational/Migrations/Operations/CreateCheckConstraintOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/CreateCheckConstraintOperation.cs @@ -26,10 +26,10 @@ public class CreateCheckConstraintOperation : MigrationOperation public virtual string Schema { get; [param: CanBeNull] set; } /// - /// The logical sql expression used in a CHECK constraint and returns TRUE or FALSE. - /// Sql used with CHECK constraints cannot reference another table - /// but can reference other columns in the same table for the same row. - /// The expression cannot reference an alias data type. + /// The logical sql expression used in a CHECK constraint and returns TRUE or FALSE. + /// Sql used with CHECK constraints cannot reference another table + /// but can reference other columns in the same table for the same row. + /// The expression cannot reference an alias data type. /// public virtual string Sql { get; [param: NotNull] set; } } diff --git a/src/EFCore.Relational/Query/CollectionInitializingExpression.cs b/src/EFCore.Relational/Query/CollectionInitializingExpression.cs index 7354f353430..6fdac3fbce4 100644 --- a/src/EFCore.Relational/Query/CollectionInitializingExpression.cs +++ b/src/EFCore.Relational/Query/CollectionInitializingExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Relational/Query/CollectionPopulatingExpression.cs b/src/EFCore.Relational/Query/CollectionPopulatingExpression.cs index 2fa7a77473d..68e78e76a0c 100644 --- a/src/EFCore.Relational/Query/CollectionPopulatingExpression.cs +++ b/src/EFCore.Relational/Query/CollectionPopulatingExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Relational/Query/EntityProjectionExpression.cs b/src/EFCore.Relational/Query/EntityProjectionExpression.cs index 6c7b6be3d54..7da776eab99 100644 --- a/src/EFCore.Relational/Query/EntityProjectionExpression.cs +++ b/src/EFCore.Relational/Query/EntityProjectionExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -13,6 +13,7 @@ public class EntityProjectionExpression : Expression { private readonly IDictionary _propertyExpressionsCache = new Dictionary(); + private readonly IDictionary _navigationExpressionsCache = new Dictionary(); @@ -80,21 +81,19 @@ public virtual EntityProjectionExpression UpdateEntityType(IEntityType derivedTy { return new EntityProjectionExpression(derivedType, _innerTable, _nullable); } - else + + var propertyExpressionCache = new Dictionary(); + foreach (var kvp in _propertyExpressionsCache) { - var propertyExpressionCache = new Dictionary(); - foreach (var kvp in _propertyExpressionsCache) + var property = kvp.Key; + if (derivedType.IsAssignableFrom(property.DeclaringEntityType) + || property.DeclaringEntityType.IsAssignableFrom(derivedType)) { - var property = kvp.Key; - if (derivedType.IsAssignableFrom(property.DeclaringEntityType) - || property.DeclaringEntityType.IsAssignableFrom(derivedType)) - { - propertyExpressionCache[property] = kvp.Value; - } + propertyExpressionCache[property] = kvp.Value; } - - return new EntityProjectionExpression(derivedType, propertyExpressionCache); } + + return new EntityProjectionExpression(derivedType, propertyExpressionCache); } public virtual IEntityType EntityType { get; } @@ -125,7 +124,7 @@ public virtual void AddNavigationBinding(INavigation navigation, EntityShaperExp && !navigation.DeclaringEntityType.IsAssignableFrom(EntityType)) { throw new InvalidOperationException( - $"Called EntityProjectionExpression.AddNavigationBinding() with incorrect INavigation. " + + "Called EntityProjectionExpression.AddNavigationBinding() with incorrect INavigation. " + $"EntityType:{EntityType.DisplayName()}, Property:{navigation.Name}"); } @@ -138,7 +137,7 @@ public virtual EntityShaperExpression BindNavigation(INavigation navigation) && !navigation.DeclaringEntityType.IsAssignableFrom(EntityType)) { throw new InvalidOperationException( - $"Called EntityProjectionExpression.BindNavigation() with incorrect INavigation. " + + "Called EntityProjectionExpression.BindNavigation() with incorrect INavigation. " + $"EntityType:{EntityType.DisplayName()}, Property:{navigation.Name}"); } diff --git a/src/EFCore.Relational/Query/ExpressionExtensions.cs b/src/EFCore.Relational/Query/ExpressionExtensions.cs index 2ff11d320c5..7a00f5fe0a5 100644 --- a/src/EFCore.Relational/Query/ExpressionExtensions.cs +++ b/src/EFCore.Relational/Query/ExpressionExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.Query.SqlExpressions; diff --git a/src/EFCore.Relational/Query/IMemberTranslator.cs b/src/EFCore.Relational/Query/IMemberTranslator.cs index 473abd2aaed..d60efd66f2f 100644 --- a/src/EFCore.Relational/Query/IMemberTranslator.cs +++ b/src/EFCore.Relational/Query/IMemberTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Relational/Query/IMemberTranslatorPlugin.cs b/src/EFCore.Relational/Query/IMemberTranslatorPlugin.cs index 1acb109b0b0..7bbc3bc17d3 100644 --- a/src/EFCore.Relational/Query/IMemberTranslatorPlugin.cs +++ b/src/EFCore.Relational/Query/IMemberTranslatorPlugin.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; @@ -11,10 +11,10 @@ namespace Microsoft.EntityFrameworkCore.Query /// Represents plugin member translators. /// /// - /// The service lifetime is and multiple registrations - /// are allowed. This means a single instance of each service is used by many + /// The service lifetime is and multiple registrations + /// are allowed. This means a single instance of each service is used by many /// instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public interface IMemberTranslatorPlugin diff --git a/src/EFCore.Relational/Query/IMemberTranslatorProvider.cs b/src/EFCore.Relational/Query/IMemberTranslatorProvider.cs index 1c4b466f73c..b9839f580e2 100644 --- a/src/EFCore.Relational/Query/IMemberTranslatorProvider.cs +++ b/src/EFCore.Relational/Query/IMemberTranslatorProvider.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -10,12 +10,12 @@ namespace Microsoft.EntityFrameworkCore.Query { /// /// - /// Provides translations for object members to instances. + /// Provides translations for object members to instances. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IMemberTranslatorProvider diff --git a/src/EFCore.Relational/Query/IMethodCallTranslator.cs b/src/EFCore.Relational/Query/IMethodCallTranslator.cs index f3f5844b589..65470501dc7 100644 --- a/src/EFCore.Relational/Query/IMethodCallTranslator.cs +++ b/src/EFCore.Relational/Query/IMethodCallTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; diff --git a/src/EFCore.Relational/Query/IMethodCallTranslatorPlugin.cs b/src/EFCore.Relational/Query/IMethodCallTranslatorPlugin.cs index 03762e812b7..9d9303e1c28 100644 --- a/src/EFCore.Relational/Query/IMethodCallTranslatorPlugin.cs +++ b/src/EFCore.Relational/Query/IMethodCallTranslatorPlugin.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; @@ -11,10 +11,10 @@ namespace Microsoft.EntityFrameworkCore.Query /// Represents plugin method call translators. /// /// - /// The service lifetime is and multiple registrations - /// are allowed. This means a single instance of each service is used by many + /// The service lifetime is and multiple registrations + /// are allowed. This means a single instance of each service is used by many /// instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public interface IMethodCallTranslatorPlugin diff --git a/src/EFCore.Relational/Query/IMethodCallTranslatorProvider.cs b/src/EFCore.Relational/Query/IMethodCallTranslatorProvider.cs index 1d0243b2db6..446098ff8af 100644 --- a/src/EFCore.Relational/Query/IMethodCallTranslatorProvider.cs +++ b/src/EFCore.Relational/Query/IMethodCallTranslatorProvider.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; @@ -11,12 +11,12 @@ namespace Microsoft.EntityFrameworkCore.Query { /// /// - /// Provides translations for method calls to instances. + /// Provides translations for method calls to instances. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IMethodCallTranslatorProvider diff --git a/src/EFCore.Relational/Query/IQuerySqlGeneratorFactory.cs b/src/EFCore.Relational/Query/IQuerySqlGeneratorFactory.cs index 56c7200db1d..c700103b337 100644 --- a/src/EFCore.Relational/Query/IQuerySqlGeneratorFactory.cs +++ b/src/EFCore.Relational/Query/IQuerySqlGeneratorFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.Extensions.DependencyInjection; @@ -7,12 +7,12 @@ namespace Microsoft.EntityFrameworkCore.Query { /// /// - /// A factory for creating instances. + /// A factory for creating instances. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IQuerySqlGeneratorFactory diff --git a/src/EFCore.Relational/Query/IRelationalSqlTranslatingExpressionVisitorFactory.cs b/src/EFCore.Relational/Query/IRelationalSqlTranslatingExpressionVisitorFactory.cs index d657790e37f..be60d7ef475 100644 --- a/src/EFCore.Relational/Query/IRelationalSqlTranslatingExpressionVisitorFactory.cs +++ b/src/EFCore.Relational/Query/IRelationalSqlTranslatingExpressionVisitorFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.Metadata; @@ -8,12 +8,12 @@ namespace Microsoft.EntityFrameworkCore.Query { /// /// - /// A factory for creating instances. + /// A factory for creating instances. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IRelationalSqlTranslatingExpressionVisitorFactory diff --git a/src/EFCore.Relational/Query/ISqlExpressionFactory.cs b/src/EFCore.Relational/Query/ISqlExpressionFactory.cs index 3dba2646919..0ff904818fe 100644 --- a/src/EFCore.Relational/Query/ISqlExpressionFactory.cs +++ b/src/EFCore.Relational/Query/ISqlExpressionFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -13,12 +13,12 @@ namespace Microsoft.EntityFrameworkCore.Query { /// /// - /// A factory for creating instances. + /// A factory for creating instances. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface ISqlExpressionFactory @@ -28,27 +28,39 @@ public interface ISqlExpressionFactory RelationalTypeMapping GetTypeMappingForValue(object value); RelationalTypeMapping FindMapping(Type type); - SqlUnaryExpression MakeUnary(ExpressionType operatorType, SqlExpression operand, Type type, RelationalTypeMapping typeMapping = null); - SqlBinaryExpression MakeBinary(ExpressionType operatorType, SqlExpression left, SqlExpression right, RelationalTypeMapping typeMapping); + SqlUnaryExpression MakeUnary( + ExpressionType operatorType, SqlExpression operand, Type type, RelationalTypeMapping typeMapping = null); + + SqlBinaryExpression MakeBinary( + ExpressionType operatorType, SqlExpression left, SqlExpression right, RelationalTypeMapping typeMapping); + // Comparison SqlBinaryExpression Equal(SqlExpression left, SqlExpression right); SqlBinaryExpression NotEqual(SqlExpression left, SqlExpression right); SqlBinaryExpression GreaterThan(SqlExpression left, SqlExpression right); SqlBinaryExpression GreaterThanOrEqual(SqlExpression left, SqlExpression right); SqlBinaryExpression LessThan(SqlExpression left, SqlExpression right); + SqlBinaryExpression LessThanOrEqual(SqlExpression left, SqlExpression right); + // Logical SqlBinaryExpression AndAlso(SqlExpression left, SqlExpression right); + SqlBinaryExpression OrElse(SqlExpression left, SqlExpression right); + // Arithmetic SqlBinaryExpression Add(SqlExpression left, SqlExpression right, RelationalTypeMapping typeMapping = null); SqlBinaryExpression Subtract(SqlExpression left, SqlExpression right, RelationalTypeMapping typeMapping = null); SqlBinaryExpression Multiply(SqlExpression left, SqlExpression right, RelationalTypeMapping typeMapping = null); SqlBinaryExpression Divide(SqlExpression left, SqlExpression right, RelationalTypeMapping typeMapping = null); + SqlBinaryExpression Modulo(SqlExpression left, SqlExpression right, RelationalTypeMapping typeMapping = null); + // Bitwise SqlBinaryExpression And(SqlExpression left, SqlExpression right, RelationalTypeMapping typeMapping = null); + SqlBinaryExpression Or(SqlExpression left, SqlExpression right, RelationalTypeMapping typeMapping = null); + // Other SqlBinaryExpression Coalesce(SqlExpression left, SqlExpression right, RelationalTypeMapping typeMapping = null); @@ -63,14 +75,20 @@ public interface ISqlExpressionFactory SqlFunctionExpression Function( string name, IEnumerable arguments, Type returnType, RelationalTypeMapping typeMapping = null); + SqlFunctionExpression Function( string schema, string name, IEnumerable arguments, Type returnType, RelationalTypeMapping typeMapping = null); + SqlFunctionExpression Function( - SqlExpression instance, string name, IEnumerable arguments, Type returnType, RelationalTypeMapping typeMapping = null); + SqlExpression instance, string name, IEnumerable arguments, Type returnType, + RelationalTypeMapping typeMapping = null); + SqlFunctionExpression Function( string name, Type returnType, RelationalTypeMapping typeMapping = null); + SqlFunctionExpression Function( string schema, string name, Type returnType, RelationalTypeMapping typeMapping = null); + SqlFunctionExpression Function( SqlExpression instance, string name, Type returnType, RelationalTypeMapping typeMapping = null); diff --git a/src/EFCore.Relational/Query/Internal/CollectionJoinApplyingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/CollectionJoinApplyingExpressionVisitor.cs index 11e18268c17..8c7338c8594 100644 --- a/src/EFCore.Relational/Query/Internal/CollectionJoinApplyingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/Internal/CollectionJoinApplyingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq.Expressions; diff --git a/src/EFCore.Relational/Query/Internal/ComparisonTranslator.cs b/src/EFCore.Relational/Query/Internal/ComparisonTranslator.cs index f87e937d463..c7939612c52 100644 --- a/src/EFCore.Relational/Query/Internal/ComparisonTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/ComparisonTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -31,25 +31,26 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method right = arguments[1]; } else if (method.Name == nameof(string.CompareTo) - && arguments.Count == 1 - && instance != null - && instance.Type.UnwrapNullableType() == arguments[0].Type.UnwrapNullableType()) + && arguments.Count == 1 + && instance != null + && instance.Type.UnwrapNullableType() == arguments[0].Type.UnwrapNullableType()) { left = instance; right = arguments[0]; } - if (left != null && right != null) + if (left != null + && right != null) { return _sqlExpressionFactory.Case( - new CaseWhenClause[] + new[] { new CaseWhenClause( _sqlExpressionFactory.Equal(left, right), _sqlExpressionFactory.Constant(0)), new CaseWhenClause( _sqlExpressionFactory.GreaterThan(left, right), _sqlExpressionFactory.Constant(1)), new CaseWhenClause( - _sqlExpressionFactory.LessThan(left, right), _sqlExpressionFactory.Constant(-1)), + _sqlExpressionFactory.LessThan(left, right), _sqlExpressionFactory.Constant(-1)) }, null); } diff --git a/src/EFCore.Relational/Query/Internal/ContainsTranslator.cs b/src/EFCore.Relational/Query/Internal/ContainsTranslator.cs index 167923d8e00..4b549546975 100644 --- a/src/EFCore.Relational/Query/Internal/ContainsTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/ContainsTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections; @@ -30,7 +30,8 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method { return _sqlExpressionFactory.In(arguments[1], arguments[0], false); } - else if (method.DeclaringType.GetInterfaces().Contains(typeof(IList)) + + if (method.DeclaringType.GetInterfaces().Contains(typeof(IList)) && string.Equals(method.Name, nameof(IList.Contains))) { return _sqlExpressionFactory.In(arguments[0], instance, false); diff --git a/src/EFCore.Relational/Query/Internal/EnumHasFlagTranslator.cs b/src/EFCore.Relational/Query/Internal/EnumHasFlagTranslator.cs index 4e5a1fa0e17..9c63fc9c048 100644 --- a/src/EFCore.Relational/Query/Internal/EnumHasFlagTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/EnumHasFlagTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Relational/Query/Internal/EqualsTranslator.cs b/src/EFCore.Relational/Query/Internal/EqualsTranslator.cs index dfc56b637f2..ab3c544ad9a 100644 --- a/src/EFCore.Relational/Query/Internal/EqualsTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/EqualsTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -31,22 +31,21 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method right = RemoveObjectConvert(arguments[0]); } else if (method.Name == nameof(object.Equals) - && arguments.Count == 2) + && arguments.Count == 2) { left = RemoveObjectConvert(arguments[0]); right = RemoveObjectConvert(arguments[1]); } - if (left != null && right != null) + if (left != null + && right != null) { if (left.Type.UnwrapNullableType() == right.Type.UnwrapNullableType()) { return _sqlExpressionFactory.Equal(left, right); } - else - { - return _sqlExpressionFactory.Constant(false); - } + + return _sqlExpressionFactory.Constant(false); } return null; diff --git a/src/EFCore.Relational/Query/Internal/GetValueOrDefaultTranslator.cs b/src/EFCore.Relational/Query/Internal/GetValueOrDefaultTranslator.cs index 11136e82ec7..7d0205ed214 100644 --- a/src/EFCore.Relational/Query/Internal/GetValueOrDefaultTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/GetValueOrDefaultTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -12,6 +12,7 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal public class GetValueOrDefaultTranslator : IMethodCallTranslator { private readonly ISqlExpressionFactory _sqlExpressionFactory; + public GetValueOrDefaultTranslator(ISqlExpressionFactory sqlExpressionFactory) { _sqlExpressionFactory = sqlExpressionFactory; @@ -25,8 +26,8 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method return _sqlExpressionFactory.Coalesce( instance, arguments.Count == 0 - ? GetDefaultConstant(method.ReturnType) - : arguments[0], + ? GetDefaultConstant(method.ReturnType) + : arguments[0], instance.TypeMapping); } diff --git a/src/EFCore.Relational/Query/Internal/LikeTranslator.cs b/src/EFCore.Relational/Query/Internal/LikeTranslator.cs index 456ace2a9e3..887577675db 100644 --- a/src/EFCore.Relational/Query/Internal/LikeTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/LikeTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; diff --git a/src/EFCore.Relational/Query/Internal/NullComparisonTransformingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/NullComparisonTransformingExpressionVisitor.cs index 35c1077a300..983640ab8a5 100644 --- a/src/EFCore.Relational/Query/Internal/NullComparisonTransformingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/Internal/NullComparisonTransformingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq.Expressions; diff --git a/src/EFCore.Relational/Query/Internal/NullSemanticsRewritingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/NullSemanticsRewritingExpressionVisitor.cs index d7e5a7b918b..45f42a83b03 100644 --- a/src/EFCore.Relational/Query/Internal/NullSemanticsRewritingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/Internal/NullSemanticsRewritingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -12,7 +12,7 @@ public class NullSemanticsRewritingExpressionVisitor : ExpressionVisitor { private readonly ISqlExpressionFactory _sqlExpressionFactory; - private bool _isNullable = false; + private bool _isNullable; public NullSemanticsRewritingExpressionVisitor(ISqlExpressionFactory sqlExpressionFactory) { @@ -234,7 +234,8 @@ private SqlBinaryExpression VisitSqlBinaryExpression(SqlBinaryExpression sqlBina if (sqlBinaryExpression.OperatorType == ExpressionType.Equal) { - if (!leftNullable && !rightNullable) + if (!leftNullable + && !rightNullable) { // a == b <=> !a == !b -> a == b // !a == b <=> a == !b -> a != b @@ -273,7 +274,8 @@ private SqlBinaryExpression VisitSqlBinaryExpression(SqlBinaryExpression sqlBina if (sqlBinaryExpression.OperatorType == ExpressionType.NotEqual) { - if (!leftNullable && !rightNullable) + if (!leftNullable + && !rightNullable) { // a != b <=> !a != !b -> a != b // !a != b <=> a != !b -> a == b diff --git a/src/EFCore.Relational/Query/Internal/NullableMemberTranslator.cs b/src/EFCore.Relational/Query/Internal/NullableMemberTranslator.cs index 2aa9a5ceb1f..b3b55e59e78 100644 --- a/src/EFCore.Relational/Query/Internal/NullableMemberTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/NullableMemberTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Relational/Query/Internal/QuerySqlGeneratorFactory.cs b/src/EFCore.Relational/Query/Internal/QuerySqlGeneratorFactory.cs index f59687622e7..cfd2510fdf3 100644 --- a/src/EFCore.Relational/Query/Internal/QuerySqlGeneratorFactory.cs +++ b/src/EFCore.Relational/Query/Internal/QuerySqlGeneratorFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. namespace Microsoft.EntityFrameworkCore.Query.Internal diff --git a/src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs index acfb152ade9..26f6edcf747 100644 --- a/src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -20,8 +20,10 @@ public class RelationalProjectionBindingExpressionVisitor : ExpressionVisitor private SelectExpression _selectExpression; private bool _clientEval; + private readonly IDictionary _projectionMapping = new Dictionary(); + private readonly Stack _projectionMembers = new Stack(); public RelationalProjectionBindingExpressionVisitor( @@ -96,7 +98,7 @@ public override Expression Visit(Expression expression) case MaterializeCollectionNavigationExpression materializeCollectionNavigationExpression: return _selectExpression.AddCollectionProjection( _queryableMethodTranslatingExpressionVisitor.TranslateSubquery( - materializeCollectionNavigationExpression.Subquery), + materializeCollectionNavigationExpression.Subquery), materializeCollectionNavigationExpression.Navigation, null); case MethodCallExpression methodCallExpression: @@ -107,7 +109,8 @@ public override Expression Visit(Expression expression) { var elementType = methodCallExpression.Method.GetGenericArguments()[0]; - var result = _queryableMethodTranslatingExpressionVisitor.TranslateSubquery(methodCallExpression.Arguments[0]); + var result = _queryableMethodTranslatingExpressionVisitor.TranslateSubquery( + methodCallExpression.Arguments[0]); return _selectExpression.AddCollectionProjection(result, null, elementType); } @@ -129,17 +132,17 @@ static bool IsAggregateResultWithCustomShaper(MethodInfo method) } return QueryableMethods.IsAverageWithoutSelector(method) - || QueryableMethods.IsAverageWithSelector(method) - || method == QueryableMethods.MaxWithoutSelector - || method == QueryableMethods.MaxWithSelector - || method == QueryableMethods.MinWithoutSelector - || method == QueryableMethods.MinWithSelector - || QueryableMethods.IsSumWithoutSelector(method) - || QueryableMethods.IsSumWithSelector(method); + || QueryableMethods.IsAverageWithSelector(method) + || method == QueryableMethods.MaxWithoutSelector + || method == QueryableMethods.MaxWithSelector + || method == QueryableMethods.MinWithoutSelector + || method == QueryableMethods.MinWithSelector + || QueryableMethods.IsSumWithoutSelector(method) + || QueryableMethods.IsSumWithSelector(method); } if (!(subquery.ShaperExpression is ProjectionBindingExpression - || IsAggregateResultWithCustomShaper(methodCallExpression.Method))) + || IsAggregateResultWithCustomShaper(methodCallExpression.Method))) { return _selectExpression.AddSingleProjection(subquery); } @@ -152,7 +155,8 @@ static bool IsAggregateResultWithCustomShaper(MethodInfo method) var translation = _sqlTranslator.Translate(expression); return translation == null ? base.Visit(expression) - : new ProjectionBindingExpression(_selectExpression, _selectExpression.AddToProjection(translation), expression.Type); + : new ProjectionBindingExpression( + _selectExpression, _selectExpression.AddToProjection(translation), expression.Type); } else { @@ -201,13 +205,11 @@ protected override Expression VisitExtension(Expression extensionExpression) return entityShaperExpression.Update( new ProjectionBindingExpression(_selectExpression, _selectExpression.AddToProjection(entityProjectionExpression))); } - else - { - _projectionMapping[_projectionMembers.Peek()] = entityProjectionExpression; - return entityShaperExpression.Update( - new ProjectionBindingExpression(_selectExpression, _projectionMembers.Peek(), typeof(ValueBuffer))); - } + _projectionMapping[_projectionMembers.Peek()] = entityProjectionExpression; + + return entityShaperExpression.Update( + new ProjectionBindingExpression(_selectExpression, _projectionMembers.Peek(), typeof(ValueBuffer))); } if (extensionExpression is IncludeExpression includeExpression) @@ -250,6 +252,7 @@ protected override Expression VisitNew(NewExpression newExpression) { return null; } + _projectionMembers.Pop(); } } diff --git a/src/EFCore.Relational/Query/Internal/RelationalQueryContextFactory.cs b/src/EFCore.Relational/Query/Internal/RelationalQueryContextFactory.cs index d7af2685bce..028ff988d2c 100644 --- a/src/EFCore.Relational/Query/Internal/RelationalQueryContextFactory.cs +++ b/src/EFCore.Relational/Query/Internal/RelationalQueryContextFactory.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; -using Microsoft.EntityFrameworkCore.Storage; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.Query.Internal @@ -12,8 +11,8 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal /// A factory for instances. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -24,7 +23,7 @@ public class RelationalQueryContextFactory : IQueryContextFactory private readonly RelationalQueryContextDependencies _relationalDependencies; /// - /// Creates a new instance using the given dependencies. + /// Creates a new instance using the given dependencies. /// /// The dependencies to use. /// Relational-specific dependencies. @@ -37,7 +36,7 @@ public RelationalQueryContextFactory( } /// - /// Creates a new . + /// Creates a new . /// /// /// A QueryContext. diff --git a/src/EFCore.Relational/Query/Internal/RelationalQueryTranslationPostprocessorFactory.cs b/src/EFCore.Relational/Query/Internal/RelationalQueryTranslationPostprocessorFactory.cs index 51670dd359b..f39a2a71199 100644 --- a/src/EFCore.Relational/Query/Internal/RelationalQueryTranslationPostprocessorFactory.cs +++ b/src/EFCore.Relational/Query/Internal/RelationalQueryTranslationPostprocessorFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.Extensions.DependencyInjection; @@ -7,12 +7,12 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal { /// /// - /// A factory for creating instances. + /// A factory for creating instances. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class RelationalQueryTranslationPostprocessorFactory : IQueryTranslationPostprocessorFactory diff --git a/src/EFCore.Relational/Query/Internal/RelationalQueryTranslationPreprocessorFactory.cs b/src/EFCore.Relational/Query/Internal/RelationalQueryTranslationPreprocessorFactory.cs index 563546e5035..b536580b009 100644 --- a/src/EFCore.Relational/Query/Internal/RelationalQueryTranslationPreprocessorFactory.cs +++ b/src/EFCore.Relational/Query/Internal/RelationalQueryTranslationPreprocessorFactory.cs @@ -7,12 +7,12 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal { /// /// - /// A factory for creating instances. + /// A factory for creating instances. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class RelationalQueryTranslationPreprocessorFactory : IQueryTranslationPreprocessorFactory @@ -29,6 +29,6 @@ public RelationalQueryTranslationPreprocessorFactory( } public virtual QueryTranslationPreprocessor Create(QueryCompilationContext queryCompilationContext) - => 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 3d81301871f..58e89303c5c 100644 --- a/src/EFCore.Relational/Query/Internal/RelationalQueryableMethodTranslatingExpressionVisitorFactory.cs +++ b/src/EFCore.Relational/Query/Internal/RelationalQueryableMethodTranslatingExpressionVisitorFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.Metadata; @@ -8,12 +8,12 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal { /// /// - /// A factory for creating instances. + /// A factory for creating instances. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class RelationalQueryableMethodTranslatingExpressionVisitorFactory : IQueryableMethodTranslatingExpressionVisitorFactory diff --git a/src/EFCore.Relational/Query/Internal/RelationalShapedQueryCompilingExpressionVisitorFactory.cs b/src/EFCore.Relational/Query/Internal/RelationalShapedQueryCompilingExpressionVisitorFactory.cs index 3fe4584dc38..1dde1662282 100644 --- a/src/EFCore.Relational/Query/Internal/RelationalShapedQueryCompilingExpressionVisitorFactory.cs +++ b/src/EFCore.Relational/Query/Internal/RelationalShapedQueryCompilingExpressionVisitorFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.Extensions.DependencyInjection; @@ -7,12 +7,12 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal { /// /// - /// A factory for creating instances. + /// A factory for creating instances. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class RelationalShapedQueryCompilingExpressionVisitorFactory : IShapedQueryCompilingExpressionVisitorFactory diff --git a/src/EFCore.Relational/Query/Internal/RelationalSqlTranslatingExpressionVisitorDependencies.cs b/src/EFCore.Relational/Query/Internal/RelationalSqlTranslatingExpressionVisitorDependencies.cs index 8c64275ec91..7bc330f75a8 100644 --- a/src/EFCore.Relational/Query/Internal/RelationalSqlTranslatingExpressionVisitorDependencies.cs +++ b/src/EFCore.Relational/Query/Internal/RelationalSqlTranslatingExpressionVisitorDependencies.cs @@ -25,9 +25,9 @@ namespace Microsoft.EntityFrameworkCore.Query /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public sealed class RelationalSqlTranslatingExpressionVisitorDependencies @@ -87,7 +87,8 @@ public RelationalSqlTranslatingExpressionVisitorDependencies( /// A replacement for the current dependency of this type. /// A new parameter object with the given service replaced. public RelationalSqlTranslatingExpressionVisitorDependencies With([NotNull] ISqlExpressionFactory sqlExpressionFactory) - => new RelationalSqlTranslatingExpressionVisitorDependencies(sqlExpressionFactory, MemberTranslatorProvider, MethodCallTranslatorProvider); + => new RelationalSqlTranslatingExpressionVisitorDependencies( + sqlExpressionFactory, MemberTranslatorProvider, MethodCallTranslatorProvider); /// /// Clones this dependency parameter object with one service replaced. @@ -95,14 +96,17 @@ public RelationalSqlTranslatingExpressionVisitorDependencies With([NotNull] ISql /// A replacement for the current dependency of this type. /// A new parameter object with the given service replaced. public RelationalSqlTranslatingExpressionVisitorDependencies With([NotNull] IMemberTranslatorProvider memberTranslatorProvider) - => new RelationalSqlTranslatingExpressionVisitorDependencies(SqlExpressionFactory, memberTranslatorProvider, MethodCallTranslatorProvider); + => new RelationalSqlTranslatingExpressionVisitorDependencies( + SqlExpressionFactory, memberTranslatorProvider, MethodCallTranslatorProvider); /// /// Clones this dependency parameter object with one service replaced. /// /// A replacement for the current dependency of this type. /// A new parameter object with the given service replaced. - public RelationalSqlTranslatingExpressionVisitorDependencies With([NotNull] IMethodCallTranslatorProvider methodCallTranslatorProvider) - => new RelationalSqlTranslatingExpressionVisitorDependencies(SqlExpressionFactory, MemberTranslatorProvider, methodCallTranslatorProvider); + public RelationalSqlTranslatingExpressionVisitorDependencies With( + [NotNull] IMethodCallTranslatorProvider methodCallTranslatorProvider) + => new RelationalSqlTranslatingExpressionVisitorDependencies( + SqlExpressionFactory, MemberTranslatorProvider, methodCallTranslatorProvider); } } diff --git a/src/EFCore.Relational/Query/Internal/SelectExpressionProjectionApplyingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/SelectExpressionProjectionApplyingExpressionVisitor.cs index 53b64a8c01a..2be4e1c47bc 100644 --- a/src/EFCore.Relational/Query/Internal/SelectExpressionProjectionApplyingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/Internal/SelectExpressionProjectionApplyingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq.Expressions; @@ -17,6 +17,5 @@ protected override Expression VisitExtension(Expression node) return base.VisitExtension(node); } - } } diff --git a/src/EFCore.Relational/Query/Internal/SqlExpressionOptimizingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/SqlExpressionOptimizingExpressionVisitor.cs index 7517df3111c..a08fe7f0589 100644 --- a/src/EFCore.Relational/Query/Internal/SqlExpressionOptimizingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/Internal/SqlExpressionOptimizingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq.Expressions; diff --git a/src/EFCore.Relational/Query/Internal/StringMethodTranslator.cs b/src/EFCore.Relational/Query/Internal/StringMethodTranslator.cs index fc41626e998..f39857765f0 100644 --- a/src/EFCore.Relational/Query/Internal/StringMethodTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/StringMethodTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; diff --git a/src/EFCore.Relational/Query/Internal/TableAliasUniquifyingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/TableAliasUniquifyingExpressionVisitor.cs index d9a0a845844..95deea9123a 100644 --- a/src/EFCore.Relational/Query/Internal/TableAliasUniquifyingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/Internal/TableAliasUniquifyingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -12,6 +12,7 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal public class TableAliasUniquifyingExpressionVisitor : ExpressionVisitor { private readonly ISet _usedAliases = new HashSet(StringComparer.OrdinalIgnoreCase); + private readonly ISet _visitedTableExpressionBases = new HashSet(ReferenceEqualityComparer.Instance); diff --git a/src/EFCore.Relational/Query/QuerySqlGenerator.cs b/src/EFCore.Relational/Query/QuerySqlGenerator.cs index 1bc9c415eee..2f47feda150 100644 --- a/src/EFCore.Relational/Query/QuerySqlGenerator.cs +++ b/src/EFCore.Relational/Query/QuerySqlGenerator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -93,19 +93,21 @@ protected override Expression VisitSqlFragment(SqlFragmentExpression sqlFragment private bool IsNonComposedSetOperation(SelectExpression selectExpression) => selectExpression.Offset == null - && selectExpression.Limit == null - && !selectExpression.IsDistinct - && selectExpression.Predicate == null - && selectExpression.Having == null - && selectExpression.Orderings.Count == 0 - && selectExpression.GroupBy.Count == 0 - && selectExpression.Tables.Count == 1 - && selectExpression.Tables[0] is SetOperationBase setOperation - && selectExpression.Projection.Count == setOperation.Source1.Projection.Count - && selectExpression.Projection.Select((pe, index) => pe.Expression is ColumnExpression column - && column.Table.Equals(setOperation) - && string.Equals(column.Name, setOperation.Source1.Projection[index].Alias, StringComparison.OrdinalIgnoreCase)) - .All(e => e); + && selectExpression.Limit == null + && !selectExpression.IsDistinct + && selectExpression.Predicate == null + && selectExpression.Having == null + && selectExpression.Orderings.Count == 0 + && selectExpression.GroupBy.Count == 0 + && selectExpression.Tables.Count == 1 + && selectExpression.Tables[0] is SetOperationBase setOperation + && selectExpression.Projection.Count == setOperation.Source1.Projection.Count + && selectExpression.Projection.Select( + (pe, index) => pe.Expression is ColumnExpression column + && column.Table.Equals(setOperation) + && string.Equals( + column.Name, setOperation.Source1.Projection[index].Alias, StringComparison.OrdinalIgnoreCase)) + .All(e => e); protected override Expression VisitSelect(SelectExpression selectExpression) { @@ -262,7 +264,7 @@ private void GenerateFromSql(FromSqlExpression fromSqlExpression) switch (fromSqlExpression.Arguments) { case ConstantExpression constantExpression - when constantExpression.Value is CompositeRelationalParameter compositeRelationalParameter: + when constantExpression.Value is CompositeRelationalParameter compositeRelationalParameter: { var subParameters = compositeRelationalParameter.RelationalParameters; substitutions = new string[subParameters.Count]; @@ -277,7 +279,7 @@ private void GenerateFromSql(FromSqlExpression fromSqlExpression) } case ConstantExpression constantExpression - when constantExpression.Value is object[] constantValues: + when constantExpression.Value is object[] constantValues: { substitutions = new string[constantValues.Length]; for (var i = 0; i < constantValues.Length; i++) @@ -373,8 +375,8 @@ protected override Expression VisitSqlBinary(SqlBinaryExpression sqlBinaryExpres private bool RequiresBrackets(SqlExpression expression) { return expression is SqlBinaryExpression sqlBinary - && sqlBinary.OperatorType != ExpressionType.Coalesce - || expression is LikeExpression; + && sqlBinary.OperatorType != ExpressionType.Coalesce + || expression is LikeExpression; } protected override Expression VisitSqlConstant(SqlConstantExpression sqlConstantExpression) @@ -490,45 +492,47 @@ protected override Expression VisitSqlUnary(SqlUnaryExpression sqlUnaryExpressio { _relationalCommandBuilder.Append("("); } + Visit(sqlUnaryExpression.Operand); if (requiresBrackets) { _relationalCommandBuilder.Append(")"); } + _relationalCommandBuilder.Append(" AS "); _relationalCommandBuilder.Append(sqlUnaryExpression.TypeMapping.StoreType); _relationalCommandBuilder.Append(")"); + break; } - break; case ExpressionType.Not: { _relationalCommandBuilder.Append("NOT ("); Visit(sqlUnaryExpression.Operand); _relationalCommandBuilder.Append(")"); + break; } - break; case ExpressionType.Equal: { Visit(sqlUnaryExpression.Operand); _relationalCommandBuilder.Append(" IS NULL"); + break; } - break; case ExpressionType.NotEqual: { Visit(sqlUnaryExpression.Operand); _relationalCommandBuilder.Append(" IS NOT NULL"); + break; } - break; case ExpressionType.Negate: { _relationalCommandBuilder.Append("-"); Visit(sqlUnaryExpression.Operand); + break; } - break; } return sqlUnaryExpression; @@ -767,6 +771,7 @@ protected virtual void GenerateSetOperationOperand(SetOperationBase setOperation { Visit(operand); } + _relationalCommandBuilder.AppendLine().Append(")"); } else @@ -782,6 +787,7 @@ private void GenerateSetOperationHelper(SetOperationBase setOperation) { GenerateSetOperation(setOperation); } + _relationalCommandBuilder.AppendLine() .Append(")") .Append(AliasSeparator) diff --git a/src/EFCore.Relational/Query/QuerySqlGeneratorDependencies.cs b/src/EFCore.Relational/Query/QuerySqlGeneratorDependencies.cs index edca49b24ee..5a6d78f67ca 100644 --- a/src/EFCore.Relational/Query/QuerySqlGeneratorDependencies.cs +++ b/src/EFCore.Relational/Query/QuerySqlGeneratorDependencies.cs @@ -26,9 +26,9 @@ namespace Microsoft.EntityFrameworkCore.Query /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public sealed class QuerySqlGeneratorDependencies @@ -70,7 +70,7 @@ public QuerySqlGeneratorDependencies( public IRelationalCommandBuilderFactory RelationalCommandBuilderFactory { get; } /// - /// SQL generation helpers. + /// SQL generation helpers. /// public ISqlGenerationHelper SqlGenerationHelper { get; } diff --git a/src/EFCore.Relational/Query/RelationalCollectionShaperExpression.cs b/src/EFCore.Relational/Query/RelationalCollectionShaperExpression.cs index 14359cf479e..3ee4e724800 100644 --- a/src/EFCore.Relational/Query/RelationalCollectionShaperExpression.cs +++ b/src/EFCore.Relational/Query/RelationalCollectionShaperExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -53,9 +53,9 @@ public virtual RelationalCollectionShaperExpression Update( Expression parentIdentifier, Expression outerIdentifier, Expression selfIdentifier, Expression innerShaper) { return parentIdentifier != ParentIdentifier - || outerIdentifier != OuterIdentifier - || selfIdentifier != SelfIdentifier - || innerShaper != InnerShaper + || outerIdentifier != OuterIdentifier + || selfIdentifier != SelfIdentifier + || innerShaper != InnerShaper ? new RelationalCollectionShaperExpression( CollectionId, parentIdentifier, outerIdentifier, selfIdentifier, innerShaper, Navigation, ElementType) : this; @@ -80,7 +80,6 @@ public virtual void Print(ExpressionPrinter expressionPrinter) expressionPrinter.Visit(InnerShaper); expressionPrinter.AppendLine(); expressionPrinter.AppendLine($"Navigation: {Navigation?.Name}"); - } } } diff --git a/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGenerator.cs b/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGenerator.cs index d3b36b6d9a7..02379782940 100644 --- a/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGenerator.cs +++ b/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGenerator.cs @@ -20,8 +20,8 @@ namespace Microsoft.EntityFrameworkCore.Query /// not used in application code. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGeneratorDependencies.cs b/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGeneratorDependencies.cs index 30fb8791247..cc05d4b58ce 100644 --- a/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGeneratorDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalCompiledQueryCacheKeyGeneratorDependencies.cs @@ -25,8 +25,8 @@ namespace Microsoft.EntityFrameworkCore.Query /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Relational/Query/RelationalEvaluatableExpressionFilter.cs b/src/EFCore.Relational/Query/RelationalEvaluatableExpressionFilter.cs index 43b75784d44..9cb272bb41d 100644 --- a/src/EFCore.Relational/Query/RelationalEvaluatableExpressionFilter.cs +++ b/src/EFCore.Relational/Query/RelationalEvaluatableExpressionFilter.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Linq.Expressions; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata; @@ -15,16 +14,16 @@ namespace Microsoft.EntityFrameworkCore.Query /// Represents a filter for evaluatable expressions. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class RelationalEvaluatableExpressionFilter : EvaluatableExpressionFilter { /// /// - /// Creates a new instance. + /// Creates a new instance. /// /// /// This type is typically used by database providers (and other extensions). It is generally diff --git a/src/EFCore.Relational/Query/RelationalEvaluatableExpressionFilterDependencies.cs b/src/EFCore.Relational/Query/RelationalEvaluatableExpressionFilterDependencies.cs index 6ef8dac92bc..0fad0324095 100644 --- a/src/EFCore.Relational/Query/RelationalEvaluatableExpressionFilterDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalEvaluatableExpressionFilterDependencies.cs @@ -23,9 +23,9 @@ namespace Microsoft.EntityFrameworkCore.Query /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public sealed class RelationalEvaluatableExpressionFilterDependencies diff --git a/src/EFCore.Relational/Query/RelationalMemberTranslatorProvider.cs b/src/EFCore.Relational/Query/RelationalMemberTranslatorProvider.cs index 3a79755e119..1f7ca897f62 100644 --- a/src/EFCore.Relational/Query/RelationalMemberTranslatorProvider.cs +++ b/src/EFCore.Relational/Query/RelationalMemberTranslatorProvider.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -20,10 +20,7 @@ public RelationalMemberTranslatorProvider(RelationalMemberTranslatorProviderDepe _plugins.AddRange(dependencies.Plugins.SelectMany(p => p.Translators)); _translators .AddRange( - new[] - { - new NullableMemberTranslator(dependencies.SqlExpressionFactory), - }); + new[] { new NullableMemberTranslator(dependencies.SqlExpressionFactory) }); } public virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType) diff --git a/src/EFCore.Relational/Query/RelationalMemberTranslatorProviderDependencies.cs b/src/EFCore.Relational/Query/RelationalMemberTranslatorProviderDependencies.cs index 9c38bdfad24..8c9d9645383 100644 --- a/src/EFCore.Relational/Query/RelationalMemberTranslatorProviderDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalMemberTranslatorProviderDependencies.cs @@ -26,9 +26,9 @@ namespace Microsoft.EntityFrameworkCore.Query /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public sealed class RelationalMemberTranslatorProviderDependencies diff --git a/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProvider.cs b/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProvider.cs index f2114375457..d3f1801becb 100644 --- a/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProvider.cs +++ b/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProvider.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; @@ -24,30 +24,32 @@ public RelationalMethodCallTranslatorProvider([NotNull] RelationalMethodCallTran var sqlExpressionFactory = dependencies.SqlExpressionFactory; _translators.AddRange( - new IMethodCallTranslator[] { + new IMethodCallTranslator[] + { new EqualsTranslator(sqlExpressionFactory), new StringMethodTranslator(sqlExpressionFactory), new ContainsTranslator(sqlExpressionFactory), new LikeTranslator(sqlExpressionFactory), new EnumHasFlagTranslator(sqlExpressionFactory), new GetValueOrDefaultTranslator(sqlExpressionFactory), - new ComparisonTranslator(sqlExpressionFactory), + new ComparisonTranslator(sqlExpressionFactory) }); _sqlExpressionFactory = sqlExpressionFactory; } - public virtual SqlExpression Translate(IModel model, SqlExpression instance, MethodInfo method, IReadOnlyList arguments) + public virtual SqlExpression Translate( + IModel model, SqlExpression instance, MethodInfo method, IReadOnlyList arguments) { var dbFunction = model.FindDbFunction(method); if (dbFunction != null) { return dbFunction.Translation?.Invoke( - arguments.Select(e => _sqlExpressionFactory.ApplyDefaultTypeMapping(e)).ToList()) - ?? _sqlExpressionFactory.Function( - dbFunction.Schema, - dbFunction.Name, - arguments, - method.ReturnType); + arguments.Select(e => _sqlExpressionFactory.ApplyDefaultTypeMapping(e)).ToList()) + ?? _sqlExpressionFactory.Function( + dbFunction.Schema, + dbFunction.Name, + arguments, + method.ReturnType); } return _plugins.Concat(_translators) diff --git a/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProviderDependencies.cs b/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProviderDependencies.cs index 3eb7af4defe..2450b641862 100644 --- a/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProviderDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProviderDependencies.cs @@ -26,9 +26,9 @@ namespace Microsoft.EntityFrameworkCore.Query /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public sealed class RelationalMethodCallTranslatorProviderDependencies diff --git a/src/EFCore.Relational/Query/RelationalQueryContextDependencies.cs b/src/EFCore.Relational/Query/RelationalQueryContextDependencies.cs index 8253e6ebe75..ed335407559 100644 --- a/src/EFCore.Relational/Query/RelationalQueryContextDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalQueryContextDependencies.cs @@ -26,8 +26,8 @@ namespace Microsoft.EntityFrameworkCore.Query /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessorDependencies.cs b/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessorDependencies.cs index d41bc31093c..fe7a2e80f62 100644 --- a/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessorDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessorDependencies.cs @@ -25,9 +25,9 @@ namespace Microsoft.EntityFrameworkCore.Query /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public sealed class RelationalQueryTranslationPostprocessorDependencies @@ -60,7 +60,7 @@ public RelationalQueryTranslationPostprocessorDependencies( } /// - /// The SQL expression factory. + /// The SQL expression factory. /// public ISqlExpressionFactory SqlExpressionFactory { get; } diff --git a/src/EFCore.Relational/Query/RelationalQueryTranslationPreprocessorDependencies.cs b/src/EFCore.Relational/Query/RelationalQueryTranslationPreprocessorDependencies.cs index ab9968b9e9e..51e2b41f256 100644 --- a/src/EFCore.Relational/Query/RelationalQueryTranslationPreprocessorDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalQueryTranslationPreprocessorDependencies.cs @@ -23,9 +23,9 @@ namespace Microsoft.EntityFrameworkCore.Query /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public sealed class RelationalQueryTranslationPreprocessorDependencies diff --git a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs index 0d6249ffd8a..fcc640adf3c 100644 --- a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -95,12 +95,12 @@ private static ShapedQueryExpression CreateShapedQueryExpression(IEntityType ent => new ShapedQueryExpression( selectExpression, new EntityShaperExpression( - entityType, - new ProjectionBindingExpression( - selectExpression, - new ProjectionMember(), - typeof(ValueBuffer)), - false)); + entityType, + new ProjectionBindingExpression( + selectExpression, + new ProjectionMember(), + typeof(ValueBuffer)), + false)); protected override ShapedQueryExpression TranslateAll(ShapedQueryExpression source, LambdaExpression predicate) { @@ -155,7 +155,7 @@ protected override ShapedQueryExpression TranslateAverage(ShapedQueryExpression selectExpression.PrepareForAggregate(); var newSelector = selector == null - || selector.Body == selector.Parameters[0] + || selector.Body == selector.Parameters[0] ? selectExpression.GetMappedProjection(new ProjectionMember()) : RemapLambdaBody(source, selector); @@ -224,10 +224,7 @@ protected override ShapedQueryExpression TranslateCount(ShapedQueryExpression so var translation = _sqlTranslator.TranslateCount(); - var projectionMapping = new Dictionary - { - { new ProjectionMember(), translation } - }; + var projectionMapping = new Dictionary { { new ProjectionMember(), translation } }; selectExpression.ClearOrdering(); selectExpression.ReplaceProjectionMapping(projectionMapping); @@ -256,7 +253,8 @@ protected override ShapedQueryExpression TranslateDistinct(ShapedQueryExpression return source; } - protected override ShapedQueryExpression TranslateElementAtOrDefault(ShapedQueryExpression source, Expression index, bool returnDefault) + protected override ShapedQueryExpression TranslateElementAtOrDefault( + ShapedQueryExpression source, Expression index, bool returnDefault) => throw new InvalidOperationException(CoreStrings.TranslationFailed(index.Print())); protected override ShapedQueryExpression TranslateExcept(ShapedQueryExpression source1, ShapedQueryExpression source2) @@ -265,7 +263,8 @@ protected override ShapedQueryExpression TranslateExcept(ShapedQueryExpression s return source1; } - protected override ShapedQueryExpression TranslateFirstOrDefault(ShapedQueryExpression source, LambdaExpression predicate, Type returnType, bool returnDefault) + protected override ShapedQueryExpression TranslateFirstOrDefault( + ShapedQueryExpression source, LambdaExpression predicate, Type returnType, bool returnDefault) { if (predicate != null) { @@ -318,10 +317,11 @@ protected override ShapedQueryExpression TranslateGroupBy( var original2 = resultSelector.Parameters[1]; var newResultSelectorBody = new ReplacingExpressionVisitor( - new Dictionary { - { original1, keyAccessExpression }, - { original2, source.ShaperExpression } - }).Visit(resultSelector.Body); + new Dictionary + { + { original1, keyAccessExpression }, { original2, source.ShaperExpression } + }) + .Visit(resultSelector.Body); newResultSelectorBody = ExpandWeakEntities(selectExpression, newResultSelectorBody); @@ -330,8 +330,9 @@ protected override ShapedQueryExpression TranslateGroupBy( return source; } - throw new InvalidOperationException(CoreStrings.TranslationFailed( - keySelector.Print() + "; " + elementSelector.Print() + "; " + resultSelector.Print())); + throw new InvalidOperationException( + CoreStrings.TranslationFailed( + keySelector.Print() + "; " + elementSelector.Print() + "; " + resultSelector.Print())); } private Expression TranslateGroupingKey(Expression expression) @@ -392,7 +393,9 @@ private Expression TranslateGroupingKey(Expression expression) } } - protected override ShapedQueryExpression TranslateGroupJoin(ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, LambdaExpression resultSelector) + protected override ShapedQueryExpression TranslateGroupJoin( + ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, + LambdaExpression resultSelector) { //var outerSelectExpression = (SelectExpression)outer.QueryExpression; //if (outerSelectExpression.Limit != null @@ -435,8 +438,9 @@ protected override ShapedQueryExpression TranslateGroupJoin(ShapedQueryExpressio //} // See #17236 - throw new InvalidOperationException(CoreStrings.TranslationFailed( - outerKeySelector.Print() + "; " + innerKeySelector.Print() + "; " + resultSelector.Print())); + throw new InvalidOperationException( + CoreStrings.TranslationFailed( + outerKeySelector.Print() + "; " + innerKeySelector.Print() + "; " + resultSelector.Print())); } protected override ShapedQueryExpression TranslateIntersect(ShapedQueryExpression source1, ShapedQueryExpression source2) @@ -470,11 +474,14 @@ protected override ShapedQueryExpression TranslateJoin( } // See #17236 - throw new InvalidOperationException(CoreStrings.TranslationFailed( - outerKeySelector.Print() + "; " + innerKeySelector.Print() + "; " + resultSelector.Print())); + throw new InvalidOperationException( + CoreStrings.TranslationFailed( + outerKeySelector.Print() + "; " + innerKeySelector.Print() + "; " + resultSelector.Print())); } - protected override ShapedQueryExpression TranslateLeftJoin(ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, LambdaExpression resultSelector) + protected override ShapedQueryExpression TranslateLeftJoin( + ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, + LambdaExpression resultSelector) { var joinPredicate = CreateJoinPredicate(outer, outerKeySelector, inner, innerKeySelector); if (joinPredicate != null) @@ -494,8 +501,9 @@ protected override ShapedQueryExpression TranslateLeftJoin(ShapedQueryExpression } // See #17236 - throw new InvalidOperationException(CoreStrings.TranslationFailed( - outerKeySelector.Print() + "; " + innerKeySelector.Print() + "; " + resultSelector.Print())); + throw new InvalidOperationException( + CoreStrings.TranslationFailed( + outerKeySelector.Print() + "; " + innerKeySelector.Print() + "; " + resultSelector.Print())); } private SqlBinaryExpression CreateJoinPredicate( @@ -586,10 +594,7 @@ protected override ShapedQueryExpression TranslateLongCount(ShapedQueryExpressio } var translation = _sqlTranslator.TranslateLongCount(); - var projectionMapping = new Dictionary - { - { new ProjectionMember(), translation } - }; + var projectionMapping = new Dictionary { { new ProjectionMember(), translation } }; selectExpression.ClearOrdering(); selectExpression.ReplaceProjectionMapping(projectionMapping); @@ -604,7 +609,7 @@ protected override ShapedQueryExpression TranslateMax(ShapedQueryExpression sour selectExpression.PrepareForAggregate(); var newSelector = selector == null - || selector.Body == selector.Parameters[0] + || selector.Body == selector.Parameters[0] ? selectExpression.GetMappedProjection(new ProjectionMember()) : RemapLambdaBody(source, selector); @@ -619,9 +624,9 @@ protected override ShapedQueryExpression TranslateMin(ShapedQueryExpression sour selectExpression.PrepareForAggregate(); var newSelector = selector == null - || selector.Body == selector.Parameters[0] - ? selectExpression.GetMappedProjection(new ProjectionMember()) - : RemapLambdaBody(source, selector); + || selector.Body == selector.Parameters[0] + ? selectExpression.GetMappedProjection(new ProjectionMember()) + : RemapLambdaBody(source, selector); var projection = _sqlTranslator.TranslateMin(newSelector); @@ -657,9 +662,11 @@ protected override ShapedQueryExpression TranslateOfType(ShapedQueryExpression s var discriminatorColumn = entityProjectionExpression.BindProperty(entityType.GetDiscriminatorProperty()); var predicate = concreteEntityTypes.Count == 1 - ? _sqlExpressionFactory.Equal(discriminatorColumn, + ? _sqlExpressionFactory.Equal( + discriminatorColumn, _sqlExpressionFactory.Constant(concreteEntityTypes[0].GetDiscriminatorValue())) - : (SqlExpression)_sqlExpressionFactory.In(discriminatorColumn, + : (SqlExpression)_sqlExpressionFactory.In( + discriminatorColumn, _sqlExpressionFactory.Constant(concreteEntityTypes.Select(et => et.GetDiscriminatorValue())), negated: false); @@ -667,7 +674,8 @@ protected override ShapedQueryExpression TranslateOfType(ShapedQueryExpression s var projectionMember = projectionBindingExpression.ProjectionMember; - Debug.Assert(new ProjectionMember().Equals(projectionMember), + Debug.Assert( + new ProjectionMember().Equals(projectionMember), "Invalid ProjectionMember when processing OfType"); var entityProjection = (EntityProjectionExpression)selectExpression.GetMappedProjection(projectionMember); @@ -675,7 +683,7 @@ protected override ShapedQueryExpression TranslateOfType(ShapedQueryExpression s selectExpression.ReplaceProjectionMapping( new Dictionary { - { projectionMember, entityProjection.UpdateEntityType(derivedType)} + { projectionMember, entityProjection.UpdateEntityType(derivedType) } }); source.ShaperExpression = entityShaperExpression.WithEntityType(derivedType); @@ -689,7 +697,8 @@ protected override ShapedQueryExpression TranslateOfType(ShapedQueryExpression s return null; } - protected override ShapedQueryExpression TranslateOrderBy(ShapedQueryExpression source, LambdaExpression keySelector, bool ascending) + protected override ShapedQueryExpression TranslateOrderBy( + ShapedQueryExpression source, LambdaExpression keySelector, bool ascending) { var translation = TranslateLambdaExpression(source, keySelector); if (translation != null) @@ -749,7 +758,7 @@ protected override ShapedQueryExpression TranslateSelectMany( else { ((SelectExpression)source.QueryExpression).AddCrossApply( - (SelectExpression)inner.QueryExpression, transparentIdentifierType); + (SelectExpression)inner.QueryExpression, transparentIdentifierType); } return TranslateResultSelectorForJoin( @@ -784,8 +793,9 @@ protected override ShapedQueryExpression TranslateSelectMany( } // See #17236 - throw new InvalidOperationException(CoreStrings.TranslationFailed( - collectionSelector.Print() + "; " + resultSelector.Print())); + throw new InvalidOperationException( + CoreStrings.TranslationFailed( + collectionSelector.Print() + "; " + resultSelector.Print())); } private class CorrelationFindingExpressionVisitor : ExpressionVisitor @@ -834,17 +844,13 @@ protected override ShapedQueryExpression TranslateSelectMany(ShapedQueryExpressi { var innerParameter = Expression.Parameter(selector.ReturnType.TryGetSequenceType(), "i"); var resultSelector = Expression.Lambda( - innerParameter, - new[] - { - Expression.Parameter(source.Type.TryGetSequenceType()), - innerParameter - }); + innerParameter, Expression.Parameter(source.Type.TryGetSequenceType()), innerParameter); return TranslateSelectMany(source, selector, resultSelector); } - protected override ShapedQueryExpression TranslateSingleOrDefault(ShapedQueryExpression source, LambdaExpression predicate, Type returnType, bool returnDefault) + protected override ShapedQueryExpression TranslateSingleOrDefault( + ShapedQueryExpression source, LambdaExpression predicate, Type returnType, bool returnDefault) { if (predicate != null) { @@ -885,7 +891,7 @@ protected override ShapedQueryExpression TranslateSum(ShapedQueryExpression sour var selectExpression = (SelectExpression)source.QueryExpression; selectExpression.PrepareForAggregate(); var newSelector = selector == null - || selector.Body == selector.Parameters[0] + || selector.Body == selector.Parameters[0] ? selectExpression.GetMappedProjection(new ProjectionMember()) : RemapLambdaBody(source, selector); @@ -1022,8 +1028,8 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp source = Visit(source); if (source is EntityShaperExpression || (source is UnaryExpression innerUnaryExpression - && innerUnaryExpression.NodeType == ExpressionType.Convert - && innerUnaryExpression.Operand is EntityShaperExpression)) + && innerUnaryExpression.NodeType == ExpressionType.Convert + && innerUnaryExpression.Operand is EntityShaperExpression)) { var collectionNavigation = Expand(source, MemberIdentity.Create(navigationName)); if (collectionNavigation != null) @@ -1149,7 +1155,8 @@ private Expression Expand(Expression source, MemberIdentity member) var joinPredicate = _sqlTranslator.Translate(Expression.Equal(outerKey, innerKey)); _selectExpression.AddLeftJoin(innerSelectExpression, joinPredicate, null); var leftJoinTable = ((LeftJoinExpression)_selectExpression.Tables.Last()).Table; - innerShaper = new EntityShaperExpression(targetEntityType, + innerShaper = new EntityShaperExpression( + targetEntityType, new EntityProjectionExpression(targetEntityType, leftJoinTable, true), true); entityProjectionExpression.AddNavigationBinding(navigation, innerShaper); @@ -1164,10 +1171,7 @@ private ShapedQueryExpression AggregateResultShaper( { var selectExpression = (SelectExpression)source.QueryExpression; selectExpression.ReplaceProjectionMapping( - new Dictionary - { - { new ProjectionMember(), projection } - }); + new Dictionary { { new ProjectionMember(), projection } }); selectExpression.ClearOrdering(); diff --git a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitorDependencies.cs b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitorDependencies.cs index 5890186fff5..4421414aa05 100644 --- a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitorDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitorDependencies.cs @@ -25,9 +25,9 @@ namespace Microsoft.EntityFrameworkCore.Query /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public sealed class RelationalQueryableMethodTranslatingExpressionVisitorDependencies @@ -78,8 +78,10 @@ public RelationalQueryableMethodTranslatingExpressionVisitorDependencies( /// /// A replacement for the current dependency of this type. /// A new parameter object with the given service replaced. - public RelationalQueryableMethodTranslatingExpressionVisitorDependencies With([NotNull] IRelationalSqlTranslatingExpressionVisitorFactory relationalSqlTranslatingExpressionVisitorFactory) - => new RelationalQueryableMethodTranslatingExpressionVisitorDependencies(relationalSqlTranslatingExpressionVisitorFactory, SqlExpressionFactory); + public RelationalQueryableMethodTranslatingExpressionVisitorDependencies With( + [NotNull] IRelationalSqlTranslatingExpressionVisitorFactory relationalSqlTranslatingExpressionVisitorFactory) + => new RelationalQueryableMethodTranslatingExpressionVisitorDependencies( + relationalSqlTranslatingExpressionVisitorFactory, SqlExpressionFactory); /// /// Clones this dependency parameter object with one service replaced. @@ -87,6 +89,7 @@ public RelationalQueryableMethodTranslatingExpressionVisitorDependencies With([N /// A replacement for the current dependency of this type. /// A new parameter object with the given service replaced. public RelationalQueryableMethodTranslatingExpressionVisitorDependencies With([NotNull] ISqlExpressionFactory sqlExpressionFactory) - => new RelationalQueryableMethodTranslatingExpressionVisitorDependencies(RelationalSqlTranslatingExpressionVisitorFactory, sqlExpressionFactory); + => new RelationalQueryableMethodTranslatingExpressionVisitorDependencies( + RelationalSqlTranslatingExpressionVisitorFactory, sqlExpressionFactory); } } diff --git a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.AsyncQueryingEnumerable.cs b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.AsyncQueryingEnumerable.cs index 31b0dc5dc5c..6358dbb825c 100644 --- a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.AsyncQueryingEnumerable.cs +++ b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.AsyncQueryingEnumerable.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -90,8 +90,8 @@ public async ValueTask MoveNextAsync() if (_dataReader == null) { var selectExpression = new ParameterValueBasedSelectExpressionOptimizer( - _sqlExpressionFactory, - _parameterNameGeneratorFactory) + _sqlExpressionFactory, + _parameterNameGeneratorFactory) .Optimize(_selectExpression, _relationalQueryContext.ParameterValues); var relationalCommand = _querySqlGeneratorFactory.Create().GetCommand(selectExpression); @@ -137,7 +137,6 @@ public async ValueTask MoveNextAsync() _resultCoordinator = new ResultCoordinator(); } - var hasNext = _resultCoordinator.HasNext ?? await _dataReader.ReadAsync(); Current = default; @@ -147,7 +146,8 @@ public async ValueTask MoveNextAsync() { _resultCoordinator.ResultReady = true; _resultCoordinator.HasNext = null; - Current = _shaper(_relationalQueryContext, _dataReader.DbDataReader, + Current = _shaper( + _relationalQueryContext, _dataReader.DbDataReader, _resultCoordinator.ResultContext, _indexMap, _resultCoordinator); if (_resultCoordinator.ResultReady) { @@ -161,7 +161,8 @@ public async ValueTask MoveNextAsync() _resultCoordinator.HasNext = false; // Enumeration has ended, materialize last element _resultCoordinator.ResultReady = true; - Current = _shaper(_relationalQueryContext, _dataReader.DbDataReader, + Current = _shaper( + _relationalQueryContext, _dataReader.DbDataReader, _resultCoordinator.ResultContext, _indexMap, _resultCoordinator); break; diff --git a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.CustomShaperCompilingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.CustomShaperCompilingExpressionVisitor.cs index e1fc08df398..b1dcef3df21 100644 --- a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.CustomShaperCompilingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.CustomShaperCompilingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -95,6 +95,7 @@ private static void PopulateCollection( // nothing to materialize since no collection created return; } + void processCurrentElementRow() { var previousResultReady = resultCoordinator.ResultReady; @@ -118,6 +119,7 @@ void generateCurrentElementIfPending() resultCoordinator.HasNext = false; processCurrentElementRow(); } + collectionMaterializationContext.UpdateSelfIdentifier(null); } @@ -161,17 +163,16 @@ void generateCurrentElementIfPending() { processCurrentElementRow(); } + resultCoordinator.ResultReady = false; return; } - else - { - // Row for new element which is not first element - // So materialize the element - generateCurrentElementIfPending(); - resultCoordinator.HasNext = null; - collectionMaterializationContext.UpdateSelfIdentifier(innerKey); - } + + // Row for new element which is not first element + // So materialize the element + generateCurrentElementIfPending(); + resultCoordinator.HasNext = null; + collectionMaterializationContext.UpdateSelfIdentifier(innerKey); } else { @@ -234,6 +235,7 @@ void generateCurrentElementIfPending() resultCoordinator.HasNext = false; processCurrentElementRow(); } + collectionMaterializationContext.UpdateSelfIdentifier(null); } @@ -277,17 +279,16 @@ void generateCurrentElementIfPending() { processCurrentElementRow(); } + resultCoordinator.ResultReady = false; return; } - else - { - // Row for new element which is not first element - // So materialize the element - generateCurrentElementIfPending(); - resultCoordinator.HasNext = null; - collectionMaterializationContext.UpdateSelfIdentifier(innerKey); - } + + // Row for new element which is not first element + // So materialize the element + generateCurrentElementIfPending(); + resultCoordinator.HasNext = null; + collectionMaterializationContext.UpdateSelfIdentifier(innerKey); } else { @@ -559,7 +560,6 @@ private static LambdaExpression GenerateFixup( inverseNavigation.IsCollection() ? AddToCollectionNavigation(relatedEntityParameter, entityParameter, inverseNavigation) : AssignReferenceNavigation(relatedEntityParameter, entityParameter, inverseNavigation)); - } return Expression.Lambda(Expression.Block(typeof(void), expressions), entityParameter, relatedEntityParameter); diff --git a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.FromSqlParameterApplyingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.FromSqlParameterApplyingExpressionVisitor.cs index c8e858d27cc..cefe503d676 100644 --- a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.FromSqlParameterApplyingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.FromSqlParameterApplyingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -100,6 +100,7 @@ public override Expression Visit(Expression expression) { parameterName = dbParameter.ParameterName; } + constantValues[i] = new RawRelationalParameter(parameterName, dbParameter); } else diff --git a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.InExpressionValuesExpandingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.InExpressionValuesExpandingExpressionVisitor.cs index 74f1c1a8925..094c44a62e4 100644 --- a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.InExpressionValuesExpandingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.InExpressionValuesExpandingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections; @@ -48,8 +48,9 @@ public override Expression Visit(Expression expression) inValues.Add(value); } + + break; } - break; case SqlParameterExpression sqlParameter: { @@ -65,8 +66,9 @@ public override Expression Visit(Expression expression) inValues.Add(value); } + + break; } - break; } var updatedInExpression = inValues.Count > 0 @@ -82,16 +84,19 @@ public override Expression Visit(Expression expression) : _sqlExpressionFactory.IsNull(inExpression.Item) : null; - if (updatedInExpression != null && nullCheckExpression != null) + if (updatedInExpression != null + && nullCheckExpression != null) { return inExpression.IsNegated ? _sqlExpressionFactory.AndAlso(updatedInExpression, nullCheckExpression) : _sqlExpressionFactory.OrElse(updatedInExpression, nullCheckExpression); } - if (updatedInExpression == null && nullCheckExpression == null) + if (updatedInExpression == null + && nullCheckExpression == null) { - return _sqlExpressionFactory.Equal(_sqlExpressionFactory.Constant(true), _sqlExpressionFactory.Constant(inExpression.IsNegated)); + return _sqlExpressionFactory.Equal( + _sqlExpressionFactory.Constant(true), _sqlExpressionFactory.Constant(inExpression.IsNegated)); } return (SqlExpression)updatedInExpression ?? nullCheckExpression; diff --git a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ParameterValueBasedSelectExpressionOptimizer.cs b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ParameterValueBasedSelectExpressionOptimizer.cs index c76120f07bd..74dedca6739 100644 --- a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ParameterValueBasedSelectExpressionOptimizer.cs +++ b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ParameterValueBasedSelectExpressionOptimizer.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; diff --git a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.QueryingEnumerable.cs b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.QueryingEnumerable.cs index 6b1e8fcb26a..7c2f159314b 100644 --- a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.QueryingEnumerable.cs +++ b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.QueryingEnumerable.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -25,7 +25,8 @@ private class QueryingEnumerable : IEnumerable private readonly ISqlExpressionFactory _sqlExpressionFactory; private readonly IParameterNameGeneratorFactory _parameterNameGeneratorFactory; - public QueryingEnumerable(RelationalQueryContext relationalQueryContext, + public QueryingEnumerable( + RelationalQueryContext relationalQueryContext, IQuerySqlGeneratorFactory querySqlGeneratorFactory, ISqlExpressionFactory sqlExpressionFactory, IParameterNameGeneratorFactory parameterNameGeneratorFactory, @@ -86,8 +87,8 @@ public bool MoveNext() if (_dataReader == null) { var selectExpression = new ParameterValueBasedSelectExpressionOptimizer( - _sqlExpressionFactory, - _parameterNameGeneratorFactory) + _sqlExpressionFactory, + _parameterNameGeneratorFactory) .Optimize(_selectExpression, _relationalQueryContext.ParameterValues); var relationalCommand = _querySqlGeneratorFactory.Create().GetCommand(selectExpression); @@ -141,7 +142,8 @@ public bool MoveNext() { _resultCoordinator.ResultReady = true; _resultCoordinator.HasNext = null; - Current = _shaper(_relationalQueryContext, _dataReader.DbDataReader, + Current = _shaper( + _relationalQueryContext, _dataReader.DbDataReader, _resultCoordinator.ResultContext, _indexMap, _resultCoordinator); if (_resultCoordinator.ResultReady) { @@ -155,7 +157,8 @@ public bool MoveNext() _resultCoordinator.HasNext = false; // Enumeration has ended, materialize last element _resultCoordinator.ResultReady = true; - Current = _shaper(_relationalQueryContext, _dataReader.DbDataReader, + Current = _shaper( + _relationalQueryContext, _dataReader.DbDataReader, _resultCoordinator.ResultContext, _indexMap, _resultCoordinator); break; diff --git a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.RelationalProjectionBindingRemovingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.RelationalProjectionBindingRemovingExpressionVisitor.cs index 3fcb76779c8..03d90077a1f 100644 --- a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.RelationalProjectionBindingRemovingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.RelationalProjectionBindingRemovingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -23,6 +23,7 @@ private class RelationalProjectionBindingRemovingExpressionVisitor : ExpressionV private readonly SelectExpression _selectExpression; private readonly ParameterExpression _dbDataReaderParameter; + private readonly IDictionary> _materializationContextBindings = new Dictionary>(); @@ -45,7 +46,8 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression) _materializationContextBindings[parameterExpression] = (IDictionary)GetProjectionIndex(projectionBindingExpression); - var updatedExpression = Expression.New(newExpression.Constructor, + var updatedExpression = Expression.New( + newExpression.Constructor, Expression.Constant(ValueBuffer.Empty), newExpression.Arguments[1]); @@ -60,7 +62,6 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression) return memberExpression.Assign(Visit(binaryExpression.Right)); } - return base.VisitBinary(binaryExpression); } @@ -72,7 +73,8 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp var property = (IProperty)((ConstantExpression)methodCallExpression.Arguments[2]).Value; var propertyProjectionMap = methodCallExpression.Arguments[0] is ProjectionBindingExpression projectionBindingExpression ? (IDictionary)GetProjectionIndex(projectionBindingExpression) - : _materializationContextBindings[(ParameterExpression)((MethodCallExpression)methodCallExpression.Arguments[0]).Object]; + : _materializationContextBindings[ + (ParameterExpression)((MethodCallExpression)methodCallExpression.Arguments[0]).Object]; var projectionIndex = propertyProjectionMap[property]; var projection = _selectExpression.Projection[projectionIndex]; diff --git a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperExpressionProcessingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperExpressionProcessingExpressionVisitor.cs index 584b54dbd1b..aba70108ba5 100644 --- a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperExpressionProcessingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperExpressionProcessingExpressionVisitor.cs @@ -1,7 +1,6 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Reflection; @@ -15,6 +14,7 @@ private class ShaperExpressionProcessingExpressionVisitor : ExpressionVisitor { private static readonly MemberInfo _resultContextValuesMemberInfo = typeof(ResultContext).GetTypeInfo().GetMember(nameof(ResultContext.Values))[0]; + private static readonly MemberInfo _resultCoordinatorResultReadyMemberInfo = typeof(ResultCoordinator).GetTypeInfo().GetMember(nameof(ResultCoordinator.ResultReady))[0]; @@ -56,6 +56,7 @@ public ShaperExpressionProcessingExpressionVisitor( private class CollectionShaperFindingExpressionVisitor : ExpressionVisitor { private bool _containsCollection; + public bool ContainsCollectionMaterialization(Expression expression) { _containsCollection = false; @@ -99,7 +100,8 @@ public virtual Expression Inject(Expression expression) if (_containsCollectionMaterialization) { - var valueArrayInitializationExpression = Expression.Assign(_valuesArrayExpression, + var valueArrayInitializationExpression = Expression.Assign( + _valuesArrayExpression, Expression.NewArrayInit( typeof(object), _valuesArrayInitializers)); @@ -113,9 +115,10 @@ public virtual Expression Inject(Expression expression) var conditionalMaterializationExpressions = new List(); - conditionalMaterializationExpressions.Add(Expression.IfThen( - Expression.Equal(_valuesArrayExpression, Expression.Constant(null, typeof(object[]))), - initializationBlock)); + conditionalMaterializationExpressions.Add( + Expression.IfThen( + Expression.Equal(_valuesArrayExpression, Expression.Constant(null, typeof(object[]))), + initializationBlock)); conditionalMaterializationExpressions.AddRange(_collectionPopulatingExpressions); @@ -230,10 +233,11 @@ protected override Expression VisitExtension(Expression extensionExpression) relationalCollectionShaperExpression) { var innerShaper = new ShaperExpressionProcessingExpressionVisitor( - _selectExpression, _dataReaderParameter, _resultCoordinatorParameter, null) - .Inject(relationalCollectionShaperExpression.InnerShaper); + _selectExpression, _dataReaderParameter, _resultCoordinatorParameter, null) + .Inject(relationalCollectionShaperExpression.InnerShaper); - _collectionPopulatingExpressions.Add(new CollectionPopulatingExpression( + _collectionPopulatingExpressions.Add( + new CollectionPopulatingExpression( relationalCollectionShaperExpression.Update( relationalCollectionShaperExpression.ParentIdentifier, relationalCollectionShaperExpression.OuterIdentifier, @@ -242,19 +246,21 @@ protected override Expression VisitExtension(Expression extensionExpression) includeExpression.Navigation.ClrType, true)); - _includeExpressions.Add(new CollectionInitializingExpression( - relationalCollectionShaperExpression.CollectionId, - entity, - relationalCollectionShaperExpression.ParentIdentifier, - relationalCollectionShaperExpression.OuterIdentifier, - includeExpression.Navigation, - includeExpression.Navigation.ClrType)); + _includeExpressions.Add( + new CollectionInitializingExpression( + relationalCollectionShaperExpression.CollectionId, + entity, + relationalCollectionShaperExpression.ParentIdentifier, + relationalCollectionShaperExpression.OuterIdentifier, + includeExpression.Navigation, + includeExpression.Navigation.ClrType)); } else { - _includeExpressions.Add(includeExpression.Update( - entity, - Visit(includeExpression.NavigationExpression))); + _includeExpressions.Add( + includeExpression.Update( + entity, + Visit(includeExpression.NavigationExpression))); } return entity; @@ -266,10 +272,11 @@ protected override Expression VisitExtension(Expression extensionExpression) if (!_mapping.TryGetValue(key, out var accessor)) { var innerShaper = new ShaperExpressionProcessingExpressionVisitor( - _selectExpression, _dataReaderParameter, _resultCoordinatorParameter, null) - .Inject(relationalCollectionShaperExpression2.InnerShaper); + _selectExpression, _dataReaderParameter, _resultCoordinatorParameter, null) + .Inject(relationalCollectionShaperExpression2.InnerShaper); - _collectionPopulatingExpressions.Add(new CollectionPopulatingExpression( + _collectionPopulatingExpressions.Add( + new CollectionPopulatingExpression( relationalCollectionShaperExpression2.Update( relationalCollectionShaperExpression2.ParentIdentifier, relationalCollectionShaperExpression2.OuterIdentifier, @@ -280,15 +287,16 @@ protected override Expression VisitExtension(Expression extensionExpression) var collectionParameter = Expression.Parameter(relationalCollectionShaperExpression2.Type); _variables.Add(collectionParameter); - _expressions.Add(Expression.Assign( - collectionParameter, - new CollectionInitializingExpression( - relationalCollectionShaperExpression2.CollectionId, - null, - relationalCollectionShaperExpression2.ParentIdentifier, - relationalCollectionShaperExpression2.OuterIdentifier, - relationalCollectionShaperExpression2.Navigation, - relationalCollectionShaperExpression2.Type))); + _expressions.Add( + Expression.Assign( + collectionParameter, + new CollectionInitializingExpression( + relationalCollectionShaperExpression2.CollectionId, + null, + relationalCollectionShaperExpression2.ParentIdentifier, + relationalCollectionShaperExpression2.OuterIdentifier, + relationalCollectionShaperExpression2.Navigation, + relationalCollectionShaperExpression2.Type))); _valuesArrayInitializers.Add(collectionParameter); accessor = Expression.Convert( @@ -309,7 +317,7 @@ protected override Expression VisitExtension(Expression extensionExpression) private Expression GenerateKey(Expression expression) => expression is ProjectionBindingExpression projectionBindingExpression - && projectionBindingExpression.ProjectionMember != null + && projectionBindingExpression.ProjectionMember != null ? _selectExpression.GetMappedProjection(projectionBindingExpression.ProjectionMember) : expression; } diff --git a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.cs index f58f05ca88e..c561329e11a 100644 --- a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -41,10 +41,10 @@ protected override Expression VisitShapedQueryExpression(ShapedQueryExpression s var indexMapParameter = Expression.Parameter(typeof(int[]), "indexMap"); var shaper = new ShaperExpressionProcessingExpressionVisitor( - selectExpression, - dataReaderParameter, - resultCoordinatorParameter, - indexMapParameter) + selectExpression, + dataReaderParameter, + resultCoordinatorParameter, + indexMapParameter) .Inject(shapedQueryExpression.ShaperExpression); shaper = InjectEntityMaterializers(shaper); @@ -52,7 +52,7 @@ protected override Expression VisitShapedQueryExpression(ShapedQueryExpression s shaper = new RelationalProjectionBindingRemovingExpressionVisitor(selectExpression, dataReaderParameter) .Visit(shaper); shaper = new CustomShaperCompilingExpressionVisitor( - dataReaderParameter, resultCoordinatorParameter, IsTracking) + dataReaderParameter, resultCoordinatorParameter, IsTracking) .Visit(shaper); if (selectExpression.IsNonComposedFromSql()) @@ -93,10 +93,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp var indexArgument = methodCallExpression.Arguments[0]; return methodCallExpression.Update( methodCallExpression.Object, - new[] - { - Expression.ArrayIndex(_indexMapParameter, indexArgument), - }); + new[] { Expression.ArrayIndex(_indexMapParameter, indexArgument) }); } return base.VisitMethodCall(methodCallExpression); diff --git a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitorDependencies.cs b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitorDependencies.cs index 00fc6bed5d1..28958a1d180 100644 --- a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitorDependencies.cs +++ b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitorDependencies.cs @@ -26,8 +26,8 @@ namespace Microsoft.EntityFrameworkCore.Query /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -88,7 +88,8 @@ public RelationalShapedQueryCompilingExpressionVisitorDependencies( /// /// A replacement for the current dependency of this type. /// A new parameter object with the given service replaced. - public RelationalShapedQueryCompilingExpressionVisitorDependencies With([NotNull] IQuerySqlGeneratorFactory querySqlGeneratorFactory) + public RelationalShapedQueryCompilingExpressionVisitorDependencies With( + [NotNull] IQuerySqlGeneratorFactory querySqlGeneratorFactory) => new RelationalShapedQueryCompilingExpressionVisitorDependencies( querySqlGeneratorFactory, SqlExpressionFactory, @@ -110,7 +111,8 @@ public RelationalShapedQueryCompilingExpressionVisitorDependencies With([NotNull /// /// A replacement for the current dependency of this type. /// A new parameter object with the given service replaced. - public RelationalShapedQueryCompilingExpressionVisitorDependencies With([NotNull] IParameterNameGeneratorFactory parameterNameGeneratorFactory) + public RelationalShapedQueryCompilingExpressionVisitorDependencies With( + [NotNull] IParameterNameGeneratorFactory parameterNameGeneratorFactory) => new RelationalShapedQueryCompilingExpressionVisitorDependencies( QuerySqlGeneratorFactory, SqlExpressionFactory, diff --git a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs index e8c136226f8..0c5f91b575a 100644 --- a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -90,10 +90,10 @@ public virtual SqlExpression TranslateAverage(Expression expression) return inputType == typeof(float) ? _sqlExpressionFactory.Convert( - _sqlExpressionFactory.Function( - "AVG", new[] { sqlExpression }, typeof(double)), - sqlExpression.Type, - sqlExpression.TypeMapping) + _sqlExpressionFactory.Function( + "AVG", new[] { sqlExpression }, typeof(double)), + sqlExpression.Type, + sqlExpression.TypeMapping) : (SqlExpression)_sqlExpressionFactory.Function( "AVG", new[] { sqlExpression }, sqlExpression.Type, sqlExpression.TypeMapping); } @@ -148,9 +148,9 @@ public virtual SqlExpression TranslateSum(Expression expression) return inputType == typeof(float) ? _sqlExpressionFactory.Convert( - _sqlExpressionFactory.Function("SUM", new[] { sqlExpression }, typeof(double)), - inputType, - sqlExpression.TypeMapping) + _sqlExpressionFactory.Function("SUM", new[] { sqlExpression }, typeof(double)), + inputType, + sqlExpression.TypeMapping) : (SqlExpression)_sqlExpressionFactory.Function( "SUM", new[] { sqlExpression }, inputType, sqlExpression.TypeMapping); } @@ -177,9 +177,9 @@ protected override Expression VisitMember(MemberExpression memberExpression) var innerExpression = Visit(memberExpression.Expression); if ((innerExpression is EntityProjectionExpression - || (innerExpression is UnaryExpression innerUnaryExpression - && innerUnaryExpression.NodeType == ExpressionType.Convert - && innerUnaryExpression.Operand is EntityProjectionExpression)) + || (innerExpression is UnaryExpression innerUnaryExpression + && innerUnaryExpression.NodeType == ExpressionType.Convert + && innerUnaryExpression.Operand is EntityProjectionExpression)) && TryBindMember(innerExpression, MemberIdentity.Create(memberExpression.Member), out var result)) { return result; @@ -249,9 +249,11 @@ protected override Expression VisitTypeBinary(TypeBinaryExpression typeBinaryExp var discriminatorColumn = entityProjectionExpression.BindProperty(entityType.GetDiscriminatorProperty()); return concreteEntityTypes.Count == 1 - ? _sqlExpressionFactory.Equal(discriminatorColumn, + ? _sqlExpressionFactory.Equal( + discriminatorColumn, _sqlExpressionFactory.Constant(concreteEntityTypes[0].GetDiscriminatorValue())) - : (Expression)_sqlExpressionFactory.In(discriminatorColumn, + : (Expression)_sqlExpressionFactory.In( + discriminatorColumn, _sqlExpressionFactory.Constant(concreteEntityTypes.Select(et => et.GetDiscriminatorValue()).ToList()), negated: false); } @@ -331,13 +333,13 @@ static bool IsAggregateResultWithCustomShaper(MethodInfo method) } return QueryableMethods.IsAverageWithoutSelector(method) - || QueryableMethods.IsAverageWithSelector(method) - || method == QueryableMethods.MaxWithoutSelector - || method == QueryableMethods.MaxWithSelector - || method == QueryableMethods.MinWithoutSelector - || method == QueryableMethods.MinWithSelector - || QueryableMethods.IsSumWithoutSelector(method) - || QueryableMethods.IsSumWithSelector(method); + || QueryableMethods.IsAverageWithSelector(method) + || method == QueryableMethods.MaxWithoutSelector + || method == QueryableMethods.MaxWithSelector + || method == QueryableMethods.MinWithoutSelector + || method == QueryableMethods.MinWithSelector + || QueryableMethods.IsSumWithoutSelector(method) + || QueryableMethods.IsSumWithSelector(method); } if (subqueryTranslation.ResultCardinality == ResultCardinality.Enumerable) @@ -349,7 +351,7 @@ static bool IsAggregateResultWithCustomShaper(MethodInfo method) subquery.ApplyProjection(); if (!(subqueryTranslation.ShaperExpression is ProjectionBindingExpression - || IsAggregateResultWithCustomShaper(methodCallExpression.Method))) + || IsAggregateResultWithCustomShaper(methodCallExpression.Method))) { return null; } @@ -382,6 +384,7 @@ static bool IsAggregateResultWithCustomShaper(MethodInfo method) { return null; } + arguments[i] = sqlArgument; } @@ -400,6 +403,7 @@ private static Expression TryRemoveImplicitConvert(Expression expression) { innerType = Enum.GetUnderlyingType(innerType); } + var convertedType = unaryExpression.Type.UnwrapNullableType(); if (innerType == convertedType @@ -436,22 +440,22 @@ static Expression removeObjectConvert(Expression expression) var rightExpressions = ((NewArrayExpression)((NewExpression)binaryExpression.Right).Arguments[0]).Expressions; return leftExpressions.Zip( - rightExpressions, - (l, r) => - { - l = removeObjectConvert(l); - r = removeObjectConvert(r); - if (l.Type.IsNullableType()) + rightExpressions, + (l, r) => { - r = r.Type.IsNullableType() ? r : Expression.Convert(r, l.Type); - } - else if (r.Type.IsNullableType()) - { - l = l.Type.IsNullableType() ? l : Expression.Convert(l, r.Type); - } - - return Expression.Equal(l, r); - }) + l = removeObjectConvert(l); + r = removeObjectConvert(r); + if (l.Type.IsNullableType()) + { + r = r.Type.IsNullableType() ? r : Expression.Convert(r, l.Type); + } + else if (r.Type.IsNullableType()) + { + l = l.Type.IsNullableType() ? l : Expression.Convert(l, r.Type); + } + + return Expression.Equal(l, r); + }) .Aggregate((a, b) => Expression.AndAlso(a, b)); } @@ -502,8 +506,8 @@ private static bool CanEvaluate(Expression expression) case MemberInitExpression memberInitExpression: return CanEvaluate(memberInitExpression.NewExpression) - && memberInitExpression.Bindings.All( - mb => mb is MemberAssignment memberAssignment && CanEvaluate(memberAssignment.Expression)); + && memberInitExpression.Bindings.All( + mb => mb is MemberAssignment memberAssignment && CanEvaluate(memberAssignment.Expression)); default: return false; @@ -592,7 +596,7 @@ protected override Expression VisitUnary(UnaryExpression unaryExpression) case ExpressionType.Convert: // Object convert needs to be converted to explicit cast when mismatching types if (operand.Type.IsInterface - && unaryExpression.Type.GetInterfaces().Any(e => e == operand.Type) + && unaryExpression.Type.GetInterfaces().Any(e => e == operand.Type) || unaryExpression.Type.UnwrapNullableType() == operand.Type.UnwrapNullableType() || unaryExpression.Type.UnwrapNullableType() == typeof(Enum)) { @@ -617,7 +621,8 @@ protected override Expression VisitUnary(UnaryExpression unaryExpression) [DebuggerStepThrough] private bool TranslationFailed(Expression original, Expression translation, out SqlExpression castTranslation) { - if (original != null && !(translation is SqlExpression)) + if (original != null + && !(translation is SqlExpression)) { castTranslation = null; return true; diff --git a/src/EFCore.Relational/Query/SqlExpressionFactory.cs b/src/EFCore.Relational/Query/SqlExpressionFactory.cs index 130a591443d..7b65273625f 100644 --- a/src/EFCore.Relational/Query/SqlExpressionFactory.cs +++ b/src/EFCore.Relational/Query/SqlExpressionFactory.cs @@ -1,16 +1,12 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; -using System.Reflection; -using Microsoft.EntityFrameworkCore.Internal; -using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; @@ -57,8 +53,8 @@ public virtual SqlExpression ApplyTypeMapping(SqlExpression sqlExpression, Relat private SqlExpression ApplyTypeMappingOnLike(LikeExpression likeExpression) { var inferredTypeMapping = ExpressionExtensions.InferTypeMapping( - likeExpression.Match, likeExpression.Pattern, likeExpression.EscapeChar) - ?? _typeMappingSource.FindMapping(likeExpression.Match.Type); + likeExpression.Match, likeExpression.Pattern, likeExpression.EscapeChar) + ?? _typeMappingSource.FindMapping(likeExpression.Match.Type); return new LikeExpression( ApplyTypeMapping(likeExpression.Match, inferredTypeMapping), @@ -139,11 +135,11 @@ private SqlExpression ApplyTypeMappingOnSqlBinary( case ExpressionType.NotEqual: { inferredTypeMapping = ExpressionExtensions.InferTypeMapping(left, right) - ?? _typeMappingSource.FindMapping(left.Type); + ?? _typeMappingSource.FindMapping(left.Type); resultType = typeof(bool); resultTypeMapping = _boolTypeMapping; + break; } - break; case ExpressionType.AndAlso: case ExpressionType.OrElse: @@ -151,8 +147,8 @@ private SqlExpression ApplyTypeMappingOnSqlBinary( inferredTypeMapping = _boolTypeMapping; resultType = typeof(bool); resultTypeMapping = _boolTypeMapping; + break; } - break; case ExpressionType.Add: case ExpressionType.Subtract: @@ -166,8 +162,8 @@ private SqlExpression ApplyTypeMappingOnSqlBinary( inferredTypeMapping = typeMapping ?? ExpressionExtensions.InferTypeMapping(left, right); resultType = left.Type; resultTypeMapping = inferredTypeMapping; + break; } - break; default: throw new InvalidOperationException("Incorrect operatorType for SqlBinaryExpression"); @@ -257,7 +253,8 @@ public virtual SqlBinaryExpression Or(SqlExpression left, SqlExpression right, R public virtual SqlBinaryExpression Coalesce(SqlExpression left, SqlExpression right, RelationalTypeMapping typeMapping = null) => MakeBinary(ExpressionType.Coalesce, left, right, typeMapping); - public virtual SqlUnaryExpression MakeUnary(ExpressionType operatorType, SqlExpression operand, Type type, RelationalTypeMapping typeMapping = null) + public virtual SqlUnaryExpression MakeUnary( + ExpressionType operatorType, SqlExpression operand, Type type, RelationalTypeMapping typeMapping = null) => (SqlUnaryExpression)ApplyTypeMapping(new SqlUnaryExpression(operatorType, operand, type, null), typeMapping); public virtual SqlUnaryExpression IsNull(SqlExpression operand) @@ -278,11 +275,11 @@ public virtual SqlUnaryExpression Negate(SqlExpression operand) public virtual CaseExpression Case(SqlExpression operand, SqlExpression elseResult, params CaseWhenClause[] whenClauses) { var operandTypeMapping = operand.TypeMapping - ?? whenClauses.Select(wc => wc.Test.TypeMapping).FirstOrDefault(t => t != null) - ?? _typeMappingSource.FindMapping(operand.Type); + ?? whenClauses.Select(wc => wc.Test.TypeMapping).FirstOrDefault(t => t != null) + ?? _typeMappingSource.FindMapping(operand.Type); var resultTypeMapping = elseResult?.TypeMapping - ?? whenClauses.Select(wc => wc.Result.TypeMapping).FirstOrDefault(t => t != null); + ?? whenClauses.Select(wc => wc.Result.TypeMapping).FirstOrDefault(t => t != null); operand = ApplyTypeMapping(operand, operandTypeMapping); @@ -306,7 +303,7 @@ public virtual CaseExpression Case(SqlExpression operand, params CaseWhenClause[ public virtual CaseExpression Case(IReadOnlyList whenClauses, SqlExpression elseResult) { var resultTypeMapping = elseResult?.TypeMapping - ?? whenClauses.Select(wc => wc.Result.TypeMapping).FirstOrDefault(t => t != null); + ?? whenClauses.Select(wc => wc.Result.TypeMapping).FirstOrDefault(t => t != null); var typeMappedWhenClauses = new List(); foreach (var caseWhenClause in whenClauses) @@ -357,7 +354,8 @@ public virtual SqlFunctionExpression Function( } public virtual SqlFunctionExpression Function( - SqlExpression instance, string name, IEnumerable arguments, Type returnType, RelationalTypeMapping typeMapping = null) + SqlExpression instance, string name, IEnumerable arguments, Type returnType, + RelationalTypeMapping typeMapping = null) { instance = ApplyDefaultTypeMapping(instance); var typeMappedArguments = new List(); @@ -380,7 +378,8 @@ public virtual SqlFunctionExpression Function(string name, Type returnType, Rela public virtual SqlFunctionExpression Function(string schema, string name, Type returnType, RelationalTypeMapping typeMapping = null) => SqlFunctionExpression.CreateNiladic(schema, name, returnType, typeMapping); - public virtual SqlFunctionExpression Function(SqlExpression instance, string name, Type returnType, RelationalTypeMapping typeMapping = null) + public virtual SqlFunctionExpression Function( + SqlExpression instance, string name, Type returnType, RelationalTypeMapping typeMapping = null) => SqlFunctionExpression.CreateNiladic(ApplyDefaultTypeMapping(instance), name, returnType, typeMapping); public virtual ExistsExpression Exists(SelectExpression subquery, bool negated) @@ -403,7 +402,8 @@ public virtual InExpression In(SqlExpression item, SelectExpression subquery, bo if (typeMapping == null) { - throw new InvalidOperationException($"The subquery '{subquery.Print()}' references type '{sqlExpression.Type}' for which no type mapping could be found."); + throw new InvalidOperationException( + $"The subquery '{subquery.Print()}' references type '{sqlExpression.Type}' for which no type mapping could be found."); } item = ApplyTypeMapping(item, typeMapping); @@ -430,10 +430,8 @@ public virtual SelectExpression Select(SqlExpression projection) if (projection != null) { - selectExpression.ReplaceProjectionMapping(new Dictionary - { - { new ProjectionMember(), projection } - }); + selectExpression.ReplaceProjectionMapping( + new Dictionary { { new ProjectionMember(), projection } }); } return selectExpression; @@ -468,21 +466,22 @@ private void AddConditions( else { sharingTypes ??= new HashSet( - entityType.Model.GetEntityTypes() - .Where(et => et.FindPrimaryKey() != null - && et.GetTableName() == entityType.GetTableName() - && et.GetSchema() == entityType.GetSchema())); + entityType.Model.GetEntityTypes() + .Where( + et => et.FindPrimaryKey() != null + && et.GetTableName() == entityType.GetTableName() + && et.GetSchema() == entityType.GetSchema())); if (sharingTypes.Count > 0) { bool discriminatorAdded = AddDiscriminatorCondition(selectExpression, entityType); var linkingFks = entityType.GetRootType().FindForeignKeys(entityType.FindPrimaryKey().Properties) - .Where( - fk => fk.PrincipalKey.IsPrimaryKey() - && fk.PrincipalEntityType != entityType - && sharingTypes.Contains(fk.PrincipalEntityType)) - .ToList(); + .Where( + fk => fk.PrincipalKey.IsPrimaryKey() + && fk.PrincipalEntityType != entityType + && sharingTypes.Contains(fk.PrincipalEntityType)) + .ToList(); if (linkingFks.Count > 0) { @@ -568,7 +567,8 @@ private bool AddDiscriminatorCondition(SelectExpression selectExpression, IEntit var discriminatorColumn = GetMappedEntityProjectionExpression(selectExpression) .BindProperty(concreteEntityTypes[0].GetDiscriminatorProperty()); - predicate = In(discriminatorColumn, Constant(concreteEntityTypes.Select(et => et.GetDiscriminatorValue()).ToList()), negated: false); + predicate = In( + discriminatorColumn, Constant(concreteEntityTypes.Select(et => et.GetDiscriminatorValue()).ToList()), negated: false); } selectExpression.ApplyPredicate(predicate); @@ -619,6 +619,7 @@ private void AddOptionalDependentConditions( IsNotNull(property, entityProjectionExpression), current)); } + selectExpression.ApplyPredicate(predicate); foreach (var referencingFk in entityType.GetReferencingForeignKeys()) @@ -626,9 +627,10 @@ private void AddOptionalDependentConditions( var otherSelectExpression = new SelectExpression(entityType); var sameTable = sharingTypes.Contains(referencingFk.DeclaringEntityType); - AddInnerJoin(otherSelectExpression, referencingFk, - sameTable ? sharingTypes : null, - skipInnerJoins: sameTable); + AddInnerJoin( + otherSelectExpression, referencingFk, + sameTable ? sharingTypes : null, + skipInnerJoins: sameTable); selectExpression.ApplyUnion(otherSelectExpression, distinct: true); } } diff --git a/src/EFCore.Relational/Query/SqlExpressionFactoryDependencies.cs b/src/EFCore.Relational/Query/SqlExpressionFactoryDependencies.cs index 2b4f4efc2f8..d644d02fd68 100644 --- a/src/EFCore.Relational/Query/SqlExpressionFactoryDependencies.cs +++ b/src/EFCore.Relational/Query/SqlExpressionFactoryDependencies.cs @@ -26,9 +26,9 @@ namespace Microsoft.EntityFrameworkCore.Query /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public sealed class SqlExpressionFactoryDependencies diff --git a/src/EFCore.Relational/Query/SqlExpressionVisitor.cs b/src/EFCore.Relational/Query/SqlExpressionVisitor.cs index b6837f83489..6db56f75572 100644 --- a/src/EFCore.Relational/Query/SqlExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/SqlExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq.Expressions; diff --git a/src/EFCore.Relational/Query/SqlExpressions/CaseExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/CaseExpression.cs index 3653c48ac94..96fe90a5d2e 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/CaseExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/CaseExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -51,7 +51,8 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) var test = (SqlExpression)visitor.Visit(whenClause.Test); var result = (SqlExpression)visitor.Visit(whenClause.Result); - if (test != whenClause.Test || result != whenClause.Result) + if (test != whenClause.Test + || result != whenClause.Result) { changed |= true; whenClauses.Add(new CaseWhenClause(test, result)); @@ -109,15 +110,15 @@ public override void Print(ExpressionPrinter expressionPrinter) public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is CaseExpression caseExpression - && Equals(caseExpression)); + && (ReferenceEquals(this, obj) + || obj is CaseExpression caseExpression + && Equals(caseExpression)); private bool Equals(CaseExpression caseExpression) => base.Equals(caseExpression) - && (Operand == null ? caseExpression.Operand == null : Operand.Equals(caseExpression.Operand)) - && WhenClauses.SequenceEqual(caseExpression.WhenClauses) - && (ElseResult == null ? caseExpression.ElseResult == null : ElseResult.Equals(caseExpression.ElseResult)); + && (Operand == null ? caseExpression.Operand == null : Operand.Equals(caseExpression.Operand)) + && WhenClauses.SequenceEqual(caseExpression.WhenClauses) + && (ElseResult == null ? caseExpression.ElseResult == null : ElseResult.Equals(caseExpression.ElseResult)); public override int GetHashCode() { @@ -128,6 +129,7 @@ public override int GetHashCode() { hash.Add(WhenClauses[i]); } + hash.Add(ElseResult); return hash.ToHashCode(); } diff --git a/src/EFCore.Relational/Query/SqlExpressions/CaseWhenClause.cs b/src/EFCore.Relational/Query/SqlExpressions/CaseWhenClause.cs index 0e0a722d9c1..a08fd752339 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/CaseWhenClause.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/CaseWhenClause.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -18,13 +18,13 @@ public CaseWhenClause(SqlExpression test, SqlExpression result) public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is CaseWhenClause caseWhenClause - && Equals(caseWhenClause)); + && (ReferenceEquals(this, obj) + || obj is CaseWhenClause caseWhenClause + && Equals(caseWhenClause)); private bool Equals(CaseWhenClause caseWhenClause) => Test.Equals(caseWhenClause.Test) - && Result.Equals(caseWhenClause.Result); + && Result.Equals(caseWhenClause.Result); public override int GetHashCode() => HashCode.Combine(Test, Result); } diff --git a/src/EFCore.Relational/Query/SqlExpressions/ColumnExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/ColumnExpression.cs index 96c1088c720..f7296653f8f 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/ColumnExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/ColumnExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -14,15 +14,17 @@ namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions public class ColumnExpression : SqlExpression { internal ColumnExpression(IProperty property, TableExpressionBase table, bool nullable) - : this(property.GetColumnName(), table, property.ClrType, property.GetRelationalTypeMapping(), - nullable || property.IsNullable || property.DeclaringEntityType.BaseType != null) + : this( + property.GetColumnName(), table, property.ClrType, property.GetRelationalTypeMapping(), + nullable || property.IsNullable || property.DeclaringEntityType.BaseType != null) { } internal ColumnExpression(ProjectionExpression subqueryProjection, TableExpressionBase table) - : this(subqueryProjection.Alias, table, - subqueryProjection.Type, subqueryProjection.Expression.TypeMapping, - IsNullableProjection(subqueryProjection)) + : this( + subqueryProjection.Alias, table, + subqueryProjection.Type, subqueryProjection.Expression.TypeMapping, + IsNullableProjection(subqueryProjection)) { } @@ -69,15 +71,15 @@ public override void Print(ExpressionPrinter expressionPrinter) public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is ColumnExpression columnExpression - && Equals(columnExpression)); + && (ReferenceEquals(this, obj) + || obj is ColumnExpression columnExpression + && Equals(columnExpression)); private bool Equals(ColumnExpression columnExpression) => base.Equals(columnExpression) - && string.Equals(Name, columnExpression.Name) - && Table.Equals(columnExpression.Table) - && IsNullable == columnExpression.IsNullable; + && string.Equals(Name, columnExpression.Name) + && Table.Equals(columnExpression.Table) + && IsNullable == columnExpression.IsNullable; public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), Name, Table, IsNullable); diff --git a/src/EFCore.Relational/Query/SqlExpressions/CrossApplyExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/CrossApplyExpression.cs index 1c6ef9df6cb..d4aebdb9e00 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/CrossApplyExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/CrossApplyExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq.Expressions; @@ -28,9 +28,9 @@ public override void Print(ExpressionPrinter expressionPrinter) public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is CrossApplyExpression crossApplyExpression - && Equals(crossApplyExpression)); + && (ReferenceEquals(this, obj) + || obj is CrossApplyExpression crossApplyExpression + && Equals(crossApplyExpression)); private bool Equals(CrossApplyExpression crossApplyExpression) => base.Equals(crossApplyExpression); diff --git a/src/EFCore.Relational/Query/SqlExpressions/CrossJoinExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/CrossJoinExpression.cs index 6ffd89c8f64..303402c522e 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/CrossJoinExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/CrossJoinExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq.Expressions; @@ -28,9 +28,9 @@ public override void Print(ExpressionPrinter expressionPrinter) public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is CrossJoinExpression crossJoinExpression - && Equals(crossJoinExpression)); + && (ReferenceEquals(this, obj) + || obj is CrossJoinExpression crossJoinExpression + && Equals(crossJoinExpression)); private bool Equals(CrossJoinExpression crossJoinExpression) => base.Equals(crossJoinExpression); diff --git a/src/EFCore.Relational/Query/SqlExpressions/ExceptExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/ExceptExpression.cs index a983f6790da..c2dc78387e1 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/ExceptExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/ExceptExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -38,17 +38,19 @@ public override void Print(ExpressionPrinter expressionPrinter) { expressionPrinter.AppendLine(" ALL"); } + expressionPrinter.Visit(Source2); } + expressionPrinter.AppendLine() .AppendLine($") AS {Alias}"); } public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is ExceptExpression exceptExpression - && Equals(exceptExpression)); + && (ReferenceEquals(this, obj) + || obj is ExceptExpression exceptExpression + && Equals(exceptExpression)); private bool Equals(ExceptExpression exceptExpression) => base.Equals(exceptExpression); diff --git a/src/EFCore.Relational/Query/SqlExpressions/ExistsExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/ExistsExpression.cs index fabca3852a4..8881655c7d0 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/ExistsExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/ExistsExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -27,7 +27,6 @@ public virtual ExistsExpression Update(SelectExpression subquery) ? new ExistsExpression(subquery, IsNegated, TypeMapping) : this; - public override void Print(ExpressionPrinter expressionPrinter) { if (IsNegated) @@ -46,14 +45,14 @@ public override void Print(ExpressionPrinter expressionPrinter) public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is ExistsExpression existsExpression - && Equals(existsExpression)); + && (ReferenceEquals(this, obj) + || obj is ExistsExpression existsExpression + && Equals(existsExpression)); private bool Equals(ExistsExpression existsExpression) => base.Equals(existsExpression) - && Subquery.Equals(existsExpression.Subquery) - && IsNegated == existsExpression.IsNegated; + && Subquery.Equals(existsExpression.Subquery) + && IsNegated == existsExpression.IsNegated; public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), Subquery, IsNegated); } diff --git a/src/EFCore.Relational/Query/SqlExpressions/InExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/InExpression.cs index 69bfa225e60..535cf0c689d 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/InExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/InExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -20,7 +20,8 @@ public InExpression(SqlExpression item, bool negated, SqlExpression values, Rela { } - private InExpression(SqlExpression item, bool negated, SqlExpression values, SelectExpression subquery, + private InExpression( + SqlExpression item, bool negated, SqlExpression values, SelectExpression subquery, RelationalTypeMapping typeMapping) : base(typeof(bool), typeMapping) { @@ -82,16 +83,16 @@ public override void Print(ExpressionPrinter expressionPrinter) public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is InExpression inExpression - && Equals(inExpression)); + && (ReferenceEquals(this, obj) + || obj is InExpression inExpression + && Equals(inExpression)); private bool Equals(InExpression inExpression) => base.Equals(inExpression) - && Item.Equals(inExpression.Item) - && IsNegated.Equals(inExpression.IsNegated) - && (Values == null ? inExpression.Values == null : Values.Equals(inExpression.Values)) - && (Subquery == null ? inExpression.Subquery == null : Subquery.Equals(inExpression.Subquery)); + && Item.Equals(inExpression.Item) + && IsNegated.Equals(inExpression.IsNegated) + && (Values == null ? inExpression.Values == null : Values.Equals(inExpression.Values)) + && (Subquery == null ? inExpression.Subquery == null : Subquery.Equals(inExpression.Subquery)); public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), Item, IsNegated, Values, Subquery); } diff --git a/src/EFCore.Relational/Query/SqlExpressions/InnerJoinExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/InnerJoinExpression.cs index 22ab3269608..a333f935c5e 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/InnerJoinExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/InnerJoinExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq.Expressions; @@ -35,9 +35,9 @@ public override void Print(ExpressionPrinter expressionPrinter) public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is InnerJoinExpression innerJoinExpression - && Equals(innerJoinExpression)); + && (ReferenceEquals(this, obj) + || obj is InnerJoinExpression innerJoinExpression + && Equals(innerJoinExpression)); private bool Equals(InnerJoinExpression innerJoinExpression) => base.Equals(innerJoinExpression); diff --git a/src/EFCore.Relational/Query/SqlExpressions/IntersectExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/IntersectExpression.cs index 2bb7e8e4b0b..82c31dbb9fe 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/IntersectExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/IntersectExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -38,17 +38,19 @@ public override void Print(ExpressionPrinter expressionPrinter) { expressionPrinter.AppendLine(" ALL"); } + expressionPrinter.Visit(Source2); } + expressionPrinter.AppendLine() .AppendLine($") AS {Alias}"); } public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is IntersectExpression intersectExpression - && Equals(intersectExpression)); + && (ReferenceEquals(this, obj) + || obj is IntersectExpression intersectExpression + && Equals(intersectExpression)); private bool Equals(IntersectExpression intersectExpression) => base.Equals(intersectExpression); diff --git a/src/EFCore.Relational/Query/SqlExpressions/JoinExpressionBase.cs b/src/EFCore.Relational/Query/SqlExpressions/JoinExpressionBase.cs index a2ece867fb6..dea55b89226 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/JoinExpressionBase.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/JoinExpressionBase.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -17,13 +17,13 @@ protected JoinExpressionBase(TableExpressionBase table) public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is JoinExpressionBase joinExpressionBase - && Equals(joinExpressionBase)); + && (ReferenceEquals(this, obj) + || obj is JoinExpressionBase joinExpressionBase + && Equals(joinExpressionBase)); private bool Equals(JoinExpressionBase joinExpressionBase) => base.Equals(joinExpressionBase) - && Table.Equals(joinExpressionBase.Table); + && Table.Equals(joinExpressionBase.Table); public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), Table); } diff --git a/src/EFCore.Relational/Query/SqlExpressions/LeftJoinExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/LeftJoinExpression.cs index 6b4d536ec81..bf4f870f04a 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/LeftJoinExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/LeftJoinExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq.Expressions; @@ -35,9 +35,9 @@ public override void Print(ExpressionPrinter expressionPrinter) public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is LeftJoinExpression leftJoinExpression - && Equals(leftJoinExpression)); + && (ReferenceEquals(this, obj) + || obj is LeftJoinExpression leftJoinExpression + && Equals(leftJoinExpression)); private bool Equals(LeftJoinExpression leftJoinExpression) => base.Equals(leftJoinExpression); diff --git a/src/EFCore.Relational/Query/SqlExpressions/LikeExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/LikeExpression.cs index d3fe205d797..d1682da0058 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/LikeExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/LikeExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -50,15 +50,15 @@ public override void Print(ExpressionPrinter expressionPrinter) public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is LikeExpression likeExpression - && Equals(likeExpression)); + && (ReferenceEquals(this, obj) + || obj is LikeExpression likeExpression + && Equals(likeExpression)); private bool Equals(LikeExpression likeExpression) => base.Equals(likeExpression) - && Match.Equals(likeExpression.Match) - && Pattern.Equals(likeExpression.Pattern) - && EscapeChar.Equals(likeExpression.EscapeChar); + && Match.Equals(likeExpression.Match) + && Pattern.Equals(likeExpression.Pattern) + && EscapeChar.Equals(likeExpression.EscapeChar); public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), Match, Pattern, EscapeChar); } diff --git a/src/EFCore.Relational/Query/SqlExpressions/OrderingExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/OrderingExpression.cs index b1b03131d00..f5675dfc3fc 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/OrderingExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/OrderingExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -19,6 +19,7 @@ public OrderingExpression(SqlExpression expression, bool ascending) public sealed override ExpressionType NodeType => ExpressionType.Extension; public override Type Type => Expression.Type; + protected override Expression VisitChildren(ExpressionVisitor visitor) => Update((SqlExpression)visitor.Visit(Expression)); @@ -36,13 +37,13 @@ public virtual void Print(ExpressionPrinter expressionPrinter) public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is OrderingExpression orderingExpression - && Equals(orderingExpression)); + && (ReferenceEquals(this, obj) + || obj is OrderingExpression orderingExpression + && Equals(orderingExpression)); private bool Equals(OrderingExpression orderingExpression) => Expression.Equals(orderingExpression.Expression) - && IsAscending == orderingExpression.IsAscending; + && IsAscending == orderingExpression.IsAscending; public override int GetHashCode() => HashCode.Combine(Expression, IsAscending); } diff --git a/src/EFCore.Relational/Query/SqlExpressions/OuterApplyExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/OuterApplyExpression.cs index 5c48cca4c44..60491edd0bb 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/OuterApplyExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/OuterApplyExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq.Expressions; @@ -28,9 +28,9 @@ public override void Print(ExpressionPrinter expressionPrinter) public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is OuterApplyExpression outerApplyExpression - && Equals(outerApplyExpression)); + && (ReferenceEquals(this, obj) + || obj is OuterApplyExpression outerApplyExpression + && Equals(outerApplyExpression)); private bool Equals(OuterApplyExpression outerApplyExpression) => base.Equals(outerApplyExpression); diff --git a/src/EFCore.Relational/Query/SqlExpressions/PredicateJoinExpressionBase.cs b/src/EFCore.Relational/Query/SqlExpressions/PredicateJoinExpressionBase.cs index 5a86222f8f2..c848e7819d8 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/PredicateJoinExpressionBase.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/PredicateJoinExpressionBase.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -17,13 +17,13 @@ protected PredicateJoinExpressionBase(TableExpressionBase table, SqlExpression j public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is PredicateJoinExpressionBase predicateJoinExpressionBase - && Equals(predicateJoinExpressionBase)); + && (ReferenceEquals(this, obj) + || obj is PredicateJoinExpressionBase predicateJoinExpressionBase + && Equals(predicateJoinExpressionBase)); private bool Equals(PredicateJoinExpressionBase predicateJoinExpressionBase) => base.Equals(predicateJoinExpressionBase) - && JoinPredicate.Equals(predicateJoinExpressionBase.JoinPredicate); + && JoinPredicate.Equals(predicateJoinExpressionBase.JoinPredicate); public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), JoinPredicate); } diff --git a/src/EFCore.Relational/Query/SqlExpressions/ProjectionExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/ProjectionExpression.cs index 3b6dfcc8872..2798077f397 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/ProjectionExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/ProjectionExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -33,7 +33,7 @@ public virtual void Print(ExpressionPrinter expressionPrinter) expressionPrinter.Visit(Expression); if (!string.Equals(string.Empty, Alias) && !(Expression is ColumnExpression column - && string.Equals(column.Name, Alias))) + && string.Equals(column.Name, Alias))) { expressionPrinter.Append(" AS " + Alias); } @@ -41,13 +41,13 @@ public virtual void Print(ExpressionPrinter expressionPrinter) public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is ProjectionExpression projectionExpression - && Equals(projectionExpression)); + && (ReferenceEquals(this, obj) + || obj is ProjectionExpression projectionExpression + && Equals(projectionExpression)); private bool Equals(ProjectionExpression projectionExpression) => string.Equals(Alias, projectionExpression.Alias) - && Expression.Equals(projectionExpression.Expression); + && Expression.Equals(projectionExpression.Expression); public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), Alias, Expression); } diff --git a/src/EFCore.Relational/Query/SqlExpressions/RowNumberExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/RowNumberExpression.cs index 1314b750cae..3d0844aa3df 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/RowNumberExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/RowNumberExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -12,7 +12,8 @@ namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions { public class RowNumberExpression : SqlExpression { - public RowNumberExpression(IReadOnlyList partitions, IReadOnlyList orderings, RelationalTypeMapping typeMapping) + public RowNumberExpression( + IReadOnlyList partitions, IReadOnlyList orderings, RelationalTypeMapping typeMapping) : base(typeof(long), typeMapping) { Check.NotEmpty(orderings, nameof(orderings)); @@ -51,7 +52,7 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) public virtual RowNumberExpression Update(IReadOnlyList partitions, IReadOnlyList orderings) { return (Partitions == null ? partitions == null : Partitions.SequenceEqual(partitions)) - && Orderings.SequenceEqual(orderings) + && Orderings.SequenceEqual(orderings) ? this : new RowNumberExpression(partitions, orderings, TypeMapping); } @@ -65,6 +66,7 @@ public override void Print(ExpressionPrinter expressionPrinter) expressionPrinter.VisitList(Partitions); expressionPrinter.Append(" "); } + expressionPrinter.Append("ORDER BY "); expressionPrinter.VisitList(Orderings); expressionPrinter.Append(")"); @@ -72,14 +74,14 @@ public override void Print(ExpressionPrinter expressionPrinter) public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is RowNumberExpression rowNumberExpression - && Equals(rowNumberExpression)); + && (ReferenceEquals(this, obj) + || obj is RowNumberExpression rowNumberExpression + && Equals(rowNumberExpression)); private bool Equals(RowNumberExpression rowNumberExpression) => base.Equals(rowNumberExpression) - && (Partitions == null ? rowNumberExpression.Partitions == null : Partitions.SequenceEqual(rowNumberExpression.Partitions)) - && Orderings.SequenceEqual(rowNumberExpression.Orderings); + && (Partitions == null ? rowNumberExpression.Partitions == null : Partitions.SequenceEqual(rowNumberExpression.Partitions)) + && Orderings.SequenceEqual(rowNumberExpression.Orderings); public override int GetHashCode() { diff --git a/src/EFCore.Relational/Query/SqlExpressions/ScalarSubqueryExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/ScalarSubqueryExpression.cs index b730ac09efc..fc8a07027e1 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/ScalarSubqueryExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/ScalarSubqueryExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -15,6 +15,7 @@ public ScalarSubqueryExpression(SelectExpression subquery) { Subquery = subquery; } + private static SelectExpression Verify(SelectExpression selectExpression) { if (selectExpression.Projection.Count != 1) @@ -42,17 +43,19 @@ public override void Print(ExpressionPrinter expressionPrinter) { expressionPrinter.Visit(Subquery); } + expressionPrinter.Append(")"); } + public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is ScalarSubqueryExpression subSelectExpression - && Equals(subSelectExpression)); + && (ReferenceEquals(this, obj) + || obj is ScalarSubqueryExpression subSelectExpression + && Equals(subSelectExpression)); private bool Equals(ScalarSubqueryExpression scalarSubqueryExpression) => base.Equals(scalarSubqueryExpression) - && Subquery.Equals(scalarSubqueryExpression.Subquery); + && Subquery.Equals(scalarSubqueryExpression.Subquery); public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), Subquery); } diff --git a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs index 91da73899b6..06b12b90a04 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -15,6 +15,7 @@ public class SelectExpression : TableExpressionBase { private IDictionary _projectionMapping = new Dictionary(); private readonly List _projection = new List(); + private readonly IDictionary> _entityProjectionCache = new Dictionary>(); @@ -57,18 +58,20 @@ internal SelectExpression( } internal SelectExpression(IEntityType entityType) - : this(entityType, new TableExpression( - entityType.GetTableName(), - entityType.GetSchema(), - entityType.GetTableName().ToLower().Substring(0, 1))) + : this( + entityType, new TableExpression( + entityType.GetTableName(), + entityType.GetSchema(), + entityType.GetTableName().ToLower().Substring(0, 1))) { } internal SelectExpression(IEntityType entityType, string sql, Expression arguments) - : this(entityType, new FromSqlExpression( - sql, - arguments, - entityType.GetTableName().ToLower().Substring(0, 1))) + : this( + entityType, new FromSqlExpression( + sql, + arguments, + entityType.GetTableName().ToLower().Substring(0, 1))) { } @@ -91,15 +94,15 @@ private SelectExpression(IEntityType entityType, TableExpressionBase tableExpres public bool IsNonComposedFromSql() => Limit == null - && Offset == null - && !IsDistinct - && Predicate == null - && GroupBy.Count == 0 - && Having == null - && Orderings.Count == 0 - && Tables.Count == 1 - && Tables[0] is FromSqlExpression fromSql - && Projection.All(pe => pe.Expression is ColumnExpression column ? ReferenceEquals(column.Table, fromSql) : false); + && Offset == null + && !IsDistinct + && Predicate == null + && GroupBy.Count == 0 + && Having == null + && Orderings.Count == 0 + && Tables.Count == 1 + && Tables[0] is FromSqlExpression fromSql + && Projection.All(pe => pe.Expression is ColumnExpression column ? ReferenceEquals(column.Table, fromSql) : false); public void ApplyProjection() { @@ -119,12 +122,14 @@ public void ApplyProjection() { map[property] = AddToProjection(entityProjection.BindProperty(property)); } + result[keyValuePair.Key] = Constant(map); } else { - result[keyValuePair.Key] = Constant(AddToProjection( - (SqlExpression)keyValuePair.Value, keyValuePair.Key.Last?.Name)); + result[keyValuePair.Key] = Constant( + AddToProjection( + (SqlExpression)keyValuePair.Value, keyValuePair.Key.Last?.Name)); } } @@ -159,7 +164,8 @@ private int AddToProjection(SqlExpression sqlExpression, string alias) var baseAlias = alias ?? (sqlExpression as ColumnExpression)?.Name ?? (Alias != null ? "c" : null); var currentAlias = baseAlias ?? ""; - if (Alias != null && baseAlias != null) + if (Alias != null + && baseAlias != null) { var counter = 0; while (_projection.Any(pe => string.Equals(pe.Alias, currentAlias, StringComparison.OrdinalIgnoreCase))) @@ -191,7 +197,10 @@ public IDictionary AddToProjection(EntityProjectionExpression en public void PrepareForAggregate() { - if (IsDistinct || Limit != null || Offset != null || GroupBy.Count > 0) + if (IsDistinct + || Limit != null + || Offset != null + || GroupBy.Count > 0) { PushdownIntoSubquery(); } @@ -205,7 +214,8 @@ public void ApplyPredicate(SqlExpression expression) return; } - if (Limit != null || Offset != null) + if (Limit != null + || Offset != null) { expression = new SqlRemappingVisitor(PushdownIntoSubquery(), (SelectExpression)Tables[0]).Remap(expression); } @@ -251,6 +261,7 @@ private void AppendGroupBy(Expression keySelector) { _groupBy.Add(sqlExpression); } + break; case NewExpression newExpression: @@ -258,6 +269,7 @@ private void AppendGroupBy(Expression keySelector) { AppendGroupBy(argument); } + break; case MemberInitExpression memberInitExpression: @@ -266,11 +278,12 @@ private void AppendGroupBy(Expression keySelector) { AppendGroupBy(((MemberAssignment)argument).Expression); } + break; case UnaryExpression unaryExpression - when unaryExpression.NodeType == ExpressionType.Convert - || unaryExpression.NodeType == ExpressionType.ConvertChecked: + when unaryExpression.NodeType == ExpressionType.Convert + || unaryExpression.NodeType == ExpressionType.ConvertChecked: AppendGroupBy(unaryExpression.Operand); break; @@ -279,14 +292,15 @@ private void AppendGroupBy(Expression keySelector) } } - public void ApplyOrdering(OrderingExpression orderingExpression) { - if (IsDistinct || Limit != null || Offset != null) + if (IsDistinct + || Limit != null + || Offset != null) { orderingExpression = orderingExpression.Update( new SqlRemappingVisitor(PushdownIntoSubquery(), (SelectExpression)Tables[0]) - .Remap(orderingExpression.Expression)); + .Remap(orderingExpression.Expression)); } _orderings.Clear(); @@ -313,7 +327,8 @@ public void ApplyLimit(SqlExpression sqlExpression) public void ApplyOffset(SqlExpression sqlExpression) { - if (Limit != null || Offset != null) + if (Limit != null + || Offset != null) { PushdownIntoSubquery(); } @@ -344,7 +359,8 @@ public void ReverseOrderings() public void ApplyDistinct() { - if (Limit != null || Offset != null) + if (Limit != null + || Offset != null) { PushdownIntoSubquery(); } @@ -416,8 +432,10 @@ private enum SetOperationType public void ApplyExcept(SelectExpression source2, bool distinct) => ApplySetOperation(SetOperationType.Except, source2, distinct); + public void ApplyIntersect(SelectExpression source2, bool distinct) => ApplySetOperation(SetOperationType.Intersect, source2, distinct); + public void ApplyUnion(SelectExpression source2, bool distinct) => ApplySetOperation(SetOperationType.Union, source2, distinct); @@ -450,56 +468,57 @@ private void ApplySetOperation(SetOperationType setOperationType, SelectExpressi _ => throw new InvalidOperationException($"Invalid {nameof(setOperationType)}: {setOperationType}") }); - if (_projection.Any() || select2._projection.Any()) + if (_projection.Any() + || select2._projection.Any()) { throw new InvalidOperationException( "Can't process set operations after client evaluation, consider moving the operation" + " before the last Select() call (see issue #16243)"); } - else + + if (select1._projectionMapping.Count != select2._projectionMapping.Count) { - if (select1._projectionMapping.Count != select2._projectionMapping.Count) + // Should not be possible after compiler checks + throw new InvalidOperationException("Different projection mapping count in set operation"); + } + + foreach (var joinedMapping in select1._projectionMapping.Join( + select2._projectionMapping, + kv => kv.Key, + kv => kv.Key, + (kv1, kv2) => (kv1.Key, Value1: kv1.Value, Value2: kv2.Value))) + { + if (joinedMapping.Value1 is EntityProjectionExpression entityProjection1 + && joinedMapping.Value2 is EntityProjectionExpression entityProjection2) { - // Should not be possible after compiler checks - throw new InvalidOperationException("Different projection mapping count in set operation"); + handleEntityMapping(joinedMapping.Key, select1, entityProjection1, select2, entityProjection2); + continue; } - foreach (var joinedMapping in select1._projectionMapping.Join( - select2._projectionMapping, - kv => kv.Key, - kv => kv.Key, - (kv1, kv2) => (kv1.Key, Value1: kv1.Value, Value2: kv2.Value))) + if (joinedMapping.Value1 is SqlExpression innerColumn1 + && joinedMapping.Value2 is SqlExpression innerColumn2) { - if (joinedMapping.Value1 is EntityProjectionExpression entityProjection1 - && joinedMapping.Value2 is EntityProjectionExpression entityProjection2) + // For now, make sure that both sides output the same store type, otherwise the query may fail. + // TODO: with #15586 we'll be able to also allow different store types which are implicitly convertible to one another. + if (innerColumn1.TypeMapping.StoreType != innerColumn2.TypeMapping.StoreType) { - handleEntityMapping(joinedMapping.Key, select1, entityProjection1, select2, entityProjection2); - continue; + throw new InvalidOperationException("Set operations over different store types are currently unsupported"); } - if (joinedMapping.Value1 is SqlExpression innerColumn1 - && joinedMapping.Value2 is SqlExpression innerColumn2) - { - // For now, make sure that both sides output the same store type, otherwise the query may fail. - // TODO: with #15586 we'll be able to also allow different store types which are implicitly convertible to one another. - if (innerColumn1.TypeMapping.StoreType != innerColumn2.TypeMapping.StoreType) - { - throw new InvalidOperationException("Set operations over different store types are currently unsupported"); - } - - var alias = generateUniqueAlias(joinedMapping.Key.Last?.Name - ?? (innerColumn1 as ColumnExpression)?.Name - ?? "c"); - - var innerProjection = new ProjectionExpression(innerColumn1, alias); - select1._projection.Add(innerProjection); - select2._projection.Add(new ProjectionExpression(innerColumn2, alias)); - _projectionMapping[joinedMapping.Key] = new ColumnExpression(innerProjection, setExpression); - continue; - } + var alias = generateUniqueAlias( + joinedMapping.Key.Last?.Name + ?? (innerColumn1 as ColumnExpression)?.Name + ?? "c"); - throw new InvalidOperationException($"Non-matching or unknown projection mapping type in set operation ({joinedMapping.Value1.GetType().Name} and {joinedMapping.Value2.GetType().Name})"); + var innerProjection = new ProjectionExpression(innerColumn1, alias); + select1._projection.Add(innerProjection); + select2._projection.Add(new ProjectionExpression(innerColumn2, alias)); + _projectionMapping[joinedMapping.Key] = new ColumnExpression(innerProjection, setExpression); + continue; } + + throw new InvalidOperationException( + $"Non-matching or unknown projection mapping type in set operation ({joinedMapping.Value1.GetType().Name} and {joinedMapping.Value2.GetType().Name})"); } Offset = null; @@ -519,7 +538,8 @@ void handleEntityMapping( { if (projection1.EntityType != projection2.EntityType) { - throw new InvalidOperationException("Set operations over different entity types are currently unsupported (see #16298)"); + throw new InvalidOperationException( + "Set operations over different entity types are currently unsupported (see #16298)"); } var propertyExpressions = new Dictionary(); @@ -578,7 +598,7 @@ public IDictionary PushdownIntoSubquery() Predicate = Predicate, Having = Having, Offset = Offset, - Limit = Limit, + Limit = Limit }; var projectionMap = new Dictionary(); @@ -597,7 +617,7 @@ EntityProjectionExpression liftEntityProjectionFromSubquery(EntityProjectionExpr var newEntityProjection = new EntityProjectionExpression(entityProjection.EntityType, propertyExpressions); // Also lift nested entity projections foreach (var navigation in entityProjection.EntityType.GetTypesInHierarchy() - .SelectMany(EntityTypeExtensions.GetDeclaredNavigations)) + .SelectMany(EntityTypeExtensions.GetDeclaredNavigations)) { var boundEntityShaperExpression = entityProjection.BindNavigation(navigation); if (boundEntityShaperExpression != null) @@ -650,7 +670,8 @@ EntityProjectionExpression liftEntityProjectionFromSubquery(EntityProjectionExpr { _identifier.Add(outerColumn); } - else if (!IsDistinct && GroupBy.Count == 0) + else if (!IsDistinct + && GroupBy.Count == 0) { outerColumn = subquery.GenerateOuterColumn(identifier); _identifier.Add(outerColumn); @@ -666,7 +687,8 @@ EntityProjectionExpression liftEntityProjectionFromSubquery(EntityProjectionExpr { _childIdentifiers.Add(outerColumn); } - else if (!IsDistinct && GroupBy.Count == 0) + else if (!IsDistinct + && GroupBy.Count == 0) { outerColumn = subquery.GenerateOuterColumn(identifier); _childIdentifiers.Add(outerColumn); @@ -693,7 +715,8 @@ EntityProjectionExpression liftEntityProjectionFromSubquery(EntityProjectionExpr } } - if (subquery.Offset == null && subquery.Limit == null) + if (subquery.Offset == null + && subquery.Limit == null) { subquery.ClearOrdering(); } @@ -780,7 +803,8 @@ public Expression ApplyCollectionJoin( || innerSelectExpression.Tables.Count > 1 || innerSelectExpression.GroupBy.Count > 1) { - var sqlRemappingVisitor = new SqlRemappingVisitor(innerSelectExpression.PushdownIntoSubquery(), + var sqlRemappingVisitor = new SqlRemappingVisitor( + innerSelectExpression.PushdownIntoSubquery(), (SelectExpression)innerSelectExpression.Tables[0]); joinPredicate = sqlRemappingVisitor.Remap(joinPredicate); } @@ -829,8 +853,8 @@ private Expression GetIdentifierAccessor(IEnumerable identifyingP updatedExpressions.Add( projectionBindingExpression.Type.IsValueType - ? Convert(projectionBindingExpression, typeof(object)) - : (Expression)projectionBindingExpression); + ? Convert(projectionBindingExpression, typeof(object)) + : (Expression)projectionBindingExpression); } return NewArrayInit( @@ -904,7 +928,8 @@ private SqlExpression TryExtractJoinKey(SelectExpression selectExpression) return null; } - private SqlExpression TryExtractJoinKey(SelectExpression selectExpression, SqlExpression predicate, out SqlExpression updatedPredicate) + private SqlExpression TryExtractJoinKey( + SelectExpression selectExpression, SqlExpression predicate, out SqlExpression updatedPredicate) { if (predicate is SqlBinaryExpression sqlBinaryExpression) { @@ -1039,7 +1064,8 @@ private void AddJoin( SqlExpression joinPredicate = null) { // Try to convert Apply to normal join - if (joinType == JoinType.CrossApply || joinType == JoinType.OuterApply) + if (joinType == JoinType.CrossApply + || joinType == JoinType.OuterApply) { // Doing for limit only since limit + offset may need sum var limit = innerSelectExpression.Limit; @@ -1071,7 +1097,7 @@ private void AddJoin( var subquery = (SelectExpression)innerSelectExpression.Tables[0]; joinPredicate = new SqlRemappingVisitor( - projectionMappings, subquery) + projectionMappings, subquery) .Remap(joinPredicate); var outerColumn = subquery.GenerateOuterColumn(rowNumberExpression, "row"); @@ -1080,7 +1106,8 @@ private void AddJoin( innerSelectExpression.ApplyPredicate(predicate); } - AddJoin(joinType == JoinType.CrossApply ? JoinType.InnerJoin : JoinType.LeftJoin, + AddJoin( + joinType == JoinType.CrossApply ? JoinType.InnerJoin : JoinType.LeftJoin, innerSelectExpression, transparentIdentifierType, joinPredicate); return; } @@ -1092,7 +1119,10 @@ private void AddJoin( } // Verify what are the cases of pushdown for inner & outer both sides - if (Limit != null || Offset != null || IsDistinct || GroupBy.Count > 0) + if (Limit != null + || Offset != null + || IsDistinct + || GroupBy.Count > 0) { var sqlRemappingVisitor = new SqlRemappingVisitor(PushdownIntoSubquery(), (SelectExpression)Tables[0]); innerSelectExpression = sqlRemappingVisitor.Remap(innerSelectExpression); @@ -1108,7 +1138,7 @@ private void AddJoin( || innerSelectExpression.GroupBy.Count > 0) { joinPredicate = new SqlRemappingVisitor( - innerSelectExpression.PushdownIntoSubquery(), (SelectExpression)innerSelectExpression.Tables[0]) + innerSelectExpression.PushdownIntoSubquery(), (SelectExpression)innerSelectExpression.Tables[0]) .Remap(joinPredicate); } @@ -1116,6 +1146,7 @@ private void AddJoin( { _identifier.AddRange(innerSelectExpression._identifier); } + var innerTable = innerSelectExpression.Tables.Single(); var joinTable = (TableExpressionBase)(joinType switch { @@ -1154,6 +1185,7 @@ private void AddJoin( projectionToAdd = column.MakeNullable(); } } + projectionMapping[projection.Key.Prepend(innerMemberInfo)] = projectionToAdd; } @@ -1195,11 +1227,11 @@ public override Expression Visit(Expression expression) switch (expression) { case SqlExpression sqlExpression - when _mappings.TryGetValue(sqlExpression, out var outer): + when _mappings.TryGetValue(sqlExpression, out var outer): return outer; case ColumnExpression columnExpression - when _subquery.ContainsTableReference(columnExpression.Table): + when _subquery.ContainsTableReference(columnExpression.Table): var index = _subquery.AddToProjection(columnExpression); var projectionExpression = _subquery._projection[index]; return new ColumnExpression(projectionExpression, _subquery); @@ -1243,8 +1275,9 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) var groupBy = _groupBy.ToList(); _groupBy.Clear(); - _groupBy.AddRange(GroupBy.Select(e => (SqlExpression)visitor.Visit(e)) - .Where(e => !(e is SqlConstantExpression || e is SqlParameterExpression))); + _groupBy.AddRange( + GroupBy.Select(e => (SqlExpression)visitor.Visit(e)) + .Where(e => !(e is SqlConstantExpression || e is SqlParameterExpression))); Having = (SqlExpression)visitor.Visit(Having); @@ -1303,7 +1336,7 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) var newGroupingKey = (SqlExpression)visitor.Visit(groupingKey); changed |= newGroupingKey != groupingKey; if (!(newGroupingKey is SqlConstantExpression - || newGroupingKey is SqlParameterExpression)) + || newGroupingKey is SqlParameterExpression)) { groupBy.Add(newGroupingKey); } @@ -1335,7 +1368,7 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) Having = havingExpression, Offset = offset, Limit = limit, - IsDistinct = IsDistinct, + IsDistinct = IsDistinct }; newSelectExpression._identifier.AddRange(_identifier); @@ -1350,9 +1383,9 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is SelectExpression selectExpression - && Equals(selectExpression)); + && (ReferenceEquals(this, obj) + || obj is SelectExpression selectExpression + && Equals(selectExpression)); private bool Equals(SelectExpression selectExpression) { @@ -1385,7 +1418,7 @@ private bool Equals(SelectExpression selectExpression) } if (!(Predicate == null && selectExpression.Predicate == null - || Predicate != null && Predicate.Equals(selectExpression.Predicate))) + || Predicate != null && Predicate.Equals(selectExpression.Predicate))) { return false; } @@ -1401,7 +1434,7 @@ private bool Equals(SelectExpression selectExpression) } if (!(Having == null && selectExpression.Having == null - || Having != null && Predicate.Equals(selectExpression.Having))) + || Having != null && Predicate.Equals(selectExpression.Having))) { return false; } @@ -1412,13 +1445,13 @@ private bool Equals(SelectExpression selectExpression) } if (!(Offset == null && selectExpression.Offset == null - || Offset != null && Offset.Equals(selectExpression.Offset))) + || Offset != null && Offset.Equals(selectExpression.Offset))) { return false; } if (!(Limit == null && selectExpression.Limit == null - || Limit != null && Limit.Equals(selectExpression.Limit))) + || Limit != null && Limit.Equals(selectExpression.Limit))) { return false; } @@ -1452,7 +1485,7 @@ public SelectExpression Update( Having = havingExpression, Offset = offset, Limit = limit, - IsDistinct = distinct, + IsDistinct = distinct }; } @@ -1596,4 +1629,3 @@ public override void Print(ExpressionPrinter expressionPrinter) } } } - diff --git a/src/EFCore.Relational/Query/SqlExpressions/SetOperationBase.cs b/src/EFCore.Relational/Query/SqlExpressions/SetOperationBase.cs index 6ebc8a6f5c7..44e7bf0d876 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SetOperationBase.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SetOperationBase.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -23,14 +23,14 @@ protected SetOperationBase([NotNull] string alias, SelectExpression source1, Sel public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is SetOperationBase setOperationBase - && Equals(setOperationBase)); + && (ReferenceEquals(this, obj) + || obj is SetOperationBase setOperationBase + && Equals(setOperationBase)); private bool Equals(SetOperationBase setOperationBase) => IsDistinct == setOperationBase.IsDistinct - && Source1.Equals(setOperationBase.Source1) - && Source2.Equals(setOperationBase.Source2); + && Source1.Equals(setOperationBase.Source1) + && Source2.Equals(setOperationBase.Source2); public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), IsDistinct, Source1, Source2); diff --git a/src/EFCore.Relational/Query/SqlExpressions/SqlBinaryExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SqlBinaryExpression.cs index 3c3602eeaff..8dd34621ad8 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SqlBinaryExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SqlBinaryExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -30,7 +30,7 @@ public class SqlBinaryExpression : SqlExpression ExpressionType.Equal, ExpressionType.NotEqual, //ExpressionType.ExclusiveOr, - ExpressionType.Coalesce, + ExpressionType.Coalesce //ExpressionType.ArrayIndex, //ExpressionType.RightShift, //ExpressionType.LeftShift, @@ -111,21 +111,21 @@ public override void Print(ExpressionPrinter expressionPrinter) private bool RequiresBrackets(SqlExpression expression) { return expression is SqlBinaryExpression sqlBinary - && sqlBinary.OperatorType != ExpressionType.Coalesce - || expression is LikeExpression; + && sqlBinary.OperatorType != ExpressionType.Coalesce + || expression is LikeExpression; } public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is SqlBinaryExpression sqlBinaryExpression - && Equals(sqlBinaryExpression)); + && (ReferenceEquals(this, obj) + || obj is SqlBinaryExpression sqlBinaryExpression + && Equals(sqlBinaryExpression)); private bool Equals(SqlBinaryExpression sqlBinaryExpression) => base.Equals(sqlBinaryExpression) - && OperatorType == sqlBinaryExpression.OperatorType - && Left.Equals(sqlBinaryExpression.Left) - && Right.Equals(sqlBinaryExpression.Right); + && OperatorType == sqlBinaryExpression.OperatorType + && Left.Equals(sqlBinaryExpression.Left) + && Right.Equals(sqlBinaryExpression.Right); public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), OperatorType, Left, Right); } diff --git a/src/EFCore.Relational/Query/SqlExpressions/SqlConstantExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SqlConstantExpression.cs index 6e5870bfed6..b174814e57e 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SqlConstantExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SqlConstantExpression.cs @@ -1,8 +1,7 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Linq; using System.Collections; using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Storage; @@ -23,6 +22,7 @@ public SqlConstantExpression(ConstantExpression constantExpression, RelationalTy public virtual SqlExpression ApplyTypeMapping(RelationalTypeMapping typeMapping) => new SqlConstantExpression(_constantExpression, typeMapping); + protected override Expression VisitChildren(ExpressionVisitor visitor) => this; public override void Print(ExpressionPrinter expressionPrinter) => Print(Value, expressionPrinter); @@ -31,13 +31,13 @@ private void Print(object value, ExpressionPrinter expressionPrinter) public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is SqlConstantExpression sqlConstantExpression - && Equals(sqlConstantExpression)); + && (ReferenceEquals(this, obj) + || obj is SqlConstantExpression sqlConstantExpression + && Equals(sqlConstantExpression)); private bool Equals(SqlConstantExpression sqlConstantExpression) => base.Equals(sqlConstantExpression) - && ValueEquals(Value, sqlConstantExpression.Value); + && ValueEquals(Value, sqlConstantExpression.Value); private bool ValueEquals(object value1, object value2) { diff --git a/src/EFCore.Relational/Query/SqlExpressions/SqlExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SqlExpression.cs index ec2da23feb5..1c464a3849d 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SqlExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SqlExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -26,13 +26,13 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is SqlExpression sqlExpression - && Equals(sqlExpression)); + && (ReferenceEquals(this, obj) + || obj is SqlExpression sqlExpression + && Equals(sqlExpression)); private bool Equals(SqlExpression sqlExpression) => Type == sqlExpression.Type - && TypeMapping?.Equals(sqlExpression.TypeMapping) == true; + && TypeMapping?.Equals(sqlExpression.TypeMapping) == true; public override int GetHashCode() => HashCode.Combine(Type, TypeMapping); } diff --git a/src/EFCore.Relational/Query/SqlExpressions/SqlFragmentExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SqlFragmentExpression.cs index 313fa71336a..b77564aabd0 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SqlFragmentExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SqlFragmentExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -16,18 +16,19 @@ internal SqlFragmentExpression(string sql) public string Sql { get; } protected override Expression VisitChildren(ExpressionVisitor visitor) => this; + public override void Print(ExpressionPrinter expressionPrinter) => expressionPrinter.Append(Sql); public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is SqlFragmentExpression sqlFragmentExpression - && Equals(sqlFragmentExpression)); + && (ReferenceEquals(this, obj) + || obj is SqlFragmentExpression sqlFragmentExpression + && Equals(sqlFragmentExpression)); private bool Equals(SqlFragmentExpression sqlFragmentExpression) => base.Equals(sqlFragmentExpression) - && string.Equals(Sql, sqlFragmentExpression.Sql); + && string.Equals(Sql, sqlFragmentExpression.Sql); public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), Sql); } diff --git a/src/EFCore.Relational/Query/SqlExpressions/SqlFunctionExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SqlFunctionExpression.cs index 4fc68c10849..75ca4a7718a 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SqlFunctionExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SqlFunctionExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -15,7 +15,8 @@ public static SqlFunctionExpression CreateNiladic( string name, Type type, RelationalTypeMapping typeMapping) - => new SqlFunctionExpression(instance: null, schema: null, name, niladic: true, arguments: null, builtIn: true, type, typeMapping); + => new SqlFunctionExpression( + instance: null, schema: null, name, niladic: true, arguments: null, builtIn: true, type, typeMapping); public static SqlFunctionExpression CreateNiladic( string schema, @@ -148,17 +149,17 @@ public override void Print(ExpressionPrinter expressionPrinter) public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is SqlFunctionExpression sqlFunctionExpression - && Equals(sqlFunctionExpression)); + && (ReferenceEquals(this, obj) + || obj is SqlFunctionExpression sqlFunctionExpression + && Equals(sqlFunctionExpression)); private bool Equals(SqlFunctionExpression sqlFunctionExpression) => base.Equals(sqlFunctionExpression) - && string.Equals(Name, sqlFunctionExpression.Name) - && string.Equals(Schema, sqlFunctionExpression.Schema) - && ((Instance == null && sqlFunctionExpression.Instance == null) - || (Instance != null && Instance.Equals(sqlFunctionExpression.Instance))) - && Arguments.SequenceEqual(sqlFunctionExpression.Arguments); + && string.Equals(Name, sqlFunctionExpression.Name) + && string.Equals(Schema, sqlFunctionExpression.Schema) + && ((Instance == null && sqlFunctionExpression.Instance == null) + || (Instance != null && Instance.Equals(sqlFunctionExpression.Instance))) + && Arguments.SequenceEqual(sqlFunctionExpression.Arguments); public override int GetHashCode() { @@ -172,6 +173,7 @@ public override int GetHashCode() { hash.Add(Arguments[i]); } + return hash.ToHashCode(); } } diff --git a/src/EFCore.Relational/Query/SqlExpressions/SqlParameterExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SqlParameterExpression.cs index b67d9228c64..d781d77f0e8 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SqlParameterExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SqlParameterExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -21,19 +21,21 @@ internal SqlParameterExpression(ParameterExpression parameterExpression, Relatio public SqlExpression ApplyTypeMapping(RelationalTypeMapping typeMapping) => new SqlParameterExpression(_parameterExpression, typeMapping); + protected override Expression VisitChildren(ExpressionVisitor visitor) => this; + public override void Print(ExpressionPrinter expressionPrinter) => expressionPrinter.Append("@" + _parameterExpression.Name); public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is SqlParameterExpression sqlParameterExpression - && Equals(sqlParameterExpression)); + && (ReferenceEquals(this, obj) + || obj is SqlParameterExpression sqlParameterExpression + && Equals(sqlParameterExpression)); private bool Equals(SqlParameterExpression sqlParameterExpression) => base.Equals(sqlParameterExpression) - && string.Equals(Name, sqlParameterExpression.Name); + && string.Equals(Name, sqlParameterExpression.Name); public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), Name); } diff --git a/src/EFCore.Relational/Query/SqlExpressions/SqlUnaryExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SqlUnaryExpression.cs index 342aa5a7a9b..17d734e4b8f 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SqlUnaryExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SqlUnaryExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -17,8 +17,9 @@ public class SqlUnaryExpression : SqlExpression ExpressionType.NotEqual, ExpressionType.Convert, ExpressionType.Not, - ExpressionType.Negate, + ExpressionType.Negate }; + private static ExpressionType VerifyOperator(ExpressionType operatorType) => _allowedOperators.Contains(operatorType) ? operatorType @@ -66,16 +67,17 @@ public override void Print(ExpressionPrinter expressionPrinter) expressionPrinter.Append(")"); } } + public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is SqlUnaryExpression sqlUnaryExpression - && Equals(sqlUnaryExpression)); + && (ReferenceEquals(this, obj) + || obj is SqlUnaryExpression sqlUnaryExpression + && Equals(sqlUnaryExpression)); private bool Equals(SqlUnaryExpression sqlUnaryExpression) => base.Equals(sqlUnaryExpression) - && OperatorType == sqlUnaryExpression.OperatorType - && Operand.Equals(sqlUnaryExpression.Operand); + && OperatorType == sqlUnaryExpression.OperatorType + && Operand.Equals(sqlUnaryExpression.Operand); public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), OperatorType, Operand); } diff --git a/src/EFCore.Relational/Query/SqlExpressions/TableExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/TableExpression.cs index 17f1806df46..134b84a618d 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/TableExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/TableExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Relational/Query/SqlExpressions/TableExpressionBase.cs b/src/EFCore.Relational/Query/SqlExpressions/TableExpressionBase.cs index 2c4ee690583..ac267ffbe7e 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/TableExpressionBase.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/TableExpressionBase.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -24,11 +24,12 @@ protected TableExpressionBase([CanBeNull] string alias) public override Type Type => typeof(object); public sealed override ExpressionType NodeType => ExpressionType.Extension; public abstract void Print(ExpressionPrinter expressionPrinter); + public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is TableExpressionBase tableExpressionBase - && Equals(tableExpressionBase)); + && (ReferenceEquals(this, obj) + || obj is TableExpressionBase tableExpressionBase + && Equals(tableExpressionBase)); private bool Equals(TableExpressionBase tableExpressionBase) => string.Equals(Alias, tableExpressionBase.Alias); diff --git a/src/EFCore.Relational/Query/SqlExpressions/UnionExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/UnionExpression.cs index 94ce272bfab..96fab38c7eb 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/UnionExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/UnionExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -38,17 +38,19 @@ public override void Print(ExpressionPrinter expressionPrinter) { expressionPrinter.AppendLine(" ALL"); } + expressionPrinter.Visit(Source2); } + expressionPrinter.AppendLine() .AppendLine($") AS {Alias}"); } public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is UnionExpression unionExpression - && Equals(unionExpression)); + && (ReferenceEquals(this, obj) + || obj is UnionExpression unionExpression + && Equals(unionExpression)); private bool Equals(UnionExpression unionExpression) => base.Equals(unionExpression); diff --git a/src/EFCore.Relational/Scaffolding/DatabaseModelFactory.cs b/src/EFCore.Relational/Scaffolding/DatabaseModelFactory.cs index ca53b2b1b9c..5eddcdd829f 100644 --- a/src/EFCore.Relational/Scaffolding/DatabaseModelFactory.cs +++ b/src/EFCore.Relational/Scaffolding/DatabaseModelFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Data.Common; diff --git a/src/EFCore.Relational/Scaffolding/DatabaseModelFactoryOptions.cs b/src/EFCore.Relational/Scaffolding/DatabaseModelFactoryOptions.cs index 8a20e4c44c0..cd6ccd990bb 100644 --- a/src/EFCore.Relational/Scaffolding/DatabaseModelFactoryOptions.cs +++ b/src/EFCore.Relational/Scaffolding/DatabaseModelFactoryOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; @@ -8,7 +8,7 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding { /// - /// Specifies which metadata to read from the database. + /// Specifies which metadata to read from the database. /// public class DatabaseModelFactoryOptions { @@ -24,12 +24,12 @@ public DatabaseModelFactoryOptions([CanBeNull] IEnumerable tables = null } /// - /// Gets the list of tables to include. If empty, include all tables. + /// Gets the list of tables to include. If empty, include all tables. /// public virtual IEnumerable Tables { get; } /// - /// Gets the list of schemas to include. If empty, include all schemas. + /// Gets the list of schemas to include. If empty, include all schemas. /// public virtual IEnumerable Schemas { get; } } diff --git a/src/EFCore.Relational/Scaffolding/IProviderCodeGeneratorPlugin.cs b/src/EFCore.Relational/Scaffolding/IProviderCodeGeneratorPlugin.cs index 31a16c8d0f0..d203069dad2 100644 --- a/src/EFCore.Relational/Scaffolding/IProviderCodeGeneratorPlugin.cs +++ b/src/EFCore.Relational/Scaffolding/IProviderCodeGeneratorPlugin.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.Design; diff --git a/src/EFCore.Relational/Scaffolding/IProviderConfigurationCodeGenerator.cs b/src/EFCore.Relational/Scaffolding/IProviderConfigurationCodeGenerator.cs index 229016c1c66..a64fd02ff88 100644 --- a/src/EFCore.Relational/Scaffolding/IProviderConfigurationCodeGenerator.cs +++ b/src/EFCore.Relational/Scaffolding/IProviderConfigurationCodeGenerator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Relational/Scaffolding/Metadata/DatabasePrimaryKey.cs b/src/EFCore.Relational/Scaffolding/Metadata/DatabasePrimaryKey.cs index e8fb9e98f6f..4e7eca6bd12 100644 --- a/src/EFCore.Relational/Scaffolding/Metadata/DatabasePrimaryKey.cs +++ b/src/EFCore.Relational/Scaffolding/Metadata/DatabasePrimaryKey.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; diff --git a/src/EFCore.Relational/Scaffolding/Metadata/DatabaseUniqueConstraint.cs b/src/EFCore.Relational/Scaffolding/Metadata/DatabaseUniqueConstraint.cs index e8936db3e5c..074354b7d26 100644 --- a/src/EFCore.Relational/Scaffolding/Metadata/DatabaseUniqueConstraint.cs +++ b/src/EFCore.Relational/Scaffolding/Metadata/DatabaseUniqueConstraint.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; diff --git a/src/EFCore.Relational/Scaffolding/Metadata/DatabaseView.cs b/src/EFCore.Relational/Scaffolding/Metadata/DatabaseView.cs index 78457252c1c..1f936e7ad18 100644 --- a/src/EFCore.Relational/Scaffolding/Metadata/DatabaseView.cs +++ b/src/EFCore.Relational/Scaffolding/Metadata/DatabaseView.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. namespace Microsoft.EntityFrameworkCore.Scaffolding.Metadata diff --git a/src/EFCore.Relational/Scaffolding/ProviderCodeGenerator.cs b/src/EFCore.Relational/Scaffolding/ProviderCodeGenerator.cs index 258e26b9385..f48a8815497 100644 --- a/src/EFCore.Relational/Scaffolding/ProviderCodeGenerator.cs +++ b/src/EFCore.Relational/Scaffolding/ProviderCodeGenerator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Relational/Scaffolding/ProviderCodeGeneratorDependencies.cs b/src/EFCore.Relational/Scaffolding/ProviderCodeGeneratorDependencies.cs index 81e7656c882..6b5f40b1c4d 100644 --- a/src/EFCore.Relational/Scaffolding/ProviderCodeGeneratorDependencies.cs +++ b/src/EFCore.Relational/Scaffolding/ProviderCodeGeneratorDependencies.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; diff --git a/src/EFCore.Relational/Scaffolding/ProviderCodeGeneratorPlugin.cs b/src/EFCore.Relational/Scaffolding/ProviderCodeGeneratorPlugin.cs index 6615dca862e..472d9ab6174 100644 --- a/src/EFCore.Relational/Scaffolding/ProviderCodeGeneratorPlugin.cs +++ b/src/EFCore.Relational/Scaffolding/ProviderCodeGeneratorPlugin.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.Design; diff --git a/src/EFCore.Relational/Storage/IParameterNameGeneratorFactory.cs b/src/EFCore.Relational/Storage/IParameterNameGeneratorFactory.cs index 7cfae9acfc7..8f03f8b6614 100644 --- a/src/EFCore.Relational/Storage/IParameterNameGeneratorFactory.cs +++ b/src/EFCore.Relational/Storage/IParameterNameGeneratorFactory.cs @@ -14,9 +14,9 @@ namespace Microsoft.EntityFrameworkCore.Storage /// not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IParameterNameGeneratorFactory diff --git a/src/EFCore.Relational/Storage/IRawSqlCommandBuilder.cs b/src/EFCore.Relational/Storage/IRawSqlCommandBuilder.cs index 4f5a352e790..08ecfb28bce 100644 --- a/src/EFCore.Relational/Storage/IRawSqlCommandBuilder.cs +++ b/src/EFCore.Relational/Storage/IRawSqlCommandBuilder.cs @@ -16,9 +16,9 @@ namespace Microsoft.EntityFrameworkCore.Storage /// not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IRawSqlCommandBuilder diff --git a/src/EFCore.Relational/Storage/IRelationalCommand.cs b/src/EFCore.Relational/Storage/IRelationalCommand.cs index f508fb367c6..cc938ffe4de 100644 --- a/src/EFCore.Relational/Storage/IRelationalCommand.cs +++ b/src/EFCore.Relational/Storage/IRelationalCommand.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; diff --git a/src/EFCore.Relational/Storage/IRelationalCommandBuilder.cs b/src/EFCore.Relational/Storage/IRelationalCommandBuilder.cs index 96469087f62..d08cc0c8bff 100644 --- a/src/EFCore.Relational/Storage/IRelationalCommandBuilder.cs +++ b/src/EFCore.Relational/Storage/IRelationalCommandBuilder.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; @@ -30,7 +30,7 @@ public interface IRelationalCommandBuilder IRelationalCommandBuilder AddParameter([NotNull] IRelationalParameter parameter); /// - /// The source for s to use. + /// The source for s to use. /// IRelationalTypeMappingSource TypeMappingSource { get; } diff --git a/src/EFCore.Relational/Storage/IRelationalCommandBuilderFactory.cs b/src/EFCore.Relational/Storage/IRelationalCommandBuilderFactory.cs index 1b6a0dcf666..9f654e499d1 100644 --- a/src/EFCore.Relational/Storage/IRelationalCommandBuilderFactory.cs +++ b/src/EFCore.Relational/Storage/IRelationalCommandBuilderFactory.cs @@ -14,9 +14,9 @@ namespace Microsoft.EntityFrameworkCore.Storage /// not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IRelationalCommandBuilderFactory diff --git a/src/EFCore.Relational/Storage/IRelationalConnection.cs b/src/EFCore.Relational/Storage/IRelationalConnection.cs index db9a77f7a1d..42281916753 100644 --- a/src/EFCore.Relational/Storage/IRelationalConnection.cs +++ b/src/EFCore.Relational/Storage/IRelationalConnection.cs @@ -18,8 +18,8 @@ namespace Microsoft.EntityFrameworkCore.Storage /// not used in application code. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -37,7 +37,7 @@ public interface IRelationalConnection : IRelationalTransactionManager, IDisposa DbConnection DbConnection { get; } /// - /// The currently in use, or null if not known. + /// The currently in use, or null if not known. /// DbContext Context { get; } diff --git a/src/EFCore.Relational/Storage/IRelationalDatabaseCreator.cs b/src/EFCore.Relational/Storage/IRelationalDatabaseCreator.cs index 945c42aea52..cb24a99d2ff 100644 --- a/src/EFCore.Relational/Storage/IRelationalDatabaseCreator.cs +++ b/src/EFCore.Relational/Storage/IRelationalDatabaseCreator.cs @@ -16,8 +16,8 @@ namespace Microsoft.EntityFrameworkCore.Storage /// not used in application code. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Relational/Storage/IRelationalTransactionFactory.cs b/src/EFCore.Relational/Storage/IRelationalTransactionFactory.cs index 859b29658ab..ba3f0c736d9 100644 --- a/src/EFCore.Relational/Storage/IRelationalTransactionFactory.cs +++ b/src/EFCore.Relational/Storage/IRelationalTransactionFactory.cs @@ -17,9 +17,9 @@ namespace Microsoft.EntityFrameworkCore.Storage /// This type is typically used by database providers It is generally not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IRelationalTransactionFactory diff --git a/src/EFCore.Relational/Storage/IRelationalTransactionManager.cs b/src/EFCore.Relational/Storage/IRelationalTransactionManager.cs index 15e2bb19ea1..0c5da17a843 100644 --- a/src/EFCore.Relational/Storage/IRelationalTransactionManager.cs +++ b/src/EFCore.Relational/Storage/IRelationalTransactionManager.cs @@ -19,8 +19,8 @@ namespace Microsoft.EntityFrameworkCore.Storage /// not used in application code. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -55,8 +55,8 @@ public interface IRelationalTransactionManager : IDbContextTransactionManager /// The transaction to be used. /// A to observe while waiting for the task to complete. /// An instance of that wraps the provided transaction. - Task UseTransactionAsync([CanBeNull] - DbTransaction transaction, + Task UseTransactionAsync( + [CanBeNull] DbTransaction transaction, CancellationToken cancellationToken = default); } } diff --git a/src/EFCore.Relational/Storage/IRelationalTypeMappingSource.cs b/src/EFCore.Relational/Storage/IRelationalTypeMappingSource.cs index 2d119f5a9e8..83dba589c40 100644 --- a/src/EFCore.Relational/Storage/IRelationalTypeMappingSource.cs +++ b/src/EFCore.Relational/Storage/IRelationalTypeMappingSource.cs @@ -22,9 +22,9 @@ namespace Microsoft.EntityFrameworkCore.Storage /// not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IRelationalTypeMappingSource : ITypeMappingSource diff --git a/src/EFCore.Relational/Storage/IRelationalTypeMappingSourcePlugin.cs b/src/EFCore.Relational/Storage/IRelationalTypeMappingSourcePlugin.cs index f0adbe52339..676bba351b4 100644 --- a/src/EFCore.Relational/Storage/IRelationalTypeMappingSourcePlugin.cs +++ b/src/EFCore.Relational/Storage/IRelationalTypeMappingSourcePlugin.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.Extensions.DependencyInjection; @@ -10,10 +10,10 @@ namespace Microsoft.EntityFrameworkCore.Storage /// Represents a plugin relational type mapping source. /// /// - /// The service lifetime is and multiple registrations - /// are allowed. This means a single instance of each service is used by many + /// The service lifetime is and multiple registrations + /// are allowed. This means a single instance of each service is used by many /// instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public interface IRelationalTypeMappingSourcePlugin diff --git a/src/EFCore.Relational/Storage/IRelationalValueBufferFactoryFactory.cs b/src/EFCore.Relational/Storage/IRelationalValueBufferFactoryFactory.cs index 435a8b92c0a..62ba8d3d688 100644 --- a/src/EFCore.Relational/Storage/IRelationalValueBufferFactoryFactory.cs +++ b/src/EFCore.Relational/Storage/IRelationalValueBufferFactoryFactory.cs @@ -18,9 +18,9 @@ namespace Microsoft.EntityFrameworkCore.Storage /// not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IRelationalValueBufferFactoryFactory diff --git a/src/EFCore.Relational/Storage/ISqlGenerationHelper.cs b/src/EFCore.Relational/Storage/ISqlGenerationHelper.cs index f7774e9ce39..ed00025daff 100644 --- a/src/EFCore.Relational/Storage/ISqlGenerationHelper.cs +++ b/src/EFCore.Relational/Storage/ISqlGenerationHelper.cs @@ -16,9 +16,9 @@ namespace Microsoft.EntityFrameworkCore.Storage /// not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface ISqlGenerationHelper diff --git a/src/EFCore.Relational/Storage/Internal/DynamicRelationalParameter.cs b/src/EFCore.Relational/Storage/Internal/DynamicRelationalParameter.cs index 9c05e55b4d9..3333f33c24b 100644 --- a/src/EFCore.Relational/Storage/Internal/DynamicRelationalParameter.cs +++ b/src/EFCore.Relational/Storage/Internal/DynamicRelationalParameter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Relational/Storage/Internal/INamedConnectionStringResolver.cs b/src/EFCore.Relational/Storage/Internal/INamedConnectionStringResolver.cs index d0758206264..e3acb7f21ac 100644 --- a/src/EFCore.Relational/Storage/Internal/INamedConnectionStringResolver.cs +++ b/src/EFCore.Relational/Storage/Internal/INamedConnectionStringResolver.cs @@ -14,8 +14,8 @@ namespace Microsoft.EntityFrameworkCore.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Relational/Storage/Internal/NamedConnectionStringResolver.cs b/src/EFCore.Relational/Storage/Internal/NamedConnectionStringResolver.cs index fb9a09fa0fe..01eaa307d12 100644 --- a/src/EFCore.Relational/Storage/Internal/NamedConnectionStringResolver.cs +++ b/src/EFCore.Relational/Storage/Internal/NamedConnectionStringResolver.cs @@ -16,8 +16,8 @@ namespace Microsoft.EntityFrameworkCore.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Relational/Storage/Internal/NamedConnectionStringResolverBase.cs b/src/EFCore.Relational/Storage/Internal/NamedConnectionStringResolverBase.cs index df23b8a282a..7c014376151 100644 --- a/src/EFCore.Relational/Storage/Internal/NamedConnectionStringResolverBase.cs +++ b/src/EFCore.Relational/Storage/Internal/NamedConnectionStringResolverBase.cs @@ -16,8 +16,8 @@ namespace Microsoft.EntityFrameworkCore.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Relational/Storage/Internal/RawRelationalParameter.cs b/src/EFCore.Relational/Storage/Internal/RawRelationalParameter.cs index c0481877666..5e0cb1a2f0e 100644 --- a/src/EFCore.Relational/Storage/Internal/RawRelationalParameter.cs +++ b/src/EFCore.Relational/Storage/Internal/RawRelationalParameter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; diff --git a/src/EFCore.Relational/Storage/Internal/RawSqlCommandBuilder.cs b/src/EFCore.Relational/Storage/Internal/RawSqlCommandBuilder.cs index 811b1e719e9..efe6e94c626 100644 --- a/src/EFCore.Relational/Storage/Internal/RawSqlCommandBuilder.cs +++ b/src/EFCore.Relational/Storage/Internal/RawSqlCommandBuilder.cs @@ -17,9 +17,9 @@ namespace Microsoft.EntityFrameworkCore.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class RawSqlCommandBuilder : IRawSqlCommandBuilder diff --git a/src/EFCore.Relational/Storage/Internal/TypeMappedPropertyRelationalParameter.cs b/src/EFCore.Relational/Storage/Internal/TypeMappedPropertyRelationalParameter.cs index 01faa66f2d7..f754dacaf18 100644 --- a/src/EFCore.Relational/Storage/Internal/TypeMappedPropertyRelationalParameter.cs +++ b/src/EFCore.Relational/Storage/Internal/TypeMappedPropertyRelationalParameter.cs @@ -1,11 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Data.Common; using System.Diagnostics; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Metadata.Internal; namespace Microsoft.EntityFrameworkCore.Storage.Internal { diff --git a/src/EFCore.Relational/Storage/Internal/TypeMappedRelationalParameter.cs b/src/EFCore.Relational/Storage/Internal/TypeMappedRelationalParameter.cs index 717922fa059..c7fe4d6cc33 100644 --- a/src/EFCore.Relational/Storage/Internal/TypeMappedRelationalParameter.cs +++ b/src/EFCore.Relational/Storage/Internal/TypeMappedRelationalParameter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Data.Common; diff --git a/src/EFCore.Relational/Storage/ParameterNameGeneratorDependencies.cs b/src/EFCore.Relational/Storage/ParameterNameGeneratorDependencies.cs index 12e534a430b..8001a00955f 100644 --- a/src/EFCore.Relational/Storage/ParameterNameGeneratorDependencies.cs +++ b/src/EFCore.Relational/Storage/ParameterNameGeneratorDependencies.cs @@ -23,10 +23,10 @@ namespace Microsoft.EntityFrameworkCore.Storage /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . - /// This means a single instance of each service is used by many instances. + /// The service lifetime is . + /// This means a single instance of each service is used by many instances. /// The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public sealed class ParameterNameGeneratorDependencies diff --git a/src/EFCore.Relational/Storage/ParameterNameGeneratorFactory.cs b/src/EFCore.Relational/Storage/ParameterNameGeneratorFactory.cs index 4e4b7fb3794..1a4e15489cd 100644 --- a/src/EFCore.Relational/Storage/ParameterNameGeneratorFactory.cs +++ b/src/EFCore.Relational/Storage/ParameterNameGeneratorFactory.cs @@ -16,9 +16,9 @@ namespace Microsoft.EntityFrameworkCore.Storage /// not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class ParameterNameGeneratorFactory : IParameterNameGeneratorFactory diff --git a/src/EFCore.Relational/Storage/RawSqlCommand.cs b/src/EFCore.Relational/Storage/RawSqlCommand.cs index d2ca7f5fe84..5d5d4c70cd5 100644 --- a/src/EFCore.Relational/Storage/RawSqlCommand.cs +++ b/src/EFCore.Relational/Storage/RawSqlCommand.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; diff --git a/src/EFCore.Relational/Storage/RelationalCommand.cs b/src/EFCore.Relational/Storage/RelationalCommand.cs index 335ef946bd3..59fce60947f 100644 --- a/src/EFCore.Relational/Storage/RelationalCommand.cs +++ b/src/EFCore.Relational/Storage/RelationalCommand.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -577,7 +577,8 @@ protected virtual DbCommand CreateCommand( if (logger != null) { - command = logger.CommandCreated(connection, command, commandMethod, context, commandId, connectionId, startTime, stopwatch.Elapsed); + command = logger.CommandCreated( + connection, command, commandMethod, context, commandId, connectionId, startTime, stopwatch.Elapsed); } command.CommandText = CommandText; diff --git a/src/EFCore.Relational/Storage/RelationalCommandBuilder.cs b/src/EFCore.Relational/Storage/RelationalCommandBuilder.cs index ba9c11bf0df..98dba84af14 100644 --- a/src/EFCore.Relational/Storage/RelationalCommandBuilder.cs +++ b/src/EFCore.Relational/Storage/RelationalCommandBuilder.cs @@ -24,7 +24,7 @@ public class RelationalCommandBuilder : IRelationalCommandBuilder /// /// - /// Constructs a new . + /// Constructs a new . /// /// /// This type is typically used by database providers (and other extensions). It is generally @@ -46,7 +46,7 @@ public RelationalCommandBuilder( public virtual RelationalCommandBuilderDependencies Dependencies { get; } /// - /// The source for s to use. + /// The source for s to use. /// public virtual IRelationalTypeMappingSource TypeMappingSource => Dependencies.TypeMappingSource; diff --git a/src/EFCore.Relational/Storage/RelationalCommandBuilderDependencies.cs b/src/EFCore.Relational/Storage/RelationalCommandBuilderDependencies.cs index 95b7be21658..f33d7f71b81 100644 --- a/src/EFCore.Relational/Storage/RelationalCommandBuilderDependencies.cs +++ b/src/EFCore.Relational/Storage/RelationalCommandBuilderDependencies.cs @@ -25,9 +25,9 @@ namespace Microsoft.EntityFrameworkCore.Storage /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public sealed class RelationalCommandBuilderDependencies @@ -61,7 +61,7 @@ public RelationalCommandBuilderDependencies( } /// - /// The source for s to use. + /// The source for s to use. /// public IRelationalTypeMappingSource TypeMappingSource { get; } diff --git a/src/EFCore.Relational/Storage/RelationalCommandBuilderFactory.cs b/src/EFCore.Relational/Storage/RelationalCommandBuilderFactory.cs index fe74e7d1b7f..5a4868b070d 100644 --- a/src/EFCore.Relational/Storage/RelationalCommandBuilderFactory.cs +++ b/src/EFCore.Relational/Storage/RelationalCommandBuilderFactory.cs @@ -9,23 +9,23 @@ namespace Microsoft.EntityFrameworkCore.Storage { /// /// - /// Factory for instances. + /// Factory for instances. /// /// /// This type is typically used by database providers (and other extensions). It is generally /// not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class RelationalCommandBuilderFactory : IRelationalCommandBuilderFactory { /// /// - /// Constructs a new . + /// Constructs a new . /// /// /// This type is typically used by database providers (and other extensions). It is generally diff --git a/src/EFCore.Relational/Storage/RelationalCommandParameterObject.cs b/src/EFCore.Relational/Storage/RelationalCommandParameterObject.cs index ab4a049f524..26ebcb9656a 100644 --- a/src/EFCore.Relational/Storage/RelationalCommandParameterObject.cs +++ b/src/EFCore.Relational/Storage/RelationalCommandParameterObject.cs @@ -30,7 +30,7 @@ public readonly struct RelationalCommandParameterObject /// /// The connection on which the command will execute. /// The SQL parameter values to use, or null if none. - /// The current instance, or null if it is not known. + /// The current instance, or null if it is not known. /// A logger, or null if no logger is available. public RelationalCommandParameterObject( [NotNull] IRelationalConnection connection, @@ -57,7 +57,7 @@ public RelationalCommandParameterObject( public IReadOnlyDictionary ParameterValues { get; } /// - /// The current instance, or null if it is not known. + /// The current instance, or null if it is not known. /// public DbContext Context { get; } diff --git a/src/EFCore.Relational/Storage/RelationalConnection.cs b/src/EFCore.Relational/Storage/RelationalConnection.cs index ba6126e36da..d1dbb5aa3c4 100644 --- a/src/EFCore.Relational/Storage/RelationalConnection.cs +++ b/src/EFCore.Relational/Storage/RelationalConnection.cs @@ -11,9 +11,9 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; +using IsolationLevel = System.Data.IsolationLevel; namespace Microsoft.EntityFrameworkCore.Storage { @@ -26,8 +26,8 @@ namespace Microsoft.EntityFrameworkCore.Storage /// not used in application code. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -85,7 +85,7 @@ protected RelationalConnection([NotNull] RelationalConnectionDependencies depend public virtual Guid ConnectionId { get; } = Guid.NewGuid(); /// - /// The currently in use, or null if not known. + /// The currently in use, or null if not known. /// public virtual DbContext Context { get; } @@ -194,7 +194,7 @@ public virtual int? CommandTimeout /// The newly created transaction. [NotNull] // ReSharper disable once RedundantNameQualifier - public virtual IDbContextTransaction BeginTransaction() => BeginTransaction(System.Data.IsolationLevel.Unspecified); + public virtual IDbContextTransaction BeginTransaction() => BeginTransaction(IsolationLevel.Unspecified); /// /// Asynchronously begins a new transaction. @@ -206,7 +206,7 @@ public virtual int? CommandTimeout [NotNull] public virtual async Task BeginTransactionAsync(CancellationToken cancellationToken = default) // ReSharper disable once RedundantNameQualifier - => await BeginTransactionAsync(System.Data.IsolationLevel.Unspecified, cancellationToken); + => await BeginTransactionAsync(IsolationLevel.Unspecified, cancellationToken); /// /// Begins a new transaction. @@ -214,7 +214,7 @@ public virtual async Task BeginTransactionAsync(Cancellat /// The isolation level to use for the transaction. /// The newly created transaction. // ReSharper disable once RedundantNameQualifier - public virtual IDbContextTransaction BeginTransaction(System.Data.IsolationLevel isolationLevel) + public virtual IDbContextTransaction BeginTransaction(IsolationLevel isolationLevel) { Open(); @@ -254,7 +254,7 @@ public virtual IDbContextTransaction BeginTransaction(System.Data.IsolationLevel /// public virtual async Task BeginTransactionAsync( // ReSharper disable once RedundantNameQualifier - System.Data.IsolationLevel isolationLevel, + IsolationLevel isolationLevel, CancellationToken cancellationToken = default) { await OpenAsync(cancellationToken); @@ -676,6 +676,7 @@ public virtual async Task CloseAsync() { await CurrentTransaction.DisposeAsync(); } + ClearTransactions(clearAmbient: false); if (DbConnection.State != ConnectionState.Closed) @@ -771,6 +772,7 @@ public virtual async ValueTask DisposeAsync() { await CurrentTransaction.DisposeAsync(); } + ClearTransactions(clearAmbient: true); if (_connectionOwned diff --git a/src/EFCore.Relational/Storage/RelationalConnectionDependencies.cs b/src/EFCore.Relational/Storage/RelationalConnectionDependencies.cs index 376f8d48dc9..a323f78070f 100644 --- a/src/EFCore.Relational/Storage/RelationalConnectionDependencies.cs +++ b/src/EFCore.Relational/Storage/RelationalConnectionDependencies.cs @@ -27,8 +27,8 @@ namespace Microsoft.EntityFrameworkCore.Storage /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -104,7 +104,7 @@ public RelationalConnectionDependencies( public IRelationalTransactionFactory RelationalTransactionFactory { get; } /// - /// Contains the instance currently in use. + /// Contains the instance currently in use. /// public ICurrentDbContext CurrentContext { get; } diff --git a/src/EFCore.Relational/Storage/RelationalDataReader.cs b/src/EFCore.Relational/Storage/RelationalDataReader.cs index 45b2e418d68..279188955ca 100644 --- a/src/EFCore.Relational/Storage/RelationalDataReader.cs +++ b/src/EFCore.Relational/Storage/RelationalDataReader.cs @@ -8,7 +8,6 @@ using System.Threading.Tasks; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Diagnostics; -using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Storage diff --git a/src/EFCore.Relational/Storage/RelationalDatabase.cs b/src/EFCore.Relational/Storage/RelationalDatabase.cs index 525d3d01ff0..773d5490d54 100644 --- a/src/EFCore.Relational/Storage/RelationalDatabase.cs +++ b/src/EFCore.Relational/Storage/RelationalDatabase.cs @@ -20,8 +20,8 @@ namespace Microsoft.EntityFrameworkCore.Storage /// not used in application code. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Relational/Storage/RelationalDatabaseCreator.cs b/src/EFCore.Relational/Storage/RelationalDatabaseCreator.cs index 1dd5f05d61c..7a659d95300 100644 --- a/src/EFCore.Relational/Storage/RelationalDatabaseCreator.cs +++ b/src/EFCore.Relational/Storage/RelationalDatabaseCreator.cs @@ -7,7 +7,6 @@ using System.Threading.Tasks; using System.Transactions; using JetBrains.Annotations; -using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; @@ -23,8 +22,8 @@ namespace Microsoft.EntityFrameworkCore.Storage /// not used in application code. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -132,14 +131,16 @@ public virtual void CreateTables() /// A task that represents the asynchronous operation. /// public virtual Task CreateTablesAsync(CancellationToken cancellationToken = default) - => Dependencies.MigrationCommandExecutor.ExecuteNonQueryAsync(GetCreateTablesCommands(), Dependencies.Connection, cancellationToken); + => Dependencies.MigrationCommandExecutor.ExecuteNonQueryAsync( + GetCreateTablesCommands(), Dependencies.Connection, cancellationToken); /// /// Gets the commands that will create all tables from the model. /// /// The generated commands. protected virtual IReadOnlyList GetCreateTablesCommands() - => Dependencies.MigrationsSqlGenerator.Generate(Dependencies.ModelDiffer.GetDifferences(null, Dependencies.Model), Dependencies.Model); + => Dependencies.MigrationsSqlGenerator.Generate( + Dependencies.ModelDiffer.GetDifferences(null, Dependencies.Model), Dependencies.Model); /// /// Determines whether the database contains any tables. No attempt is made to determine if diff --git a/src/EFCore.Relational/Storage/RelationalDatabaseCreatorDependencies.cs b/src/EFCore.Relational/Storage/RelationalDatabaseCreatorDependencies.cs index c26a35a0e13..9b4f16f957d 100644 --- a/src/EFCore.Relational/Storage/RelationalDatabaseCreatorDependencies.cs +++ b/src/EFCore.Relational/Storage/RelationalDatabaseCreatorDependencies.cs @@ -28,8 +28,8 @@ namespace Microsoft.EntityFrameworkCore.Storage /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -135,7 +135,7 @@ public RelationalDatabaseCreatorDependencies( public IDiagnosticsLogger CommandLogger { get; } /// - /// Contains the currently in use. + /// Contains the currently in use. /// public ICurrentDbContext CurrentContext { get; } diff --git a/src/EFCore.Relational/Storage/RelationalDatabaseDependencies.cs b/src/EFCore.Relational/Storage/RelationalDatabaseDependencies.cs index 64caac15161..2252f5449bc 100644 --- a/src/EFCore.Relational/Storage/RelationalDatabaseDependencies.cs +++ b/src/EFCore.Relational/Storage/RelationalDatabaseDependencies.cs @@ -26,8 +26,8 @@ namespace Microsoft.EntityFrameworkCore.Storage /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Relational/Storage/RelationalExecutionStrategyExtensions.cs b/src/EFCore.Relational/Storage/RelationalExecutionStrategyExtensions.cs index 898ddf604c7..578ac717bd3 100644 --- a/src/EFCore.Relational/Storage/RelationalExecutionStrategyExtensions.cs +++ b/src/EFCore.Relational/Storage/RelationalExecutionStrategyExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Relational/Storage/RelationalExecutionStrategyFactory.cs b/src/EFCore.Relational/Storage/RelationalExecutionStrategyFactory.cs index baf02c2b602..14e06190503 100644 --- a/src/EFCore.Relational/Storage/RelationalExecutionStrategyFactory.cs +++ b/src/EFCore.Relational/Storage/RelationalExecutionStrategyFactory.cs @@ -16,8 +16,8 @@ namespace Microsoft.EntityFrameworkCore.Storage /// database providers. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Relational/Storage/RelationalSqlGenerationHelper.cs b/src/EFCore.Relational/Storage/RelationalSqlGenerationHelper.cs index 42be1ae1fdb..51fbcb11634 100644 --- a/src/EFCore.Relational/Storage/RelationalSqlGenerationHelper.cs +++ b/src/EFCore.Relational/Storage/RelationalSqlGenerationHelper.cs @@ -18,9 +18,9 @@ namespace Microsoft.EntityFrameworkCore.Storage /// not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class RelationalSqlGenerationHelper : ISqlGenerationHelper diff --git a/src/EFCore.Relational/Storage/RelationalSqlGenerationHelperDependencies.cs b/src/EFCore.Relational/Storage/RelationalSqlGenerationHelperDependencies.cs index 7c226e6640c..25d9daa65b7 100644 --- a/src/EFCore.Relational/Storage/RelationalSqlGenerationHelperDependencies.cs +++ b/src/EFCore.Relational/Storage/RelationalSqlGenerationHelperDependencies.cs @@ -23,10 +23,10 @@ namespace Microsoft.EntityFrameworkCore.Storage /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . - /// This means a single instance of each service is used by many instances. + /// The service lifetime is . + /// This means a single instance of each service is used by many instances. /// The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public sealed class RelationalSqlGenerationHelperDependencies diff --git a/src/EFCore.Relational/Storage/RelationalTransaction.cs b/src/EFCore.Relational/Storage/RelationalTransaction.cs index 79c2797207f..0b1aadaa8c3 100644 --- a/src/EFCore.Relational/Storage/RelationalTransaction.cs +++ b/src/EFCore.Relational/Storage/RelationalTransaction.cs @@ -9,7 +9,6 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Storage @@ -175,7 +174,7 @@ public virtual void Rollback() /// Commits all changes made to the database in the current transaction asynchronously. /// /// The cancellation token. - /// A representing the asynchronous operation. + /// A representing the asynchronous operation. public virtual async Task CommitAsync(CancellationToken cancellationToken = default) { var startTime = DateTimeOffset.UtcNow; @@ -225,7 +224,7 @@ await Logger.TransactionErrorAsync( /// Discards all changes made to the database in the current transaction asynchronously. /// /// The cancellation token. - /// A representing the asynchronous operation. + /// A representing the asynchronous operation. public virtual async Task RollbackAsync(CancellationToken cancellationToken = default) { var startTime = DateTimeOffset.UtcNow; diff --git a/src/EFCore.Relational/Storage/RelationalTransactionFactory.cs b/src/EFCore.Relational/Storage/RelationalTransactionFactory.cs index a8e51dee0c5..f626f3ee349 100644 --- a/src/EFCore.Relational/Storage/RelationalTransactionFactory.cs +++ b/src/EFCore.Relational/Storage/RelationalTransactionFactory.cs @@ -18,9 +18,9 @@ namespace Microsoft.EntityFrameworkCore.Storage /// This type is typically used by database providers It is generally not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class RelationalTransactionFactory : IRelationalTransactionFactory diff --git a/src/EFCore.Relational/Storage/RelationalTransactionFactoryDependencies.cs b/src/EFCore.Relational/Storage/RelationalTransactionFactoryDependencies.cs index f3d0dc2bb22..5beb3c6f8b8 100644 --- a/src/EFCore.Relational/Storage/RelationalTransactionFactoryDependencies.cs +++ b/src/EFCore.Relational/Storage/RelationalTransactionFactoryDependencies.cs @@ -23,10 +23,10 @@ namespace Microsoft.EntityFrameworkCore.Storage /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . - /// This means a single instance of each service is used by many instances. + /// The service lifetime is . + /// This means a single instance of each service is used by many instances. /// The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public sealed class RelationalTransactionFactoryDependencies diff --git a/src/EFCore.Relational/Storage/RelationalTypeMapping.cs b/src/EFCore.Relational/Storage/RelationalTypeMapping.cs index 224ed8e808d..192c48a364f 100644 --- a/src/EFCore.Relational/Storage/RelationalTypeMapping.cs +++ b/src/EFCore.Relational/Storage/RelationalTypeMapping.cs @@ -257,7 +257,7 @@ protected RelationalTypeMapping(RelationalTypeMappingParameters parameters) } /// - /// Processes the store type name to add appropriate postfix/prefix text as needed. + /// Processes the store type name to add appropriate postfix/prefix text as needed. /// /// The parameters for this mapping. /// The specified store type name. diff --git a/src/EFCore.Relational/Storage/RelationalTypeMappingInfo.cs b/src/EFCore.Relational/Storage/RelationalTypeMappingInfo.cs index f375810f710..dd611530b7d 100644 --- a/src/EFCore.Relational/Storage/RelationalTypeMappingInfo.cs +++ b/src/EFCore.Relational/Storage/RelationalTypeMappingInfo.cs @@ -35,11 +35,23 @@ public RelationalTypeMappingInfo([NotNull] IProperty property) /// The principal property chain for the property for which mapping is needed. /// The provider-specific relational type name for which mapping is needed. /// The provider-specific relational type name, with any facets removed. - /// Specifies a fallback Specifies Unicode or ANSI mapping for the mapping, in case one isn't found at the core level, or null for default. + /// + /// Specifies a fallback Specifies Unicode or ANSI mapping for the mapping, in case one isn't found at the core + /// level, or null for default. + /// /// Specifies a fixed length mapping, or null for default. - /// Specifies a fallback size for the mapping, in case one isn't found at the core level, or null for default. - /// Specifies a fallback precision for the mapping, in case one isn't found at the core level, or null for default. - /// Specifies a fallback scale for the mapping, in case one isn't found at the core level, or null for default. + /// + /// Specifies a fallback size for the mapping, in case one isn't found at the core level, or null for + /// default. + /// + /// + /// Specifies a fallback precision for the mapping, in case one isn't found at the core level, or null + /// for default. + /// + /// + /// Specifies a fallback scale for the mapping, in case one isn't found at the core level, or null for + /// default. + /// public RelationalTypeMappingInfo( [NotNull] IReadOnlyList principals, [CanBeNull] string storeTypeName = null, diff --git a/src/EFCore.Relational/Storage/RelationalTypeMappingSource.cs b/src/EFCore.Relational/Storage/RelationalTypeMappingSource.cs index e5aba369fb3..ab0e5243698 100644 --- a/src/EFCore.Relational/Storage/RelationalTypeMappingSource.cs +++ b/src/EFCore.Relational/Storage/RelationalTypeMappingSource.cs @@ -4,8 +4,8 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; -using System.Reflection; using System.ComponentModel.DataAnnotations.Schema; +using System.Reflection; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Metadata.Internal; @@ -26,9 +26,9 @@ namespace Microsoft.EntityFrameworkCore.Storage /// not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public abstract class RelationalTypeMappingSource : TypeMappingSourceBase, IRelationalTypeMappingSource @@ -88,7 +88,8 @@ protected virtual RelationalTypeMapping FindMapping(in RelationalTypeMappingInfo /// The mapping info to use to create the mapping. /// The type mapping, or null if none could be found. protected override CoreTypeMapping FindMapping(in TypeMappingInfo mappingInfo) - => throw new InvalidOperationException("FindMapping on a 'RelationalTypeMappingSource' with a non-relational 'TypeMappingInfo'."); + => throw new InvalidOperationException( + "FindMapping on a 'RelationalTypeMappingSource' with a non-relational 'TypeMappingInfo'."); private RelationalTypeMapping FindMappingWithConversion( in RelationalTypeMappingInfo mappingInfo, @@ -228,7 +229,8 @@ public override CoreTypeMapping FindMapping(IProperty property) var storeTypeNameBase = ParseStoreTypeName(storeTypeName, out var unicode, out var size, out var precision, out var scale); return FindMappingWithConversion( - new RelationalTypeMappingInfo(principals, storeTypeName, storeTypeNameBase, unicode, isFixedLength, size, precision, scale), principals); + new RelationalTypeMappingInfo(principals, storeTypeName, storeTypeNameBase, unicode, isFixedLength, size, precision, scale), + principals); } /// @@ -269,15 +271,14 @@ public override CoreTypeMapping FindMapping(MemberInfo member) if (member.GetCustomAttribute(true) is ColumnAttribute attribute) { var storeTypeName = attribute.TypeName; - var storeTypeNameBase = ParseStoreTypeName(attribute.TypeName, out var unicode, out var size, out var precision, out var scale); + var storeTypeNameBase = ParseStoreTypeName( + attribute.TypeName, out var unicode, out var size, out var precision, out var scale); return FindMappingWithConversion( new RelationalTypeMappingInfo(member, storeTypeName, storeTypeNameBase, unicode, size, precision, scale), null); } - else - { - return FindMappingWithConversion(new RelationalTypeMappingInfo(member), null); - } + + return FindMappingWithConversion(new RelationalTypeMappingInfo(member), null); } /// @@ -339,19 +340,23 @@ public virtual RelationalTypeMapping FindMapping( if (storeTypeName != null) { - storeTypeBaseName = ParseStoreTypeName(storeTypeName, out var parsedUnicode, out var parsedSize, out var parsedPrecision, out var parsedScale); + storeTypeBaseName = ParseStoreTypeName( + storeTypeName, out var parsedUnicode, out var parsedSize, out var parsedPrecision, out var parsedScale); if (size == null) { size = parsedSize; } + if (precision == null) { precision = parsedPrecision; } + if (scale == null) { scale = parsedScale; } + if (unicode == null) { unicode = parsedUnicode; @@ -413,7 +418,8 @@ protected virtual string ParseStoreTypeName( if (closeParen > openParen) { var comma = storeTypeName.IndexOf(",", openParen + 1, StringComparison.Ordinal); - if (comma > openParen && comma < closeParen) + if (comma > openParen + && comma < closeParen) { if (int.TryParse(storeTypeName.Substring(openParen + 1, comma - openParen - 1), out var parsedPrecision)) { @@ -425,7 +431,8 @@ protected virtual string ParseStoreTypeName( scale = parsedScale; } } - else if (int.TryParse(storeTypeName.Substring(openParen + 1, closeParen - openParen - 1).Trim(), out var parsedSize)) + else if (int.TryParse( + storeTypeName.Substring(openParen + 1, closeParen - openParen - 1).Trim(), out var parsedSize)) { size = parsedSize; precision = parsedSize; diff --git a/src/EFCore.Relational/Storage/RelationalTypeMappingSourceDependencies.cs b/src/EFCore.Relational/Storage/RelationalTypeMappingSourceDependencies.cs index 792dbcde89c..580d6e82f04 100644 --- a/src/EFCore.Relational/Storage/RelationalTypeMappingSourceDependencies.cs +++ b/src/EFCore.Relational/Storage/RelationalTypeMappingSourceDependencies.cs @@ -26,10 +26,10 @@ namespace Microsoft.EntityFrameworkCore.Storage /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . - /// This means a single instance of each service is used by many instances. + /// The service lifetime is . + /// This means a single instance of each service is used by many instances. /// The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public sealed class RelationalTypeMappingSourceDependencies diff --git a/src/EFCore.Relational/Storage/RelationalValueBufferFactoryDependencies.cs b/src/EFCore.Relational/Storage/RelationalValueBufferFactoryDependencies.cs index b81391aeb7f..202da381ab2 100644 --- a/src/EFCore.Relational/Storage/RelationalValueBufferFactoryDependencies.cs +++ b/src/EFCore.Relational/Storage/RelationalValueBufferFactoryDependencies.cs @@ -26,10 +26,10 @@ namespace Microsoft.EntityFrameworkCore.Storage /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . - /// This means a single instance of each service is used by many instances. + /// The service lifetime is . + /// This means a single instance of each service is used by many instances. /// The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public sealed class RelationalValueBufferFactoryDependencies diff --git a/src/EFCore.Relational/Storage/TypedRelationalValueBufferFactoryFactory.cs b/src/EFCore.Relational/Storage/TypedRelationalValueBufferFactoryFactory.cs index 4db455032cc..2c5649ba133 100644 --- a/src/EFCore.Relational/Storage/TypedRelationalValueBufferFactoryFactory.cs +++ b/src/EFCore.Relational/Storage/TypedRelationalValueBufferFactoryFactory.cs @@ -34,9 +34,9 @@ namespace Microsoft.EntityFrameworkCore.Storage /// not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class TypedRelationalValueBufferFactoryFactory : IRelationalValueBufferFactoryFactory @@ -93,6 +93,7 @@ public override int GetHashCode() { hash.Add(TypeMaterializationInfo[i]); } + return hash.ToHashCode(); } } @@ -122,7 +123,7 @@ public virtual IRelationalValueBufferFactory Create(IReadOnlyList Types and mapping for the values to be read. /// The value buffer assignment expressions. public virtual IReadOnlyList CreateAssignmentExpressions([NotNull] IReadOnlyList types) - => Check.NotNull(types, nameof(types)) + => Check.NotNull(types, nameof(types)) .Select( (mi, i) => CreateGetValueExpression( diff --git a/src/EFCore.Relational/Update/ColumnModification.cs b/src/EFCore.Relational/Update/ColumnModification.cs index 0c560c28fab..4d109b4d5eb 100644 --- a/src/EFCore.Relational/Update/ColumnModification.cs +++ b/src/EFCore.Relational/Update/ColumnModification.cs @@ -198,9 +198,9 @@ public virtual object Value else { Entry.SetStoreGeneratedValue(Property, value); - if(_sharedColumnModifications != null) + if (_sharedColumnModifications != null) { - foreach(var sharedModification in _sharedColumnModifications) + foreach (var sharedModification in _sharedColumnModifications) { sharedModification.Value = value; } @@ -243,8 +243,9 @@ public virtual void AddSharedColumnModification([NotNull] ColumnModification mod new[] { modification.Property }.Format(), new[] { Property }.FormatColumns())); } - else if (UseOriginalValueParameter - && !StructuralComparisons.StructuralEqualityComparer.Equals(OriginalValue, modification.OriginalValue)) + + if (UseOriginalValueParameter + && !StructuralComparisons.StructuralEqualityComparer.Equals(OriginalValue, modification.OriginalValue)) { if (_sensitiveLoggingEnabled) { diff --git a/src/EFCore.Relational/Update/IBatchExecutor.cs b/src/EFCore.Relational/Update/IBatchExecutor.cs index 2cd52af8684..d172ca03495 100644 --- a/src/EFCore.Relational/Update/IBatchExecutor.cs +++ b/src/EFCore.Relational/Update/IBatchExecutor.cs @@ -18,8 +18,8 @@ namespace Microsoft.EntityFrameworkCore.Update /// This type is typically used by database providers; it is generally not used in application code. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Relational/Update/ICommandBatchPreparer.cs b/src/EFCore.Relational/Update/ICommandBatchPreparer.cs index 3202c13dfc7..3ba112dedfb 100644 --- a/src/EFCore.Relational/Update/ICommandBatchPreparer.cs +++ b/src/EFCore.Relational/Update/ICommandBatchPreparer.cs @@ -16,8 +16,8 @@ namespace Microsoft.EntityFrameworkCore.Update /// This type is typically used by database providers; it is generally not used in application code. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Relational/Update/IModificationCommandBatchFactory.cs b/src/EFCore.Relational/Update/IModificationCommandBatchFactory.cs index 421f481d10a..e20e5c5ad28 100644 --- a/src/EFCore.Relational/Update/IModificationCommandBatchFactory.cs +++ b/src/EFCore.Relational/Update/IModificationCommandBatchFactory.cs @@ -13,8 +13,8 @@ namespace Microsoft.EntityFrameworkCore.Update /// This type is typically used by database providers; it is generally not used in application code. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Relational/Update/IUpdateSqlGenerator.cs b/src/EFCore.Relational/Update/IUpdateSqlGenerator.cs index 4ca2b6151be..75175a65702 100644 --- a/src/EFCore.Relational/Update/IUpdateSqlGenerator.cs +++ b/src/EFCore.Relational/Update/IUpdateSqlGenerator.cs @@ -16,9 +16,9 @@ namespace Microsoft.EntityFrameworkCore.Update /// This type is typically used by database providers; it is generally not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IUpdateSqlGenerator @@ -38,7 +38,8 @@ public interface IUpdateSqlGenerator /// The builder to which the SQL fragment should be appended. /// The name of the sequence. /// The schema that contains the sequence, or null to use the default schema. - void AppendNextSequenceValueOperation([NotNull] StringBuilder commandStringBuilder, [NotNull] string name, [CanBeNull] string schema); + void AppendNextSequenceValueOperation( + [NotNull] StringBuilder commandStringBuilder, [NotNull] string name, [CanBeNull] string schema); /// /// Appends a SQL fragment for the start of a batch to diff --git a/src/EFCore.Relational/Update/Internal/BatchExecutor.cs b/src/EFCore.Relational/Update/Internal/BatchExecutor.cs index 4245a2446e3..18c8a293574 100644 --- a/src/EFCore.Relational/Update/Internal/BatchExecutor.cs +++ b/src/EFCore.Relational/Update/Internal/BatchExecutor.cs @@ -20,8 +20,8 @@ namespace Microsoft.EntityFrameworkCore.Update.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Relational/Update/Internal/CommandBatchPreparer.cs b/src/EFCore.Relational/Update/Internal/CommandBatchPreparer.cs index 4f9b9c63365..1c0d120af3e 100644 --- a/src/EFCore.Relational/Update/Internal/CommandBatchPreparer.cs +++ b/src/EFCore.Relational/Update/Internal/CommandBatchPreparer.cs @@ -25,8 +25,8 @@ namespace Microsoft.EntityFrameworkCore.Update.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -40,7 +40,8 @@ public class CommandBatchPreparer : ICommandBatchPreparer private readonly int _minBatchSize; private readonly bool _sensitiveLoggingEnabled; - private IReadOnlyDictionary<(string Schema, string Name), SharedTableEntryMapFactory> _sharedTableEntryMapFactories; + private IReadOnlyDictionary<(string Schema, string Name), SharedTableEntryMapFactory> + _sharedTableEntryMapFactories; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -140,7 +141,8 @@ public virtual IEnumerable BatchCommands( } } - private ModificationCommandBatch StartNewBatch(ParameterNameGenerator parameterNameGenerator, ModificationCommand modificationCommand) + private ModificationCommandBatch StartNewBatch( + ParameterNameGenerator parameterNameGenerator, ModificationCommand modificationCommand) { parameterNameGenerator.Reset(); var batch = _modificationCommandBatchFactory.Create(); @@ -579,7 +581,8 @@ private Dictionary> CreateKeyValuePred if (command.EntityState == EntityState.Deleted || foreignKeyValueColumnModifications.Any()) { - var dependentKeyValue = keyValueIndexFactory.CreateDependentKeyValueFromOriginalValues((InternalEntityEntry)entry, foreignKey); + var dependentKeyValue = + keyValueIndexFactory.CreateDependentKeyValueFromOriginalValues((InternalEntityEntry)entry, foreignKey); if (dependentKeyValue != null) { @@ -718,7 +721,7 @@ private void AddUniqueValueEdges(Multigraph c if (valueFactory.TryCreateFromOriginalValues( (InternalEntityEntry)entry, out var indexValue)) { - predecessorsMap ??= new Dictionary>(); + predecessorsMap ??= new Dictionary>(); if (!predecessorsMap.TryGetValue(index, out var predecessorCommands)) { predecessorCommands = diff --git a/src/EFCore.Relational/Update/Internal/CommandBatchPreparerDependencies.cs b/src/EFCore.Relational/Update/Internal/CommandBatchPreparerDependencies.cs index e089b236c04..e2ffb2b65e8 100644 --- a/src/EFCore.Relational/Update/Internal/CommandBatchPreparerDependencies.cs +++ b/src/EFCore.Relational/Update/Internal/CommandBatchPreparerDependencies.cs @@ -27,8 +27,8 @@ namespace Microsoft.EntityFrameworkCore.Update.Internal /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Relational/Update/Internal/IKeyValueIndexFactorySource.cs b/src/EFCore.Relational/Update/Internal/IKeyValueIndexFactorySource.cs index 609e393e963..01920eb88b6 100644 --- a/src/EFCore.Relational/Update/Internal/IKeyValueIndexFactorySource.cs +++ b/src/EFCore.Relational/Update/Internal/IKeyValueIndexFactorySource.cs @@ -15,9 +15,9 @@ namespace Microsoft.EntityFrameworkCore.Update.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IKeyValueIndexFactorySource diff --git a/src/EFCore.Relational/Update/Internal/KeyValueIndexFactorySource.cs b/src/EFCore.Relational/Update/Internal/KeyValueIndexFactorySource.cs index 6f35925fb41..26da794a587 100644 --- a/src/EFCore.Relational/Update/Internal/KeyValueIndexFactorySource.cs +++ b/src/EFCore.Relational/Update/Internal/KeyValueIndexFactorySource.cs @@ -19,9 +19,9 @@ namespace Microsoft.EntityFrameworkCore.Update.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class KeyValueIndexFactorySource : IdentityMapFactoryFactoryBase, IKeyValueIndexFactorySource diff --git a/src/EFCore.Relational/Update/Internal/ModificationCommandComparer.cs b/src/EFCore.Relational/Update/Internal/ModificationCommandComparer.cs index e5ea0e6a6df..9a9cb1b0199 100644 --- a/src/EFCore.Relational/Update/Internal/ModificationCommandComparer.cs +++ b/src/EFCore.Relational/Update/Internal/ModificationCommandComparer.cs @@ -20,9 +20,9 @@ namespace Microsoft.EntityFrameworkCore.Update.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class ModificationCommandComparer : IComparer diff --git a/src/EFCore.Relational/Update/Internal/SharedTableEntryMap.cs b/src/EFCore.Relational/Update/Internal/SharedTableEntryMap.cs index 542e989cbd9..2f9bd110724 100644 --- a/src/EFCore.Relational/Update/Internal/SharedTableEntryMap.cs +++ b/src/EFCore.Relational/Update/Internal/SharedTableEntryMap.cs @@ -84,7 +84,8 @@ public SharedTableEntryMap( continue; } - var factory = CreateSharedTableEntryMapFactory(tableMapping.Value, updateAdapter, tableMapping.Key.TableName, tableMapping.Key.Schema); + var factory = CreateSharedTableEntryMapFactory( + tableMapping.Value, updateAdapter, tableMapping.Key.TableName, tableMapping.Key.Schema); sharedTablesMap.Add(tableMapping.Key, factory); } diff --git a/src/EFCore.Relational/Update/ModificationCommand.cs b/src/EFCore.Relational/Update/ModificationCommand.cs index 0ee605e9569..a56e3a90a1b 100644 --- a/src/EFCore.Relational/Update/ModificationCommand.cs +++ b/src/EFCore.Relational/Update/ModificationCommand.cs @@ -130,7 +130,8 @@ public virtual EntityState EntityState /// The list of s needed to perform the insert, update, or delete. /// public virtual IReadOnlyList ColumnModifications - => NonCapturingLazyInitializer.EnsureInitialized(ref _columnModifications, this, command => command.GenerateColumnModifications()); + => NonCapturingLazyInitializer.EnsureInitialized( + ref _columnModifications, this, command => command.GenerateColumnModifications()); /// /// Indicates whether or not the database will return values for some mapped properties @@ -343,11 +344,13 @@ public void RecordValue(IProperty property, IUpdateEntry entry) switch (entry.EntityState) { case EntityState.Modified: - if (!_write && entry.IsModified(property)) + if (!_write + && entry.IsModified(property)) { _write = true; _currentValue = entry.GetCurrentValue(property); } + break; case EntityState.Added: if (!_write) @@ -355,6 +358,7 @@ public void RecordValue(IProperty property, IUpdateEntry entry) _currentValue = entry.GetCurrentValue(property); _write = !Equals(_originalValue, _currentValue); } + break; case EntityState.Deleted: _originalValue = entry.GetOriginalValue(property); @@ -366,8 +370,8 @@ public bool TryPropagate(IProperty property, InternalEntityEntry entry) { if (_write && (entry.EntityState == EntityState.Unchanged - || (entry.EntityState == EntityState.Modified && !entry.IsModified(property)) - || (entry.EntityState == EntityState.Added && Equals(_originalValue, entry.GetCurrentValue(property))))) + || (entry.EntityState == EntityState.Modified && !entry.IsModified(property)) + || (entry.EntityState == EntityState.Added && Equals(_originalValue, entry.GetCurrentValue(property))))) { entry[property] = _currentValue; diff --git a/src/EFCore.Relational/Update/ModificationCommandBatchFactoryDependencies.cs b/src/EFCore.Relational/Update/ModificationCommandBatchFactoryDependencies.cs index cdae4d57f57..7dc1dec4c59 100644 --- a/src/EFCore.Relational/Update/ModificationCommandBatchFactoryDependencies.cs +++ b/src/EFCore.Relational/Update/ModificationCommandBatchFactoryDependencies.cs @@ -27,8 +27,8 @@ namespace Microsoft.EntityFrameworkCore.Update /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -103,7 +103,7 @@ public ModificationCommandBatchFactoryDependencies( public IRelationalValueBufferFactoryFactory ValueBufferFactoryFactory { get; } /// - /// Contains the currently in use. + /// Contains the currently in use. /// public ICurrentDbContext CurrentContext { get; } diff --git a/src/EFCore.Relational/Update/ReaderModificationCommandBatch.cs b/src/EFCore.Relational/Update/ReaderModificationCommandBatch.cs index ef8aabd7009..75d8f1d01d8 100644 --- a/src/EFCore.Relational/Update/ReaderModificationCommandBatch.cs +++ b/src/EFCore.Relational/Update/ReaderModificationCommandBatch.cs @@ -318,7 +318,8 @@ protected abstract Task ConsumeAsync( /// being modified such that a ValueBuffer with appropriate slots can be created. /// /// The factory. - protected virtual IRelationalValueBufferFactory CreateValueBufferFactory([NotNull] IReadOnlyList columnModifications) + protected virtual IRelationalValueBufferFactory CreateValueBufferFactory( + [NotNull] IReadOnlyList columnModifications) => Dependencies.ValueBufferFactoryFactory .Create( Check.NotNull(columnModifications, nameof(columnModifications)) diff --git a/src/EFCore.Relational/Update/UpdateSqlGenerator.cs b/src/EFCore.Relational/Update/UpdateSqlGenerator.cs index 124c1af8265..d809e6259a3 100644 --- a/src/EFCore.Relational/Update/UpdateSqlGenerator.cs +++ b/src/EFCore.Relational/Update/UpdateSqlGenerator.cs @@ -21,9 +21,9 @@ namespace Microsoft.EntityFrameworkCore.Update /// This type is typically used by database providers; it is generally not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public abstract class UpdateSqlGenerator : IUpdateSqlGenerator @@ -88,7 +88,8 @@ public virtual ResultSetMapping AppendInsertOperation( /// The command that represents the delete operation. /// The ordinal of this command in the batch. /// The for the command. - public virtual ResultSetMapping AppendUpdateOperation(StringBuilder commandStringBuilder, ModificationCommand command, int commandPosition) + public virtual ResultSetMapping AppendUpdateOperation( + StringBuilder commandStringBuilder, ModificationCommand command, int commandPosition) { Check.NotNull(commandStringBuilder, nameof(commandStringBuilder)); Check.NotNull(command, nameof(command)); @@ -120,7 +121,8 @@ public virtual ResultSetMapping AppendUpdateOperation(StringBuilder commandStrin /// The command that represents the delete operation. /// The ordinal of this command in the batch. /// The for the command. - public virtual ResultSetMapping AppendDeleteOperation(StringBuilder commandStringBuilder, ModificationCommand command, int commandPosition) + public virtual ResultSetMapping AppendDeleteOperation( + StringBuilder commandStringBuilder, ModificationCommand command, int commandPosition) { Check.NotNull(commandStringBuilder, nameof(commandStringBuilder)); Check.NotNull(command, nameof(command)); diff --git a/src/EFCore.Relational/Update/UpdateSqlGeneratorDependencies.cs b/src/EFCore.Relational/Update/UpdateSqlGeneratorDependencies.cs index 112aa2b3e60..25d73494374 100644 --- a/src/EFCore.Relational/Update/UpdateSqlGeneratorDependencies.cs +++ b/src/EFCore.Relational/Update/UpdateSqlGeneratorDependencies.cs @@ -26,10 +26,10 @@ namespace Microsoft.EntityFrameworkCore.Update /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . - /// This means a single instance of each service is used by many instances. + /// The service lifetime is . + /// This means a single instance of each service is used by many instances. /// The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public sealed class UpdateSqlGeneratorDependencies diff --git a/src/EFCore.Relational/ValueGeneration/RelationalValueGeneratorSelector.cs b/src/EFCore.Relational/ValueGeneration/RelationalValueGeneratorSelector.cs index 4581bf4e68b..817a40b806c 100644 --- a/src/EFCore.Relational/ValueGeneration/RelationalValueGeneratorSelector.cs +++ b/src/EFCore.Relational/ValueGeneration/RelationalValueGeneratorSelector.cs @@ -19,8 +19,8 @@ namespace Microsoft.EntityFrameworkCore.ValueGeneration /// not used in application code. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.SqlServer.NTS/Design/Internal/SqlServerNetTopologySuiteDesignTimeServices.cs b/src/EFCore.SqlServer.NTS/Design/Internal/SqlServerNetTopologySuiteDesignTimeServices.cs index 341a8ff69fa..e1ad4b40e98 100644 --- a/src/EFCore.SqlServer.NTS/Design/Internal/SqlServerNetTopologySuiteDesignTimeServices.cs +++ b/src/EFCore.SqlServer.NTS/Design/Internal/SqlServerNetTopologySuiteDesignTimeServices.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.Design; diff --git a/src/EFCore.SqlServer.NTS/Extensions/SqlServerNetTopologySuiteDbContextOptionsBuilderExtensions.cs b/src/EFCore.SqlServer.NTS/Extensions/SqlServerNetTopologySuiteDbContextOptionsBuilderExtensions.cs index 516b453bebe..88ade35034a 100644 --- a/src/EFCore.SqlServer.NTS/Extensions/SqlServerNetTopologySuiteDbContextOptionsBuilderExtensions.cs +++ b/src/EFCore.SqlServer.NTS/Extensions/SqlServerNetTopologySuiteDbContextOptionsBuilderExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.SqlServer.NTS/Extensions/SqlServerNetTopologySuiteServiceCollectionExtensions.cs b/src/EFCore.SqlServer.NTS/Extensions/SqlServerNetTopologySuiteServiceCollectionExtensions.cs index 12926a0d847..b5ad3c544cf 100644 --- a/src/EFCore.SqlServer.NTS/Extensions/SqlServerNetTopologySuiteServiceCollectionExtensions.cs +++ b/src/EFCore.SqlServer.NTS/Extensions/SqlServerNetTopologySuiteServiceCollectionExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.SqlServer.NTS/Infrastructure/Internal/SqlServerNetTopologySuiteOptionsExtension.cs b/src/EFCore.SqlServer.NTS/Infrastructure/Internal/SqlServerNetTopologySuiteOptionsExtension.cs index ccde0d3b4a5..335ac039bf7 100644 --- a/src/EFCore.SqlServer.NTS/Infrastructure/Internal/SqlServerNetTopologySuiteOptionsExtension.cs +++ b/src/EFCore.SqlServer.NTS/Infrastructure/Internal/SqlServerNetTopologySuiteOptionsExtension.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMemberTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMemberTranslator.cs index ccaafa5f030..05454cbc997 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMemberTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMemberTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMethodTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMethodTranslator.cs index a7fb18f7735..3ad63a18097 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMethodTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMethodTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; @@ -31,7 +31,8 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method return _sqlExpressionFactory.Function( instance, "STGeometryN", - new[] { + new[] + { _sqlExpressionFactory.Add( arguments[0], _sqlExpressionFactory.Constant(1)) diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMemberTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMemberTranslator.cs index af132b5e9fe..3ae8a7a77bd 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMemberTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMemberTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -42,7 +42,8 @@ public class SqlServerGeometryMemberTranslator : IMemberTranslator private readonly IRelationalTypeMappingSource _typeMappingSource; private readonly ISqlExpressionFactory _sqlExpressionFactory; - public SqlServerGeometryMemberTranslator(IRelationalTypeMappingSource typeMappingSource, + public SqlServerGeometryMemberTranslator( + IRelationalTypeMappingSource typeMappingSource, ISqlExpressionFactory sqlExpressionFactory) { _typeMappingSource = typeMappingSource; @@ -76,21 +77,39 @@ public virtual SqlExpression Translate(SqlExpression instance, MemberInfo member { var whenClauses = new List { - new CaseWhenClause(_sqlExpressionFactory.Constant("Point"), _sqlExpressionFactory.Constant(OgcGeometryType.Point)), - new CaseWhenClause(_sqlExpressionFactory.Constant("LineString"), _sqlExpressionFactory.Constant(OgcGeometryType.LineString)), - new CaseWhenClause(_sqlExpressionFactory.Constant("Polygon"), _sqlExpressionFactory.Constant(OgcGeometryType.Polygon)), - new CaseWhenClause(_sqlExpressionFactory.Constant("MultiPoint"), _sqlExpressionFactory.Constant(OgcGeometryType.MultiPoint)), - new CaseWhenClause(_sqlExpressionFactory.Constant("MultiLineString"), _sqlExpressionFactory.Constant(OgcGeometryType.MultiLineString)), - new CaseWhenClause(_sqlExpressionFactory.Constant("MultiPolygon"), _sqlExpressionFactory.Constant(OgcGeometryType.MultiPolygon)), - new CaseWhenClause(_sqlExpressionFactory.Constant("GeometryCollection"), _sqlExpressionFactory.Constant(OgcGeometryType.GeometryCollection)), - new CaseWhenClause(_sqlExpressionFactory.Constant("CircularString"), _sqlExpressionFactory.Constant(OgcGeometryType.CircularString)), - new CaseWhenClause(_sqlExpressionFactory.Constant("CompoundCurve"), _sqlExpressionFactory.Constant(OgcGeometryType.CompoundCurve)), - new CaseWhenClause(_sqlExpressionFactory.Constant("CurvePolygon"), _sqlExpressionFactory.Constant(OgcGeometryType.CurvePolygon)) + new CaseWhenClause( + _sqlExpressionFactory.Constant("Point"), _sqlExpressionFactory.Constant(OgcGeometryType.Point)), + new CaseWhenClause( + _sqlExpressionFactory.Constant("LineString"), _sqlExpressionFactory.Constant(OgcGeometryType.LineString)), + new CaseWhenClause( + _sqlExpressionFactory.Constant("Polygon"), _sqlExpressionFactory.Constant(OgcGeometryType.Polygon)), + new CaseWhenClause( + _sqlExpressionFactory.Constant("MultiPoint"), _sqlExpressionFactory.Constant(OgcGeometryType.MultiPoint)), + new CaseWhenClause( + _sqlExpressionFactory.Constant("MultiLineString"), + _sqlExpressionFactory.Constant(OgcGeometryType.MultiLineString)), + new CaseWhenClause( + _sqlExpressionFactory.Constant("MultiPolygon"), + _sqlExpressionFactory.Constant(OgcGeometryType.MultiPolygon)), + new CaseWhenClause( + _sqlExpressionFactory.Constant("GeometryCollection"), + _sqlExpressionFactory.Constant(OgcGeometryType.GeometryCollection)), + new CaseWhenClause( + _sqlExpressionFactory.Constant("CircularString"), + _sqlExpressionFactory.Constant(OgcGeometryType.CircularString)), + new CaseWhenClause( + _sqlExpressionFactory.Constant("CompoundCurve"), + _sqlExpressionFactory.Constant(OgcGeometryType.CompoundCurve)), + new CaseWhenClause( + _sqlExpressionFactory.Constant("CurvePolygon"), + _sqlExpressionFactory.Constant(OgcGeometryType.CurvePolygon)) }; if (isGeography) { - whenClauses.Add(new CaseWhenClause(_sqlExpressionFactory.Constant("FullGlobe"), _sqlExpressionFactory.Constant((OgcGeometryType)126))); + whenClauses.Add( + new CaseWhenClause( + _sqlExpressionFactory.Constant("FullGlobe"), _sqlExpressionFactory.Constant((OgcGeometryType)126))); } return _sqlExpressionFactory.Case( diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMethodTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMethodTranslator.cs index 133ccad2a36..e8f61922d03 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMethodTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMethodTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -43,8 +43,11 @@ public class SqlServerGeometryMethodTranslator : IMethodCallTranslator { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Touches), new[] { typeof(Geometry) }), "STTouches" } }; - private static readonly MethodInfo _getGeometryN = typeof(Geometry).GetRuntimeMethod(nameof(Geometry.GetGeometryN), new[] { typeof(int) }); - private static readonly MethodInfo _isWithinDistance = typeof(Geometry).GetRuntimeMethod(nameof(Geometry.IsWithinDistance), new[] { typeof(Geometry), typeof(double) }); + private static readonly MethodInfo _getGeometryN = typeof(Geometry).GetRuntimeMethod( + nameof(Geometry.GetGeometryN), new[] { typeof(int) }); + + private static readonly MethodInfo _isWithinDistance = typeof(Geometry).GetRuntimeMethod( + nameof(Geometry.IsWithinDistance), new[] { typeof(Geometry), typeof(double) }); private readonly IRelationalTypeMappingSource _typeMappingSource; private readonly ISqlExpressionFactory _sqlExpressionFactory; @@ -103,7 +106,8 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method return _sqlExpressionFactory.Function( instance, "STGeometryN", - new[] { + new[] + { _sqlExpressionFactory.Add( arguments[0], _sqlExpressionFactory.Constant(1)) diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMemberTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMemberTranslator.cs index b6147b18c64..93bd4f35ac5 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMemberTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMemberTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -27,7 +27,8 @@ public class SqlServerLineStringMemberTranslator : IMemberTranslator private readonly IRelationalTypeMappingSource _typeMappingSource; private readonly ISqlExpressionFactory _sqlExpressionFactory; - public SqlServerLineStringMemberTranslator(IRelationalTypeMappingSource typeMappingSource, + public SqlServerLineStringMemberTranslator( + IRelationalTypeMappingSource typeMappingSource, ISqlExpressionFactory sqlExpressionFactory) { _typeMappingSource = typeMappingSource; @@ -48,8 +49,8 @@ public virtual SqlExpression Translate(SqlExpression instance, MemberInfo member } var resultTypeMapping = typeof(Geometry).IsAssignableFrom(returnType) - ? _typeMappingSource.FindMapping(returnType, storeType) - : _typeMappingSource.FindMapping(returnType); + ? _typeMappingSource.FindMapping(returnType, storeType) + : _typeMappingSource.FindMapping(returnType); return _sqlExpressionFactory.Function( instance, diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMethodTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMethodTranslator.cs index 882cb94e429..24a2a89fb4d 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMethodTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMethodTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; @@ -12,7 +12,8 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal { public class SqlServerLineStringMethodTranslator : IMethodCallTranslator { - private static readonly MethodInfo _getPointN = typeof(LineString).GetRuntimeMethod(nameof(LineString.GetPointN), new[] { typeof(int) }); + private static readonly MethodInfo _getPointN = typeof(LineString).GetRuntimeMethod( + nameof(LineString.GetPointN), new[] { typeof(int) }); private readonly IRelationalTypeMappingSource _typeMappingSource; private readonly ISqlExpressionFactory _sqlExpressionFactory; @@ -32,7 +33,8 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method return _sqlExpressionFactory.Function( instance, "STPointN", - new[] { + new[] + { _sqlExpressionFactory.Add( arguments[0], _sqlExpressionFactory.Constant(1)) diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerMultiLineStringMemberTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerMultiLineStringMemberTranslator.cs index e0c9d706573..d690083b98f 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerMultiLineStringMemberTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerMultiLineStringMemberTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerNetTopologySuiteMemberTranslatorPlugin.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerNetTopologySuiteMemberTranslatorPlugin.cs index c15313184fa..def42d6ee06 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerNetTopologySuiteMemberTranslatorPlugin.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerNetTopologySuiteMemberTranslatorPlugin.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; @@ -16,9 +16,9 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class SqlServerNetTopologySuiteMemberTranslatorPlugin : IMemberTranslatorPlugin @@ -32,7 +32,8 @@ public class SqlServerNetTopologySuiteMemberTranslatorPlugin : IMemberTranslator public SqlServerNetTopologySuiteMemberTranslatorPlugin( IRelationalTypeMappingSource typeMappingSource, ISqlExpressionFactory sqlExpressionFactory) { - Translators = new IMemberTranslator[] { + Translators = new IMemberTranslator[] + { new SqlServerGeometryMemberTranslator(typeMappingSource, sqlExpressionFactory), new SqlServerGeometryCollectionMemberTranslator(sqlExpressionFactory), new SqlServerLineStringMemberTranslator(typeMappingSource, sqlExpressionFactory), diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerNetTopologySuiteMethodCallTranslatorPlugin.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerNetTopologySuiteMethodCallTranslatorPlugin.cs index 79885627dfc..7c2dcb3d682 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerNetTopologySuiteMethodCallTranslatorPlugin.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerNetTopologySuiteMethodCallTranslatorPlugin.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; @@ -16,10 +16,10 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is and multiple registrations - /// are allowed. This means a single instance of each service is used by many + /// The service lifetime is and multiple registrations + /// are allowed. This means a single instance of each service is used by many /// instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public class SqlServerNetTopologySuiteMethodCallTranslatorPlugin : IMethodCallTranslatorPlugin @@ -30,7 +30,8 @@ public class SqlServerNetTopologySuiteMethodCallTranslatorPlugin : IMethodCallTr /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public SqlServerNetTopologySuiteMethodCallTranslatorPlugin(IRelationalTypeMappingSource typeMappingSource, + public SqlServerNetTopologySuiteMethodCallTranslatorPlugin( + IRelationalTypeMappingSource typeMappingSource, ISqlExpressionFactory sqlExpressionFactory) { Translators = new IMethodCallTranslator[] diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPointMemberTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPointMemberTranslator.cs index 5f3b06dfda6..26b97d364d8 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPointMemberTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPointMemberTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -15,20 +15,17 @@ internal class SqlServerPointMemberTranslator : IMemberTranslator { private static readonly IDictionary _memberToPropertyName = new Dictionary { - { typeof(Point).GetRuntimeProperty(nameof(Point.M)), "M" }, - { typeof(Point).GetRuntimeProperty(nameof(Point.Z)), "Z" } + { typeof(Point).GetRuntimeProperty(nameof(Point.M)), "M" }, { typeof(Point).GetRuntimeProperty(nameof(Point.Z)), "Z" } }; private static readonly IDictionary _geographyMemberToPropertyName = new Dictionary { - { typeof(Point).GetRuntimeProperty(nameof(Point.X)), "Long" }, - { typeof(Point).GetRuntimeProperty(nameof(Point.Y)), "Lat" } + { typeof(Point).GetRuntimeProperty(nameof(Point.X)), "Long" }, { typeof(Point).GetRuntimeProperty(nameof(Point.Y)), "Lat" } }; private static readonly IDictionary _geometryMemberToPropertyName = new Dictionary { - { typeof(Point).GetRuntimeProperty(nameof(Point.X)), "STX" }, - { typeof(Point).GetRuntimeProperty(nameof(Point.Y)), "STY" } + { typeof(Point).GetRuntimeProperty(nameof(Point.X)), "STX" }, { typeof(Point).GetRuntimeProperty(nameof(Point.Y)), "STY" } }; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMemberTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMemberTranslator.cs index 598581c3864..bb322147920 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMemberTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMemberTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -19,14 +19,14 @@ public class SqlServerPolygonMemberTranslator : IMemberTranslator private static readonly IDictionary _geometryMemberToFunctionName = new Dictionary { - { _exteriorRing, "STExteriorRing" }, - { _numInteriorRings, "STNumInteriorRing" } + { _exteriorRing, "STExteriorRing" }, { _numInteriorRings, "STNumInteriorRing" } }; private readonly IRelationalTypeMappingSource _typeMappingSource; private readonly ISqlExpressionFactory _sqlExpressionFactory; - public SqlServerPolygonMemberTranslator(IRelationalTypeMappingSource typeMappingSource, + public SqlServerPolygonMemberTranslator( + IRelationalTypeMappingSource typeMappingSource, ISqlExpressionFactory sqlExpressionFactory) { _typeMappingSource = typeMappingSource; diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMethodTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMethodTranslator.cs index 3d556a14895..0004f871e2e 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMethodTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMethodTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -13,7 +13,8 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal { public class SqlServerPolygonMethodTranslator : IMethodCallTranslator { - private static readonly MethodInfo _getInteriorRingN = typeof(Polygon).GetRuntimeMethod(nameof(Polygon.GetInteriorRingN), new[] { typeof(int) }); + private static readonly MethodInfo _getInteriorRingN = typeof(Polygon).GetRuntimeMethod( + nameof(Polygon.GetInteriorRingN), new[] { typeof(int) }); private readonly IRelationalTypeMappingSource _typeMappingSource; private readonly ISqlExpressionFactory _sqlExpressionFactory; @@ -38,7 +39,8 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method return _sqlExpressionFactory.Function( instance, "RingN", - new[] { + new[] + { _sqlExpressionFactory.Add( arguments[0], _sqlExpressionFactory.Constant(2)) @@ -46,19 +48,18 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method method.ReturnType, _typeMappingSource.FindMapping(method.ReturnType, storeType)); } - else - { - return _sqlExpressionFactory.Function( - instance, - "STInteriorRingN", - new[] { - _sqlExpressionFactory.Add( - arguments[0], - _sqlExpressionFactory.Constant(1)) - }, - method.ReturnType, - _typeMappingSource.FindMapping(method.ReturnType, storeType)); - } + + return _sqlExpressionFactory.Function( + instance, + "STInteriorRingN", + new[] + { + _sqlExpressionFactory.Add( + arguments[0], + _sqlExpressionFactory.Constant(1)) + }, + method.ReturnType, + _typeMappingSource.FindMapping(method.ReturnType, storeType)); } return null; diff --git a/src/EFCore.SqlServer.NTS/Scaffolding/Internal/SqlServerNetTopologySuiteCodeGeneratorPlugin.cs b/src/EFCore.SqlServer.NTS/Scaffolding/Internal/SqlServerNetTopologySuiteCodeGeneratorPlugin.cs index a5cd3ec8aac..cd97fc7f83d 100644 --- a/src/EFCore.SqlServer.NTS/Scaffolding/Internal/SqlServerNetTopologySuiteCodeGeneratorPlugin.cs +++ b/src/EFCore.SqlServer.NTS/Scaffolding/Internal/SqlServerNetTopologySuiteCodeGeneratorPlugin.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.Design; diff --git a/src/EFCore.SqlServer.NTS/Storage/Internal/SqlServerGeometryTypeMapping.cs b/src/EFCore.SqlServer.NTS/Storage/Internal/SqlServerGeometryTypeMapping.cs index 52c7f541348..2ee0ddf2c5c 100644 --- a/src/EFCore.SqlServer.NTS/Storage/Internal/SqlServerGeometryTypeMapping.cs +++ b/src/EFCore.SqlServer.NTS/Storage/Internal/SqlServerGeometryTypeMapping.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -169,16 +169,10 @@ protected override void ConfigureParameter(DbParameter parameter) } private static SqlServerBytesReader CreateReader(NtsGeometryServices services, bool isGeography) - => new SqlServerBytesReader(services) - { - IsGeography = isGeography - }; + => new SqlServerBytesReader(services) { IsGeography = isGeography }; private static SqlServerBytesWriter CreateWriter(bool isGeography) - => new SqlServerBytesWriter - { - IsGeography = isGeography - }; + => new SqlServerBytesWriter { IsGeography = isGeography }; private static bool IsGeography(string storeType) => string.Equals(storeType, "geography", StringComparison.OrdinalIgnoreCase); diff --git a/src/EFCore.SqlServer.NTS/Storage/Internal/SqlServerNetTopologySuiteTypeMappingSourcePlugin.cs b/src/EFCore.SqlServer.NTS/Storage/Internal/SqlServerNetTopologySuiteTypeMappingSourcePlugin.cs index e2aca41c8b7..9367d2ff195 100644 --- a/src/EFCore.SqlServer.NTS/Storage/Internal/SqlServerNetTopologySuiteTypeMappingSourcePlugin.cs +++ b/src/EFCore.SqlServer.NTS/Storage/Internal/SqlServerNetTopologySuiteTypeMappingSourcePlugin.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -20,18 +20,17 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is and multiple registrations - /// are allowed. This means a single instance of each service is used by many + /// The service lifetime is and multiple registrations + /// are allowed. This means a single instance of each service is used by many /// instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public class SqlServerNetTopologySuiteTypeMappingSourcePlugin : IRelationalTypeMappingSourcePlugin { private readonly HashSet _spatialStoreTypes = new HashSet(StringComparer.OrdinalIgnoreCase) { - "geometry", - "geography" + "geometry", "geography" }; private readonly NtsGeometryServices _geometryServices; diff --git a/src/EFCore.SqlServer.NTS/Storage/ValueConversion/Internal/GeometryValueConverter.cs b/src/EFCore.SqlServer.NTS/Storage/ValueConversion/Internal/GeometryValueConverter.cs index 25d6f10c8b4..6e75cbe38d6 100644 --- a/src/EFCore.SqlServer.NTS/Storage/ValueConversion/Internal/GeometryValueConverter.cs +++ b/src/EFCore.SqlServer.NTS/Storage/ValueConversion/Internal/GeometryValueConverter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Data.SqlTypes; diff --git a/src/EFCore.SqlServer/Design/Internal/SqlServerAnnotationCodeGenerator.cs b/src/EFCore.SqlServer/Design/Internal/SqlServerAnnotationCodeGenerator.cs index 893a2bda01f..f53a4418296 100644 --- a/src/EFCore.SqlServer/Design/Internal/SqlServerAnnotationCodeGenerator.cs +++ b/src/EFCore.SqlServer/Design/Internal/SqlServerAnnotationCodeGenerator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.SqlServer/Diagnostics/SqlServerEventId.cs b/src/EFCore.SqlServer/Diagnostics/SqlServerEventId.cs index 8d6b343fb84..b5df7311019 100644 --- a/src/EFCore.SqlServer/Diagnostics/SqlServerEventId.cs +++ b/src/EFCore.SqlServer/Diagnostics/SqlServerEventId.cs @@ -126,7 +126,8 @@ private enum Id /// A foreign key references a missing table at the principal end. /// This event is in the category. /// - public static readonly EventId ForeignKeyReferencesMissingPrincipalTableWarning = MakeScaffoldingId(Id.ForeignKeyReferencesMissingPrincipalTableWarning); + public static readonly EventId ForeignKeyReferencesMissingPrincipalTableWarning = + MakeScaffoldingId(Id.ForeignKeyReferencesMissingPrincipalTableWarning); /// /// A table was found. @@ -168,7 +169,8 @@ private enum Id /// A principal column referenced by a foreign key was not found. /// This event is in the category. /// - public static readonly EventId ForeignKeyPrincipalColumnMissingWarning = MakeScaffoldingId(Id.ForeignKeyPrincipalColumnMissingWarning); + public static readonly EventId ForeignKeyPrincipalColumnMissingWarning = + MakeScaffoldingId(Id.ForeignKeyPrincipalColumnMissingWarning); /// /// A reflexive foreign key constraint was skipped. diff --git a/src/EFCore.SqlServer/Extensions/SqlServerDbFunctionsExtensions.cs b/src/EFCore.SqlServer/Extensions/SqlServerDbFunctionsExtensions.cs index d00ffd3c5e0..7816c44948e 100644 --- a/src/EFCore.SqlServer/Extensions/SqlServerDbFunctionsExtensions.cs +++ b/src/EFCore.SqlServer/Extensions/SqlServerDbFunctionsExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.SqlServer/Extensions/SqlServerMigrationBuilderExtensions.cs b/src/EFCore.SqlServer/Extensions/SqlServerMigrationBuilderExtensions.cs index 2d3e3dad176..e676f54b916 100644 --- a/src/EFCore.SqlServer/Extensions/SqlServerMigrationBuilderExtensions.cs +++ b/src/EFCore.SqlServer/Extensions/SqlServerMigrationBuilderExtensions.cs @@ -19,10 +19,14 @@ public static class SqlServerMigrationBuilderExtensions /// Returns true if the database provider currently in use is the SQL Server provider. /// /// - /// The migrationBuilder from the parameters on or . + /// + /// The migrationBuilder from the parameters on or + /// . + /// /// True if SQL Server is being used; false otherwise. public static bool IsSqlServer([NotNull] this MigrationBuilder migrationBuilder) - => string.Equals(migrationBuilder.ActiveProvider, + => string.Equals( + migrationBuilder.ActiveProvider, typeof(SqlServerOptionsExtension).GetTypeInfo().Assembly.GetName().Name, StringComparison.Ordinal); } diff --git a/src/EFCore.SqlServer/Extensions/SqlServerPropertyExtensions.cs b/src/EFCore.SqlServer/Extensions/SqlServerPropertyExtensions.cs index 8eef58268b1..c40a961a160 100644 --- a/src/EFCore.SqlServer/Extensions/SqlServerPropertyExtensions.cs +++ b/src/EFCore.SqlServer/Extensions/SqlServerPropertyExtensions.cs @@ -203,7 +203,7 @@ public static void SetIdentityIncrement( /// If no strategy is set for the property, then the strategy to use will be taken from the . /// /// - /// The strategy, or if none was set. + /// The strategy, or if none was set. public static SqlServerValueGenerationStrategy GetValueGenerationStrategy([NotNull] this IProperty property) { var annotation = property[SqlServerAnnotationNames.ValueGenerationStrategy]; @@ -304,7 +304,7 @@ private static void CheckValueGenerationStrategy(IProperty property, SqlServerVa => property.FindAnnotation(SqlServerAnnotationNames.ValueGenerationStrategy)?.GetConfigurationSource(); /// - /// Returns a value indicating whether the property is compatible with any . + /// Returns a value indicating whether the property is compatible with any . /// /// The property. /// true if compatible. diff --git a/src/EFCore.SqlServer/Extensions/SqlServerServiceCollectionExtensions.cs b/src/EFCore.SqlServer/Extensions/SqlServerServiceCollectionExtensions.cs index eef884a4854..f2db984a0d9 100644 --- a/src/EFCore.SqlServer/Extensions/SqlServerServiceCollectionExtensions.cs +++ b/src/EFCore.SqlServer/Extensions/SqlServerServiceCollectionExtensions.cs @@ -39,7 +39,7 @@ public static class SqlServerServiceCollectionExtensions /// Calling this method is no longer necessary when building most applications, including those that /// use dependency injection in ASP.NET or elsewhere. /// It is only needed when building the internal service provider for use with - /// the method. + /// the method. /// This is not recommend other than for some advanced scenarios. /// /// @@ -77,8 +77,6 @@ public static IServiceCollection AddEntityFrameworkSqlServer([NotNull] this ISer .TryAdd() .TryAdd() .TryAdd() - - .TryAddProviderSpecificServices( b => b .TryAddSingleton() diff --git a/src/EFCore.SqlServer/Infrastructure/Internal/ISqlServerOptions.cs b/src/EFCore.SqlServer/Infrastructure/Internal/ISqlServerOptions.cs index 27c92f2ac96..4d1d829cce9 100644 --- a/src/EFCore.SqlServer/Infrastructure/Internal/ISqlServerOptions.cs +++ b/src/EFCore.SqlServer/Infrastructure/Internal/ISqlServerOptions.cs @@ -13,10 +13,10 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal /// SQL Server specific options. /// /// - /// The service lifetime is and multiple registrations - /// are allowed. This means a single instance of each service is used by many + /// The service lifetime is and multiple registrations + /// are allowed. This means a single instance of each service is used by many /// instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public interface ISqlServerOptions : ISingletonOptions diff --git a/src/EFCore.SqlServer/Internal/SqlServerModelValidator.cs b/src/EFCore.SqlServer/Internal/SqlServerModelValidator.cs index ec301f6abe4..c11e35cf449 100644 --- a/src/EFCore.SqlServer/Internal/SqlServerModelValidator.cs +++ b/src/EFCore.SqlServer/Internal/SqlServerModelValidator.cs @@ -23,9 +23,9 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class SqlServerModelValidator : RelationalModelValidator @@ -65,7 +65,8 @@ public override void Validate(IModel model, IDiagnosticsLogger - protected virtual void ValidateDefaultDecimalMapping([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void ValidateDefaultDecimalMapping( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { foreach (var property in model.GetEntityTypes() .SelectMany(t => t.GetDeclaredProperties()) @@ -78,7 +79,7 @@ protected virtual void ValidateDefaultDecimalMapping([NotNull] IModel model, [No if ((typeConfigurationSource == null && ConfigurationSource.Convention.Overrides(typeMappingConfigurationSource)) || (typeConfigurationSource != null - && ConfigurationSource.Convention.Overrides(typeConfigurationSource))) + && ConfigurationSource.Convention.Overrides(typeConfigurationSource))) { logger.DecimalTypeDefaultWarning(property); } @@ -91,7 +92,8 @@ protected virtual void ValidateDefaultDecimalMapping([NotNull] IModel model, [No /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected virtual void ValidateByteIdentityMapping([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void ValidateByteIdentityMapping( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { foreach (var property in model.GetEntityTypes() .SelectMany(t => t.GetDeclaredProperties()) @@ -109,7 +111,8 @@ protected virtual void ValidateByteIdentityMapping([NotNull] IModel model, [NotN /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected virtual void ValidateNonKeyValueGeneration([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void ValidateNonKeyValueGeneration( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { foreach (var property in model.GetEntityTypes() .SelectMany(t => t.GetDeclaredProperties()) @@ -132,7 +135,8 @@ protected virtual void ValidateNonKeyValueGeneration([NotNull] IModel model, [No /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected virtual void ValidateIndexIncludeProperties([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void ValidateIndexIncludeProperties( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { foreach (var index in model.GetEntityTypes().SelectMany(t => t.GetDeclaredIndexes())) { diff --git a/src/EFCore.SqlServer/Internal/SqlServerOptions.cs b/src/EFCore.SqlServer/Internal/SqlServerOptions.cs index 6b3b1eef901..3632cdb4cc4 100644 --- a/src/EFCore.SqlServer/Internal/SqlServerOptions.cs +++ b/src/EFCore.SqlServer/Internal/SqlServerOptions.cs @@ -17,10 +17,10 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is and multiple registrations - /// are allowed. This means a single instance of each service is used by many + /// The service lifetime is and multiple registrations + /// are allowed. This means a single instance of each service is used by many /// instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public class SqlServerOptions : ISqlServerOptions diff --git a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerConventionSetBuilder.cs b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerConventionSetBuilder.cs index dda38ebbeab..ad5eba45689 100644 --- a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerConventionSetBuilder.cs +++ b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerConventionSetBuilder.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; @@ -53,7 +53,8 @@ public override ConventionSet CreateConventionSet() conventionSet.ModelInitializedConventions.Add( new RelationalMaxIdentifierLengthConvention(128, Dependencies, RelationalDependencies)); - ValueGenerationConvention valueGenerationConvention = new SqlServerValueGenerationConvention(Dependencies, RelationalDependencies); + ValueGenerationConvention valueGenerationConvention = + new SqlServerValueGenerationConvention(Dependencies, RelationalDependencies); ReplaceConvention(conventionSet.EntityTypeBaseTypeChangedConventions, valueGenerationConvention); var sqlServerInMemoryTablesConvention = new SqlServerMemoryOptimizedTablesConvention(Dependencies, RelationalDependencies); diff --git a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerStoreGenerationConvention.cs b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerStoreGenerationConvention.cs index 4284f8842c3..a0927e52bcf 100644 --- a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerStoreGenerationConvention.cs +++ b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerStoreGenerationConvention.cs @@ -13,7 +13,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// /// A convention that ensures that properties aren't configured to have a default value, as computed column - /// or using a at the same time. + /// or using a at the same time. /// public class SqlServerStoreGenerationConvention : StoreGenerationConvention { @@ -109,7 +109,7 @@ protected override void Validate(IConventionProperty property) "SqlServerValueGenerationStrategy", property.Name, "DefaultValue")); } - if(property.GetDefaultValueSql() != null) + if (property.GetDefaultValueSql() != null) { throw new InvalidOperationException( RelationalStrings.ConflictingColumnServerGeneration( diff --git a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerValueGenerationConvention.cs b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerValueGenerationConvention.cs index 624c0348098..93eab0584a0 100644 --- a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerValueGenerationConvention.cs +++ b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerValueGenerationConvention.cs @@ -10,10 +10,10 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// - /// A convention that configures store value generation as on properties that are + /// A convention that configures store value generation as on properties that are /// part of the primary key and not part of any foreign keys, were configured to have a database default value - /// or were configured to use a . - /// It also configures properties as if they were configured as computed columns. + /// or were configured to use a . + /// It also configures properties as if they were configured as computed columns. /// public class SqlServerValueGenerationConvention : RelationalValueGenerationConvention { @@ -59,7 +59,7 @@ public override void ProcessPropertyAnnotationChanged( /// The property. /// The store value generation strategy to set for the given property. protected override ValueGenerated? GetValueGenerated(IConventionProperty property) - => GetValueGenerated((IProperty)property); + => GetValueGenerated(property); /// /// Returns the store value generation strategy to set for the given property. @@ -68,8 +68,8 @@ public override void ProcessPropertyAnnotationChanged( /// The store value generation strategy to set for the given property. public static new ValueGenerated? GetValueGenerated([NotNull] IProperty property) => RelationalValueGenerationConvention.GetValueGenerated(property) - ?? (property.GetValueGenerationStrategy() != SqlServerValueGenerationStrategy.None - ? ValueGenerated.OnAdd - : (ValueGenerated?)null); + ?? (property.GetValueGenerationStrategy() != SqlServerValueGenerationStrategy.None + ? ValueGenerated.OnAdd + : (ValueGenerated?)null); } } diff --git a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerValueGenerationStrategyConvention.cs b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerValueGenerationStrategyConvention.cs index d3df05ee417..8f681652548 100644 --- a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerValueGenerationStrategyConvention.cs +++ b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerValueGenerationStrategyConvention.cs @@ -9,8 +9,8 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// - /// A convention that configures the default model as - /// . + /// A convention that configures the default model as + /// . /// public class SqlServerValueGenerationStrategyConvention : IModelInitializedConvention, IModelFinalizedConvention { @@ -36,7 +36,8 @@ public SqlServerValueGenerationStrategyConvention( /// /// The builder for the model. /// Additional information associated with convention execution. - public virtual void ProcessModelInitialized(IConventionModelBuilder modelBuilder, IConventionContext context) + public virtual void ProcessModelInitialized( + IConventionModelBuilder modelBuilder, IConventionContext context) { modelBuilder.HasValueGenerationStrategy(SqlServerValueGenerationStrategy.IdentityColumn); } diff --git a/src/EFCore.SqlServer/Migrations/Internal/SqlServerHistoryRepository.cs b/src/EFCore.SqlServer/Migrations/Internal/SqlServerHistoryRepository.cs index 0e367c3e75b..f384d6d36a0 100644 --- a/src/EFCore.SqlServer/Migrations/Internal/SqlServerHistoryRepository.cs +++ b/src/EFCore.SqlServer/Migrations/Internal/SqlServerHistoryRepository.cs @@ -20,8 +20,8 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Migrations.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.SqlServer/Migrations/Internal/SqlServerMigrationsAnnotationProvider.cs b/src/EFCore.SqlServer/Migrations/Internal/SqlServerMigrationsAnnotationProvider.cs index d111de56f2f..7a2ea66c007 100644 --- a/src/EFCore.SqlServer/Migrations/Internal/SqlServerMigrationsAnnotationProvider.cs +++ b/src/EFCore.SqlServer/Migrations/Internal/SqlServerMigrationsAnnotationProvider.cs @@ -21,9 +21,9 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Migrations.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class SqlServerMigrationsAnnotationProvider : MigrationsAnnotationProvider @@ -124,7 +124,6 @@ public override IEnumerable For(IProperty property) SqlServerAnnotationNames.Identity, string.Format(CultureInfo.InvariantCulture, "{0}, {1}", seed ?? 1, increment ?? 1)); } - } /// diff --git a/src/EFCore.SqlServer/Migrations/SqlServerMigrationsSqlGenerator.cs b/src/EFCore.SqlServer/Migrations/SqlServerMigrationsSqlGenerator.cs index 06e60e8ee18..87c48eae3ee 100644 --- a/src/EFCore.SqlServer/Migrations/SqlServerMigrationsSqlGenerator.cs +++ b/src/EFCore.SqlServer/Migrations/SqlServerMigrationsSqlGenerator.cs @@ -27,8 +27,8 @@ namespace Microsoft.EntityFrameworkCore.Migrations /// SQL Server-specific implementation of . /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -41,7 +41,7 @@ public class SqlServerMigrationsSqlGenerator : MigrationsSqlGenerator private int _variableCounter; /// - /// Creates a new instance. + /// Creates a new instance. /// /// Parameter object containing dependencies for this service. /// Provider-specific Migrations annotations to use. @@ -117,9 +117,11 @@ protected override void Generate( MigrationCommandListBuilder builder, bool terminate) { - if (!terminate && operation.Comment != null) + if (!terminate + && operation.Comment != null) { - throw new ArgumentException($"When generating migrations SQL for {nameof(AddColumnOperation)}, can't produce unterminated SQL with comments"); + throw new ArgumentException( + $"When generating migrations SQL for {nameof(AddColumnOperation)}, can't produce unterminated SQL with comments"); } if (IsIdentity(operation)) @@ -137,7 +139,8 @@ protected override void Generate( if (operation.Comment != null) { - AddDescription(builder, operation.Comment, + AddDescription( + builder, operation.Comment, operation.Schema, operation.Table, operation.Name); @@ -217,9 +220,7 @@ protected override void Generate( { var dropColumnOperation = new DropColumnOperation { - Schema = operation.Schema, - Table = operation.Table, - Name = operation.Name + Schema = operation.Schema, Table = operation.Table, Name = operation.Name }; if (property != null) { @@ -314,7 +315,7 @@ protected override void Generate( definitionOperation.AddAnnotations( operation.GetAnnotations().Where( a => a.Name != SqlServerAnnotationNames.ValueGenerationStrategy - && a.Name != SqlServerAnnotationNames.Identity)); + && a.Name != SqlServerAnnotationNames.Identity)); ColumnDefinition( operation.Schema, @@ -345,7 +346,8 @@ protected override void Generate( var dropDescription = operation.OldColumn.Comment != null; if (dropDescription) { - DropDescription(builder, + DropDescription( + builder, operation.Schema, operation.Table, operation.Name); @@ -353,7 +355,8 @@ protected override void Generate( if (operation.Comment != null) { - AddDescription(builder, operation.Comment, + AddDescription( + builder, operation.Comment, operation.Schema, operation.Table, operation.Name, @@ -472,9 +475,11 @@ protected override void Generate( MigrationCommandListBuilder builder, bool terminate = true) { - if (!terminate && operation.Comment != null) + if (!terminate + && operation.Comment != null) { - throw new ArgumentException($"When generating migrations SQL for {nameof(CreateTableOperation)}, can't produce unterminated SQL with comments"); + throw new ArgumentException( + $"When generating migrations SQL for {nameof(CreateTableOperation)}, can't produce unterminated SQL with comments"); } base.Generate(operation, model, builder, terminate: false); @@ -505,7 +510,8 @@ protected override void Generate( foreach (var column in operation.Columns.Where(c => c.Comment != null)) { - AddDescription(builder, column.Comment, + AddDescription( + builder, column.Comment, operation.Schema, operation.Name, column.Name, @@ -946,8 +952,10 @@ protected override void Generate( .IncrementIndent().AppendLine("SET @path = '\\' + @db_name;").DecrementIndent() .AppendLine() .AppendLine("DECLARE @filename NVARCHAR(MAX) = right(@path, charindex('\\', reverse(@path)) - 1);") - .AppendLine("SET @filename = REPLACE(left(@filename, len(@filename) - charindex('.', reverse(@filename))), '''', '''''') + N'_MOD';") - .AppendLine("DECLARE @new_path NVARCHAR(MAX) = REPLACE(CAST(SERVERPROPERTY('InstanceDefaultDataPath') AS NVARCHAR(MAX)), '''', '''''') + @filename;") + .AppendLine( + "SET @filename = REPLACE(left(@filename, len(@filename) - charindex('.', reverse(@filename))), '''', '''''') + N'_MOD';") + .AppendLine( + "DECLARE @new_path NVARCHAR(MAX) = REPLACE(CAST(SERVERPROPERTY('InstanceDefaultDataPath') AS NVARCHAR(MAX)), '''', '''''') + @filename;") .AppendLine() .AppendLine("EXEC(N'"); @@ -998,7 +1006,7 @@ protected override void Generate(AlterTableOperation operation, IModel model, Mi var dropDescription = operation.OldTable.Comment != null; if (dropDescription) { - DropDescription(builder, operation.Schema, operation.Name); + DropDescription(builder, operation.Schema, operation.Name); } if (operation.Comment != null) @@ -1331,7 +1339,8 @@ protected override void ColumnDefinition( var identity = operation[SqlServerAnnotationNames.Identity] as string; if (identity != null - || operation[SqlServerAnnotationNames.ValueGenerationStrategy] as SqlServerValueGenerationStrategy? == SqlServerValueGenerationStrategy.IdentityColumn) + || operation[SqlServerAnnotationNames.ValueGenerationStrategy] as SqlServerValueGenerationStrategy? + == SqlServerValueGenerationStrategy.IdentityColumn) { builder.Append(" IDENTITY"); @@ -1559,7 +1568,8 @@ protected virtual void DropDefaultConstraint( .Append(variable) .AppendLine(" = [d].[name]") .AppendLine("FROM [sys].[default_constraints] [d]") - .AppendLine("INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]") + .AppendLine( + "INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]") .Append("WHERE ([d].[parent_object_id] = OBJECT_ID(") .Append( stringTypeMapping.GenerateSqlLiteral( @@ -1602,7 +1612,8 @@ protected virtual IEnumerable GetIndexesToRebuild( var createIndexOperations = _operations.SkipWhile(o => o != currentOperation).Skip(1) .OfType().ToList(); - foreach (var index in property.DeclaringEntityType.GetIndexes().Concat(property.DeclaringEntityType.GetDerivedTypes().SelectMany(et => et.GetDeclaredIndexes()))) + foreach (var index in property.DeclaringEntityType.GetIndexes() + .Concat(property.DeclaringEntityType.GetDerivedTypes().SelectMany(et => et.GetDeclaredIndexes()))) { var indexName = index.GetName(); if (createIndexOperations.Any(o => o.Name == indexName)) @@ -1714,6 +1725,7 @@ protected virtual void AddDescription( builder.Append("SET @defaultSchema = SCHEMA_NAME()") .AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator); } + schemaLiteral = "@defaultSchema"; } else @@ -1772,6 +1784,7 @@ protected virtual void DropDescription( builder.Append("SET @defaultSchema = SCHEMA_NAME()") .AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator); } + schemaLiteral = "@defaultSchema"; } else @@ -1818,6 +1831,7 @@ private static bool IsMemoryOptimized(Annotatable annotatable) private static bool IsIdentity(ColumnOperation operation) => operation[SqlServerAnnotationNames.Identity] != null - || operation[SqlServerAnnotationNames.ValueGenerationStrategy] as SqlServerValueGenerationStrategy? == SqlServerValueGenerationStrategy.IdentityColumn; + || operation[SqlServerAnnotationNames.ValueGenerationStrategy] as SqlServerValueGenerationStrategy? + == SqlServerValueGenerationStrategy.IdentityColumn; } } diff --git a/src/EFCore.SqlServer/Properties/AssemblyInfo.cs b/src/EFCore.SqlServer/Properties/AssemblyInfo.cs index 8e093254fec..fc4c0f5da62 100644 --- a/src/EFCore.SqlServer/Properties/AssemblyInfo.cs +++ b/src/EFCore.SqlServer/Properties/AssemblyInfo.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.Design; diff --git a/src/EFCore.SqlServer/Query/Internal/SearchConditionConvertingExpressionVisitor.cs b/src/EFCore.SqlServer/Query/Internal/SearchConditionConvertingExpressionVisitor.cs index ffeb0b052f2..cd1d31f8f5b 100644 --- a/src/EFCore.SqlServer/Query/Internal/SearchConditionConvertingExpressionVisitor.cs +++ b/src/EFCore.SqlServer/Query/Internal/SearchConditionConvertingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -21,9 +21,9 @@ public SearchConditionConvertingExpressionVisitor( } private Expression ApplyConversion(SqlExpression sqlExpression, bool condition) - => _isSearchCondition - ? ConvertToSearchCondition(sqlExpression, condition) - : ConvertToValue(sqlExpression, condition); + => _isSearchCondition + ? ConvertToSearchCondition(sqlExpression, condition) + : ConvertToValue(sqlExpression, condition); private Expression ConvertToSearchCondition(SqlExpression sqlExpression, bool condition) => condition @@ -33,7 +33,8 @@ private Expression ConvertToSearchCondition(SqlExpression sqlExpression, bool co private Expression ConvertToValue(SqlExpression sqlExpression, bool condition) { return condition - ? _sqlExpressionFactory.Case(new[] + ? _sqlExpressionFactory.Case( + new[] { new CaseWhenClause( sqlExpression, @@ -174,7 +175,8 @@ protected override Expression VisitSelect(SelectExpression selectExpression) return changed ? selectExpression.Update( - projections, tables, predicate, groupBy, havingExpression, orderings, limit, offset, selectExpression.IsDistinct, selectExpression.Alias) + projections, tables, predicate, groupBy, havingExpression, orderings, limit, offset, selectExpression.IsDistinct, + selectExpression.Alias) : selectExpression; } @@ -201,13 +203,13 @@ protected override Expression VisitSqlBinary(SqlBinaryExpression sqlBinaryExpres sqlBinaryExpression = sqlBinaryExpression.Update(newLeft, newRight); var condition = sqlBinaryExpression.OperatorType == ExpressionType.AndAlso - || sqlBinaryExpression.OperatorType == ExpressionType.OrElse - || sqlBinaryExpression.OperatorType == ExpressionType.Equal - || sqlBinaryExpression.OperatorType == ExpressionType.NotEqual - || sqlBinaryExpression.OperatorType == ExpressionType.GreaterThan - || sqlBinaryExpression.OperatorType == ExpressionType.GreaterThanOrEqual - || sqlBinaryExpression.OperatorType == ExpressionType.LessThan - || sqlBinaryExpression.OperatorType == ExpressionType.LessThanOrEqual; + || sqlBinaryExpression.OperatorType == ExpressionType.OrElse + || sqlBinaryExpression.OperatorType == ExpressionType.Equal + || sqlBinaryExpression.OperatorType == ExpressionType.NotEqual + || sqlBinaryExpression.OperatorType == ExpressionType.GreaterThan + || sqlBinaryExpression.OperatorType == ExpressionType.GreaterThanOrEqual + || sqlBinaryExpression.OperatorType == ExpressionType.LessThan + || sqlBinaryExpression.OperatorType == ExpressionType.LessThanOrEqual; return ApplyConversion(sqlBinaryExpression, condition); } @@ -270,7 +272,7 @@ protected override Expression VisitSqlFunction(SqlFunctionExpression sqlFunction var newFunction = sqlFunctionExpression.Update(instance, arguments); var condition = string.Equals(sqlFunctionExpression.Name, "FREETEXT") - || string.Equals(sqlFunctionExpression.Name, "CONTAINS"); + || string.Equals(sqlFunctionExpression.Name, "CONTAINS"); return ApplyConversion(newFunction, condition); } diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerCompiledQueryCacheKeyGenerator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerCompiledQueryCacheKeyGenerator.cs index 1e347beb4ac..e94bd54531b 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerCompiledQueryCacheKeyGenerator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerCompiledQueryCacheKeyGenerator.cs @@ -18,8 +18,8 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerConvertTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerConvertTranslator.cs index ee9406293c3..be9d51717ee 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerConvertTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerConvertTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -43,6 +43,7 @@ private static readonly IEnumerable _supportedMethods .Where( m => m.GetParameters().Length == 1 && _supportedTypes.Contains(m.GetParameters().First().ParameterType))); + private readonly ISqlExpressionFactory _sqlExpressionFactory; public SqlServerConvertTranslator(ISqlExpressionFactory sqlExpressionFactory) @@ -55,11 +56,7 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method return _supportedMethods.Contains(method) ? _sqlExpressionFactory.Function( "CONVERT", - new[] - { - _sqlExpressionFactory.Fragment(_typeMapping[method.Name]), - arguments[0] - }, + new[] { _sqlExpressionFactory.Fragment(_typeMapping[method.Name]), arguments[0] }, method.ReturnType) : null; } diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerDateDiffFunctionsTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerDateDiffFunctionsTranslator.cs index 414aeca53e6..159143c7e87 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerDateDiffFunctionsTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerDateDiffFunctionsTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -303,6 +303,7 @@ private readonly Dictionary _methodInfoDateDiffMapping "NANOSECOND" } }; + private readonly ISqlExpressionFactory _sqlExpressionFactory; public SqlServerDateDiffFunctionsTranslator( @@ -324,12 +325,7 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method return _sqlExpressionFactory.Function( "DATEDIFF", - new[] - { - _sqlExpressionFactory.Fragment(datePart), - startDate, - endDate - }, + new[] { _sqlExpressionFactory.Fragment(datePart), startDate, endDate }, typeof(int)); } diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerDateTimeMemberTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerDateTimeMemberTranslator.cs index 43bbadef99f..293036b5fa5 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerDateTimeMemberTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerDateTimeMemberTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -23,6 +23,7 @@ private static readonly Dictionary _datePartMapping { nameof(DateTime.Second), "second" }, { nameof(DateTime.Millisecond), "millisecond" } }; + private readonly ISqlExpressionFactory _sqlExpressionFactory; public SqlServerDateTimeMemberTranslator(ISqlExpressionFactory sqlExpressionFactory) @@ -43,11 +44,7 @@ public virtual SqlExpression Translate(SqlExpression instance, MemberInfo member { return _sqlExpressionFactory.Function( "DATEPART", - new[] - { - _sqlExpressionFactory.Fragment(datePart), - instance - }, + new[] { _sqlExpressionFactory.Fragment(datePart), instance }, returnType); } @@ -55,13 +52,10 @@ public virtual SqlExpression Translate(SqlExpression instance, MemberInfo member { case nameof(DateTime.Date): return _sqlExpressionFactory.Function( - "CONVERT", - new[]{ - _sqlExpressionFactory.Fragment("date"), - instance - }, - returnType, - instance.TypeMapping); + "CONVERT", + new[] { _sqlExpressionFactory.Fragment("date"), instance }, + returnType, + instance.TypeMapping); case nameof(DateTime.TimeOfDay): return _sqlExpressionFactory.Convert(instance, returnType); diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerDateTimeMethodTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerDateTimeMethodTranslator.cs index ed509ca6b18..91a0beafad2 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerDateTimeMethodTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerDateTimeMethodTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -28,6 +28,7 @@ public class SqlServerDateTimeMethodTranslator : IMethodCallTranslator { typeof(DateTimeOffset).GetRuntimeMethod(nameof(DateTimeOffset.AddSeconds), new[] { typeof(double) }), "second" }, { typeof(DateTimeOffset).GetRuntimeMethod(nameof(DateTimeOffset.AddMilliseconds), new[] { typeof(double) }), "millisecond" } }; + private readonly ISqlExpressionFactory _sqlExpressionFactory; public SqlServerDateTimeMethodTranslator( @@ -50,9 +51,7 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method "DATEADD", new[] { - _sqlExpressionFactory.Fragment(datePart), - _sqlExpressionFactory.Convert(arguments[0], typeof(int)), - instance + _sqlExpressionFactory.Fragment(datePart), _sqlExpressionFactory.Convert(arguments[0], typeof(int)), instance }, instance.Type, instance.TypeMapping); diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerFullTextSearchFunctionsTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerFullTextSearchFunctionsTranslator.cs index 7ac60f01793..b63a5c41194 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerFullTextSearchFunctionsTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerFullTextSearchFunctionsTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -38,11 +38,12 @@ private static readonly MethodInfo _containsMethodInfoWithLanguage private static readonly IDictionary _functionMapping = new Dictionary { - {_freeTextMethodInfo, FreeTextFunctionName }, - {_freeTextMethodInfoWithLanguage, FreeTextFunctionName }, - {_containsMethodInfo, ContainsFunctionName }, - {_containsMethodInfoWithLanguage, ContainsFunctionName }, + { _freeTextMethodInfo, FreeTextFunctionName }, + { _freeTextMethodInfoWithLanguage, FreeTextFunctionName }, + { _containsMethodInfo, ContainsFunctionName }, + { _containsMethodInfoWithLanguage, ContainsFunctionName } }; + private readonly ISqlExpressionFactory _sqlExpressionFactory; public SqlServerFullTextSearchFunctionsTranslator( @@ -64,11 +65,7 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method var typeMapping = propertyReference.TypeMapping; var freeText = _sqlExpressionFactory.ApplyTypeMapping(arguments[2], typeMapping); - var functionArguments = new List - { - propertyReference, - freeText - }; + var functionArguments = new List { propertyReference, freeText }; if (arguments.Count == 4) { diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerIsDateFunctionTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerIsDateFunctionTranslator.cs index eca1b1b090f..18f0c004fee 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerIsDateFunctionTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerIsDateFunctionTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; @@ -22,14 +22,11 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method { return _methodInfo.Equals(method) ? _sqlExpressionFactory.Convert( - _sqlExpressionFactory.Function( + _sqlExpressionFactory.Function( "ISDATE", - new[] - { - arguments[1] - }, + new[] { arguments[1] }, _methodInfo.ReturnType), - _methodInfo.ReturnType) + _methodInfo.ReturnType) : null; } } diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerMathTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerMathTranslator.cs index 038ab5e0bda..974a0cb2d66 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerMathTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerMathTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -60,6 +60,7 @@ public class SqlServerMathTranslator : IMethodCallTranslator typeof(Math).GetRuntimeMethod(nameof(Math.Round), new[] { typeof(decimal), typeof(int) }), typeof(Math).GetRuntimeMethod(nameof(Math.Round), new[] { typeof(double), typeof(int) }) }; + private readonly ISqlExpressionFactory _sqlExpressionFactory; public SqlServerMathTranslator(ISqlExpressionFactory sqlExpressionFactory) @@ -96,11 +97,7 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method return _sqlExpressionFactory.Function( "ROUND", - new[] { - argument, - _sqlExpressionFactory.Constant(0), - _sqlExpressionFactory.Constant(1) - }, + new[] { argument, _sqlExpressionFactory.Constant(0), _sqlExpressionFactory.Constant(1) }, method.ReturnType, argument.TypeMapping); } diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerMemberTranslatorProvider.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerMemberTranslatorProvider.cs index 214ca6a2b49..96298d97f55 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerMemberTranslatorProvider.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerMemberTranslatorProvider.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; @@ -14,7 +14,8 @@ public SqlServerMemberTranslatorProvider([NotNull] RelationalMemberTranslatorPro var sqlExpressionFactory = dependencies.SqlExpressionFactory; AddTranslators( - new IMemberTranslator[] { + new IMemberTranslator[] + { new SqlServerDateTimeMemberTranslator(sqlExpressionFactory), new SqlServerStringMemberTranslator(sqlExpressionFactory) }); diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerMethodCallTranslatorProvider.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerMethodCallTranslatorProvider.cs index 0e000fb5b76..8d6906e807e 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerMethodCallTranslatorProvider.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerMethodCallTranslatorProvider.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; @@ -13,18 +13,19 @@ public SqlServerMethodCallTranslatorProvider([NotNull] RelationalMethodCallTrans { var sqlExpressionFactory = dependencies.SqlExpressionFactory; - AddTranslators(new IMethodCallTranslator[] - { - new SqlServerConvertTranslator(sqlExpressionFactory), - new SqlServerDateTimeMethodTranslator(sqlExpressionFactory), - new SqlServerDateDiffFunctionsTranslator(sqlExpressionFactory), - new SqlServerFullTextSearchFunctionsTranslator(sqlExpressionFactory), - new SqlServerIsDateFunctionTranslator(sqlExpressionFactory), - new SqlServerMathTranslator(sqlExpressionFactory), - new SqlServerNewGuidTranslator(sqlExpressionFactory), - new SqlServerObjectToStringTranslator(sqlExpressionFactory), - new SqlServerStringMethodTranslator(sqlExpressionFactory), - }); + AddTranslators( + new IMethodCallTranslator[] + { + new SqlServerConvertTranslator(sqlExpressionFactory), + new SqlServerDateTimeMethodTranslator(sqlExpressionFactory), + new SqlServerDateDiffFunctionsTranslator(sqlExpressionFactory), + new SqlServerFullTextSearchFunctionsTranslator(sqlExpressionFactory), + new SqlServerIsDateFunctionTranslator(sqlExpressionFactory), + new SqlServerMathTranslator(sqlExpressionFactory), + new SqlServerNewGuidTranslator(sqlExpressionFactory), + new SqlServerObjectToStringTranslator(sqlExpressionFactory), + new SqlServerStringMethodTranslator(sqlExpressionFactory) + }); } } } diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerNewGuidTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerNewGuidTranslator.cs index bc08eb8a415..bd9aec0745e 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerNewGuidTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerNewGuidTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerObjectToStringTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerObjectToStringTranslator.cs index 4c109c2946b..668977b7181 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerObjectToStringTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerObjectToStringTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -34,6 +34,7 @@ private static readonly Dictionary _typeMapping { typeof(ulong), "VARCHAR(19)" }, { typeof(sbyte), "VARCHAR(4)" } }; + private readonly ISqlExpressionFactory _sqlExpressionFactory; public SqlServerObjectToStringTranslator(ISqlExpressionFactory sqlExpressionFactory) @@ -51,11 +52,7 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method out var storeType) ? _sqlExpressionFactory.Function( "CONVERT", - new[] - { - _sqlExpressionFactory.Fragment(storeType), - instance - }, + new[] { _sqlExpressionFactory.Fragment(storeType), instance }, typeof(string)) : null; } diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerQuerySqlGenerator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerQuerySqlGenerator.cs index e74e654bf7a..2a07ece04bd 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerQuerySqlGenerator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerQuerySqlGenerator.cs @@ -63,7 +63,6 @@ protected override Expression VisitSqlFunction(SqlFunctionExpression sqlFunction sqlFunctionExpression.TypeMapping); } - return base.VisitSqlFunction(sqlFunctionExpression); } } diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerQueryTranslationPostprocessor.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerQueryTranslationPostprocessor.cs index 2ddece8e370..a81be171ec6 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerQueryTranslationPostprocessor.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerQueryTranslationPostprocessor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq.Expressions; diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerQueryTranslationPostprocessorFactory.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerQueryTranslationPostprocessorFactory.cs index f26664992d2..c87d356fd6a 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerQueryTranslationPostprocessorFactory.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerQueryTranslationPostprocessorFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.Query; diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerSqlTranslatingExpressionVisitor.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerSqlTranslatingExpressionVisitor.cs index 498539c95d9..d63e6cebee0 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerSqlTranslatingExpressionVisitor.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerSqlTranslatingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; @@ -28,8 +28,9 @@ private static readonly HashSet _arithmeticOperatorTypes ExpressionType.Subtract, ExpressionType.Multiply, ExpressionType.Divide, - ExpressionType.Modulo, + ExpressionType.Modulo }; + // TODO: Possibly make this protected in base private readonly ISqlExpressionFactory _sqlExpressionFactory; @@ -52,9 +53,9 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression) } return visitedExpression is SqlBinaryExpression sqlBinary - && _arithmeticOperatorTypes.Contains(sqlBinary.OperatorType) - && (_dateTimeDataTypes.Contains(GetProviderType(sqlBinary.Left)) - || _dateTimeDataTypes.Contains(GetProviderType(sqlBinary.Right))) + && _arithmeticOperatorTypes.Contains(sqlBinary.OperatorType) + && (_dateTimeDataTypes.Contains(GetProviderType(sqlBinary.Left)) + || _dateTimeDataTypes.Contains(GetProviderType(sqlBinary.Right))) ? null : visitedExpression; } diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerSqlTranslatingExpressionVisitorFactory.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerSqlTranslatingExpressionVisitorFactory.cs index 6d91e6e1040..9792e0439e8 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerSqlTranslatingExpressionVisitorFactory.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerSqlTranslatingExpressionVisitorFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerStringMemberTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerStringMemberTranslator.cs index 10f5688ff20..4fb3fa5eb7f 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerStringMemberTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerStringMemberTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerStringMethodTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerStringMethodTranslator.cs index 4ebf5b408f2..2bca24ff7a6 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerStringMethodTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerStringMethodTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -15,39 +15,51 @@ public class SqlServerStringMethodTranslator : IMethodCallTranslator { private static readonly MethodInfo _indexOfMethodInfo = typeof(string).GetRuntimeMethod(nameof(string.IndexOf), new[] { typeof(string) }); + private static readonly MethodInfo _replaceMethodInfo = typeof(string).GetRuntimeMethod(nameof(string.Replace), new[] { typeof(string), typeof(string) }); + private static readonly MethodInfo _toLowerMethodInfo = typeof(string).GetRuntimeMethod(nameof(string.ToLower), Array.Empty()); + private static readonly MethodInfo _toUpperMethodInfo = typeof(string).GetRuntimeMethod(nameof(string.ToUpper), Array.Empty()); + private static readonly MethodInfo _substringMethodInfo = typeof(string).GetRuntimeMethod(nameof(string.Substring), new[] { typeof(int), typeof(int) }); + private static readonly MethodInfo _isNullOrWhiteSpaceMethodInfo = typeof(string).GetRuntimeMethod(nameof(string.IsNullOrWhiteSpace), new[] { typeof(string) }); // Method defined in netcoreapp2.0 only private static readonly MethodInfo _trimStartMethodInfoWithoutArgs = typeof(string).GetRuntimeMethod(nameof(string.TrimStart), Array.Empty()); + private static readonly MethodInfo _trimEndMethodInfoWithoutArgs = typeof(string).GetRuntimeMethod(nameof(string.TrimEnd), Array.Empty()); + private static readonly MethodInfo _trimMethodInfoWithoutArgs = typeof(string).GetRuntimeMethod(nameof(string.Trim), Array.Empty()); // Method defined in netstandard2.0 private static readonly MethodInfo _trimStartMethodInfoWithCharArrayArg = typeof(string).GetRuntimeMethod(nameof(string.TrimStart), new[] { typeof(char[]) }); + private static readonly MethodInfo _trimEndMethodInfoWithCharArrayArg = typeof(string).GetRuntimeMethod(nameof(string.TrimEnd), new[] { typeof(char[]) }); + private static readonly MethodInfo _trimMethodInfoWithCharArrayArg = typeof(string).GetRuntimeMethod(nameof(string.Trim), new[] { typeof(char[]) }); private static readonly MethodInfo _startsWithMethodInfo = typeof(string).GetRuntimeMethod(nameof(string.StartsWith), new[] { typeof(string) }); + private static readonly MethodInfo _containsMethodInfo = typeof(string).GetRuntimeMethod(nameof(string.Contains), new[] { typeof(string) }); + private static readonly MethodInfo _endsWithMethodInfo = typeof(string).GetRuntimeMethod(nameof(string.EndsWith), new[] { typeof(string) }); + private readonly ISqlExpressionFactory _sqlExpressionFactory; private const char LikeEscapeChar = '\\'; @@ -68,11 +80,7 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method var charIndexExpression = _sqlExpressionFactory.Subtract( _sqlExpressionFactory.Function( "CHARINDEX", - new[] - { - argument, - _sqlExpressionFactory.ApplyTypeMapping(instance, stringTypeMapping) - }, + new[] { argument, _sqlExpressionFactory.ApplyTypeMapping(instance, stringTypeMapping) }, method.ReturnType), _sqlExpressionFactory.Constant(1)); @@ -100,12 +108,7 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method return _sqlExpressionFactory.Function( "REPLACE", - new[] - { - instance, - firstArgument, - secondArgument - }, + new[] { instance, firstArgument, secondArgument }, method.ReturnType, stringTypeMapping); } @@ -145,13 +148,11 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method _sqlExpressionFactory.Equal( _sqlExpressionFactory.Function( "LTRIM", - new[] { + new[] + { _sqlExpressionFactory.Function( "RTRIM", - new[] - { - argument - }, + new[] { argument }, argument.Type, argument.TypeMapping) }, @@ -167,10 +168,7 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method { return _sqlExpressionFactory.Function( "LTRIM", - new[] - { - instance - }, + new[] { instance }, instance.Type, instance.TypeMapping); } @@ -182,10 +180,7 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method { return _sqlExpressionFactory.Function( "RTRIM", - new[] - { - instance - }, + new[] { instance }, instance.Type, instance.TypeMapping); } @@ -201,10 +196,7 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method { _sqlExpressionFactory.Function( "RTRIM", - new [] - { - instance - }, + new[] { instance }, instance.Type, instance.TypeMapping) }, @@ -229,11 +221,7 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method return _sqlExpressionFactory.GreaterThan( _sqlExpressionFactory.Function( "CHARINDEX", - new[] - { - pattern, - instance - }, + new[] { pattern, instance }, typeof(int)), _sqlExpressionFactory.Constant(0)); } @@ -245,11 +233,7 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method _sqlExpressionFactory.GreaterThan( _sqlExpressionFactory.Function( "CHARINDEX", - new[] - { - pattern, - instance - }, + new[] { pattern, instance }, typeof(int)), _sqlExpressionFactory.Constant(0))); } @@ -292,11 +276,11 @@ private SqlExpression TranslateStartsEndsWith(SqlExpression instance, SqlExpress startsWith ? EscapeLikePattern(constantString) + '%' : '%' + EscapeLikePattern(constantString)), - _sqlExpressionFactory.Constant(LikeEscapeChar.ToString())) // SQL Server has no char mapping, avoid value conversion warning) + _sqlExpressionFactory.Constant( + LikeEscapeChar.ToString())) // SQL Server has no char mapping, avoid value conversion warning) : _sqlExpressionFactory.Like( instance, - _sqlExpressionFactory.Constant(startsWith ? constantString + '%' : '%' + constantString), - null); + _sqlExpressionFactory.Constant(startsWith ? constantString + '%' : '%' + constantString)); } // The pattern is non-constant, we use LEFT or RIGHT to extract substring and compare. @@ -313,10 +297,7 @@ private SqlExpression TranslateStartsEndsWith(SqlExpression instance, SqlExpress _sqlExpressionFactory.Equal( _sqlExpressionFactory.Function( "LEFT", - new[] { - instance, - _sqlExpressionFactory.Function("LEN", new[] { pattern }, typeof(int)) - }, + new[] { instance, _sqlExpressionFactory.Function("LEN", new[] { pattern }, typeof(int)) }, typeof(string), stringTypeMapping), pattern)); @@ -325,10 +306,7 @@ private SqlExpression TranslateStartsEndsWith(SqlExpression instance, SqlExpress return _sqlExpressionFactory.Equal( _sqlExpressionFactory.Function( "RIGHT", - new[] { - instance, - _sqlExpressionFactory.Function("LEN", new[] { pattern }, typeof(int)) - }, + new[] { instance, _sqlExpressionFactory.Function("LEN", new[] { pattern }, typeof(int)) }, typeof(string), stringTypeMapping), pattern); @@ -343,7 +321,8 @@ private string EscapeLikePattern(string pattern) for (var i = 0; i < pattern.Length; i++) { var c = pattern[i]; - if (IsLikeWildChar(c) || c == LikeEscapeChar) + if (IsLikeWildChar(c) + || c == LikeEscapeChar) { builder.Append(LikeEscapeChar); } diff --git a/src/EFCore.SqlServer/Scaffolding/Internal/SqlServerCodeGenerator.cs b/src/EFCore.SqlServer/Scaffolding/Internal/SqlServerCodeGenerator.cs index ab3bfc0f3f8..044de83b72c 100644 --- a/src/EFCore.SqlServer/Scaffolding/Internal/SqlServerCodeGenerator.cs +++ b/src/EFCore.SqlServer/Scaffolding/Internal/SqlServerCodeGenerator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.SqlServer/Scaffolding/Internal/SqlServerDatabaseModelFactory.cs b/src/EFCore.SqlServer/Scaffolding/Internal/SqlServerDatabaseModelFactory.cs index de89ffd5842..8b83926f84f 100644 --- a/src/EFCore.SqlServer/Scaffolding/Internal/SqlServerDatabaseModelFactory.cs +++ b/src/EFCore.SqlServer/Scaffolding/Internal/SqlServerDatabaseModelFactory.cs @@ -33,12 +33,7 @@ public class SqlServerDatabaseModelFactory : DatabaseModelFactory { private readonly IDiagnosticsLogger _logger; - private static readonly ISet _dateTimePrecisionTypes = new HashSet - { - "datetimeoffset", - "datetime2", - "time" - }; + private static readonly ISet _dateTimePrecisionTypes = new HashSet { "datetimeoffset", "datetime2", "time" }; private static readonly ISet _maxLengthRequiredTypes = new HashSet @@ -66,13 +61,14 @@ private static readonly Regex _partExtractor // see https://msdn.microsoft.com/en-us/library/ff878091.aspx // decimal/numeric are excluded because default value varies based on the precision. - private static readonly Dictionary _defaultSequenceMinMax = new Dictionary(StringComparer.OrdinalIgnoreCase) - { - { "tinyint", new[] { 0L, 255L } }, - { "smallint", new[] { -32768L, 32767L } }, - { "int", new[] { -2147483648L, 2147483647L } }, - { "bigint", new[] { -9223372036854775808L, 9223372036854775807L } } - }; + private static readonly Dictionary _defaultSequenceMinMax = + new Dictionary(StringComparer.OrdinalIgnoreCase) + { + { "tinyint", new[] { 0L, 255L } }, + { "smallint", new[] { -32768L, 32767L } }, + { "int", new[] { -2147483648L, 2147483647L } }, + { "bigint", new[] { -9223372036854775808L, 9223372036854775807L } } + }; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -420,7 +416,9 @@ FROM [sys].[sequences] AS [s] sequence.MinValue = sequence.MinValue == defaultMin ? null : sequence.MinValue; sequence.StartValue = sequence.StartValue == defaultMin ? null : sequence.StartValue; - sequence.MaxValue = sequence.MaxValue == _defaultSequenceMinMax[sequence.StoreType][1] ? null : sequence.MaxValue; + sequence.MaxValue = sequence.MaxValue == _defaultSequenceMinMax[sequence.StoreType][1] + ? null + : sequence.MaxValue; } yield return sequence; @@ -869,11 +867,7 @@ FROM [sys].[indexes] i _logger.PrimaryKeyFound(primaryKeyGroup.Key.Name, DisplayName(tableSchema, tableName)); - var primaryKey = new DatabasePrimaryKey - { - Table = table, - Name = primaryKeyGroup.Key.Name - }; + var primaryKey = new DatabasePrimaryKey { Table = table, Name = primaryKeyGroup.Key.Name }; if (primaryKeyGroup.Key.TypeDesc == "NONCLUSTERED") { @@ -884,7 +878,8 @@ FROM [sys].[indexes] i { var columnName = dataRecord.GetValueOrDefault("column_name"); var column = table.Columns.FirstOrDefault(c => c.Name == columnName) - ?? table.Columns.FirstOrDefault(c => c.Name.Equals(columnName, StringComparison.OrdinalIgnoreCase)); + ?? table.Columns.FirstOrDefault( + c => c.Name.Equals(columnName, StringComparison.OrdinalIgnoreCase)); Debug.Assert(column != null, "column is null."); primaryKey.Columns.Add(column); @@ -905,11 +900,7 @@ FROM [sys].[indexes] i { _logger.UniqueConstraintFound(uniqueConstraintGroup.Key.Name, DisplayName(tableSchema, tableName)); - var uniqueConstraint = new DatabaseUniqueConstraint - { - Table = table, - Name = uniqueConstraintGroup.Key.Name - }; + var uniqueConstraint = new DatabaseUniqueConstraint { Table = table, Name = uniqueConstraintGroup.Key.Name }; if (uniqueConstraintGroup.Key.TypeDesc == "CLUSTERED") { @@ -920,7 +911,8 @@ FROM [sys].[indexes] i { var columnName = dataRecord.GetValueOrDefault("column_name"); var column = table.Columns.FirstOrDefault(c => c.Name == columnName) - ?? table.Columns.FirstOrDefault(c => c.Name.Equals(columnName, StringComparison.OrdinalIgnoreCase)); + ?? table.Columns.FirstOrDefault( + c => c.Name.Equals(columnName, StringComparison.OrdinalIgnoreCase)); Debug.Assert(column != null, "column is null."); uniqueConstraint.Columns.Add(column); @@ -963,7 +955,8 @@ FROM [sys].[indexes] i { var columnName = dataRecord.GetValueOrDefault("column_name"); var column = table.Columns.FirstOrDefault(c => c.Name == columnName) - ?? table.Columns.FirstOrDefault(c => c.Name.Equals(columnName, StringComparison.OrdinalIgnoreCase)); + ?? table.Columns.FirstOrDefault( + c => c.Name.Equals(columnName, StringComparison.OrdinalIgnoreCase)); Debug.Assert(column != null, "column is null."); index.Columns.Add(column); @@ -1061,12 +1054,14 @@ FROM [sys].[foreign_keys] AS [f] { var columnName = dataRecord.GetValueOrDefault("column_name"); var column = table.Columns.FirstOrDefault(c => c.Name == columnName) - ?? table.Columns.FirstOrDefault(c => c.Name.Equals(columnName, StringComparison.OrdinalIgnoreCase)); + ?? table.Columns.FirstOrDefault( + c => c.Name.Equals(columnName, StringComparison.OrdinalIgnoreCase)); Debug.Assert(column != null, "column is null."); var principalColumnName = dataRecord.GetValueOrDefault("referenced_column_name"); var principalColumn = foreignKey.PrincipalTable.Columns.FirstOrDefault(c => c.Name == principalColumnName) - ?? foreignKey.PrincipalTable.Columns.FirstOrDefault(c => c.Name.Equals(principalColumnName, StringComparison.OrdinalIgnoreCase)); + ?? foreignKey.PrincipalTable.Columns.FirstOrDefault( + c => c.Name.Equals(principalColumnName, StringComparison.OrdinalIgnoreCase)); if (principalColumn == null) { invalid = true; diff --git a/src/EFCore.SqlServer/Storage/Internal/ISqlServerConnection.cs b/src/EFCore.SqlServer/Storage/Internal/ISqlServerConnection.cs index bf11ec11b80..c2819c82997 100644 --- a/src/EFCore.SqlServer/Storage/Internal/ISqlServerConnection.cs +++ b/src/EFCore.SqlServer/Storage/Internal/ISqlServerConnection.cs @@ -14,8 +14,8 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.SqlServer/Storage/Internal/SqlServerBoolTypeMapping.cs b/src/EFCore.SqlServer/Storage/Internal/SqlServerBoolTypeMapping.cs index 3a7f15592de..0dd23ef2ba2 100644 --- a/src/EFCore.SqlServer/Storage/Internal/SqlServerBoolTypeMapping.cs +++ b/src/EFCore.SqlServer/Storage/Internal/SqlServerBoolTypeMapping.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Data; diff --git a/src/EFCore.SqlServer/Storage/Internal/SqlServerByteTypeMapping.cs b/src/EFCore.SqlServer/Storage/Internal/SqlServerByteTypeMapping.cs index ebf9083890d..64fd39348f8 100644 --- a/src/EFCore.SqlServer/Storage/Internal/SqlServerByteTypeMapping.cs +++ b/src/EFCore.SqlServer/Storage/Internal/SqlServerByteTypeMapping.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Data; diff --git a/src/EFCore.SqlServer/Storage/Internal/SqlServerConnection.cs b/src/EFCore.SqlServer/Storage/Internal/SqlServerConnection.cs index 300a6ecf468..f1a7ee6cdef 100644 --- a/src/EFCore.SqlServer/Storage/Internal/SqlServerConnection.cs +++ b/src/EFCore.SqlServer/Storage/Internal/SqlServerConnection.cs @@ -17,8 +17,8 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -57,10 +57,7 @@ public SqlServerConnection([NotNull] RelationalConnectionDependencies dependenci /// public virtual ISqlServerConnection CreateMasterConnection() { - var connectionStringBuilder = new SqlConnectionStringBuilder(ConnectionString) - { - InitialCatalog = "master" - }; + var connectionStringBuilder = new SqlConnectionStringBuilder(ConnectionString) { InitialCatalog = "master" }; connectionStringBuilder.Remove("AttachDBFilename"); var contextOptions = new DbContextOptionsBuilder() diff --git a/src/EFCore.SqlServer/Storage/Internal/SqlServerDatabaseCreator.cs b/src/EFCore.SqlServer/Storage/Internal/SqlServerDatabaseCreator.cs index 7c82e592b57..7fdfbd28cc1 100644 --- a/src/EFCore.SqlServer/Storage/Internal/SqlServerDatabaseCreator.cs +++ b/src/EFCore.SqlServer/Storage/Internal/SqlServerDatabaseCreator.cs @@ -24,8 +24,8 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -144,7 +144,8 @@ public override Task HasTablesAsync(CancellationToken cancellationToken = private IRelationalCommand CreateHasTablesCommand() => _rawSqlCommandBuilder - .Build(@" + .Build( + @" IF EXISTS (SELECT * FROM [sys].[objects] o @@ -164,14 +165,7 @@ private IReadOnlyList CreateCreateOperations() { var builder = new SqlConnectionStringBuilder(_connection.DbConnection.ConnectionString); return Dependencies.MigrationsSqlGenerator.Generate( - new[] - { - new SqlServerCreateDatabaseOperation - { - Name = builder.InitialCatalog, - FileName = builder.AttachDBFilename - } - }); + new[] { new SqlServerCreateDatabaseOperation { Name = builder.InitialCatalog, FileName = builder.AttachDBFilename } }); } /// @@ -345,13 +339,7 @@ private IReadOnlyList CreateDropCommands() throw new InvalidOperationException(SqlServerStrings.NoInitialCatalog); } - var operations = new MigrationOperation[] - { - new SqlServerDropDatabaseOperation - { - Name = databaseName - } - }; + var operations = new MigrationOperation[] { new SqlServerDropDatabaseOperation { Name = databaseName } }; return Dependencies.MigrationsSqlGenerator.Generate(operations); } diff --git a/src/EFCore.SqlServer/Storage/Internal/SqlServerDateTimeTypeMapping.cs b/src/EFCore.SqlServer/Storage/Internal/SqlServerDateTimeTypeMapping.cs index 9974c941bb0..843af09ec47 100644 --- a/src/EFCore.SqlServer/Storage/Internal/SqlServerDateTimeTypeMapping.cs +++ b/src/EFCore.SqlServer/Storage/Internal/SqlServerDateTimeTypeMapping.cs @@ -21,7 +21,7 @@ public class SqlServerDateTimeTypeMapping : DateTimeTypeMapping private const string SmallDateTimeFormatConst = "'{0:yyyy-MM-ddTHH:mm:ss}'"; private const string DateTimeFormatConst = "'{0:yyyy-MM-ddTHH:mm:ss.fff}'"; - private readonly string[] _dateTime2Formats = new[] + private readonly string[] _dateTime2Formats = { "'{0:yyyy-MM-ddTHH:mm:ss}'", "'{0:yyyy-MM-ddTHH:mm:ss.fK}'", @@ -110,7 +110,8 @@ protected override string SqlLiteralFormatString if (Size.HasValue) { var size = Size.Value; - if (size <= 7 && size >= 0) + if (size <= 7 + && size >= 0) { return _dateTime2Formats[size]; } diff --git a/src/EFCore.SqlServer/Storage/Internal/SqlServerExecutionStrategyFactory.cs b/src/EFCore.SqlServer/Storage/Internal/SqlServerExecutionStrategyFactory.cs index 2d043652945..3b54fd9532e 100644 --- a/src/EFCore.SqlServer/Storage/Internal/SqlServerExecutionStrategyFactory.cs +++ b/src/EFCore.SqlServer/Storage/Internal/SqlServerExecutionStrategyFactory.cs @@ -15,8 +15,8 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.SqlServer/Storage/Internal/SqlServerLongTypeMapping.cs b/src/EFCore.SqlServer/Storage/Internal/SqlServerLongTypeMapping.cs index d9111d747ae..c952321baf9 100644 --- a/src/EFCore.SqlServer/Storage/Internal/SqlServerLongTypeMapping.cs +++ b/src/EFCore.SqlServer/Storage/Internal/SqlServerLongTypeMapping.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Data; diff --git a/src/EFCore.SqlServer/Storage/Internal/SqlServerShortTypeMapping.cs b/src/EFCore.SqlServer/Storage/Internal/SqlServerShortTypeMapping.cs index bfb0e7c7c80..f0433736bc1 100644 --- a/src/EFCore.SqlServer/Storage/Internal/SqlServerShortTypeMapping.cs +++ b/src/EFCore.SqlServer/Storage/Internal/SqlServerShortTypeMapping.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Data; diff --git a/src/EFCore.SqlServer/Storage/Internal/SqlServerSqlGenerationHelper.cs b/src/EFCore.SqlServer/Storage/Internal/SqlServerSqlGenerationHelper.cs index 2d596df06fc..899cf074bf9 100644 --- a/src/EFCore.SqlServer/Storage/Internal/SqlServerSqlGenerationHelper.cs +++ b/src/EFCore.SqlServer/Storage/Internal/SqlServerSqlGenerationHelper.cs @@ -18,9 +18,9 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class SqlServerSqlGenerationHelper : RelationalSqlGenerationHelper diff --git a/src/EFCore.SqlServer/Storage/Internal/SqlServerTypeMappingSource.cs b/src/EFCore.SqlServer/Storage/Internal/SqlServerTypeMappingSource.cs index 4d3502a653e..95cb1a0681b 100644 --- a/src/EFCore.SqlServer/Storage/Internal/SqlServerTypeMappingSource.cs +++ b/src/EFCore.SqlServer/Storage/Internal/SqlServerTypeMappingSource.cs @@ -23,9 +23,9 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class SqlServerTypeMappingSource : RelationalTypeMappingSource @@ -116,7 +116,8 @@ private readonly GuidTypeMapping _uniqueidentifier = new GuidTypeMapping("uniqueidentifier", DbType.Guid); private readonly DecimalTypeMapping _decimal - = new SqlServerDecimalTypeMapping("decimal(18, 2)", precision: 18, scale: 2, storeTypePostfix: StoreTypePostfix.PrecisionAndScale); + = new SqlServerDecimalTypeMapping( + "decimal(18, 2)", precision: 18, scale: 2, storeTypePostfix: StoreTypePostfix.PrecisionAndScale); private readonly DecimalTypeMapping _money = new SqlServerDecimalTypeMapping("money"); diff --git a/src/EFCore.SqlServer/Storage/Internal/SqlServerUdtTypeMapping.cs b/src/EFCore.SqlServer/Storage/Internal/SqlServerUdtTypeMapping.cs index 4d8e3761e71..1631e39c356 100644 --- a/src/EFCore.SqlServer/Storage/Internal/SqlServerUdtTypeMapping.cs +++ b/src/EFCore.SqlServer/Storage/Internal/SqlServerUdtTypeMapping.cs @@ -48,7 +48,8 @@ public SqlServerUdtTypeMapping( : base( new RelationalTypeMappingParameters( new CoreTypeMappingParameters( - clrType, converter, comparer, keyComparer), storeType, storeTypePostfix, dbType, unicode, size, fixedLength, precision, scale)) + clrType, converter, comparer, keyComparer), storeType, storeTypePostfix, dbType, unicode, size, fixedLength, + precision, scale)) { LiteralGenerator = literalGenerator; diff --git a/src/EFCore.SqlServer/Update/Internal/ISqlServerUpdateSqlGenerator.cs b/src/EFCore.SqlServer/Update/Internal/ISqlServerUpdateSqlGenerator.cs index 04db029fe51..65f4ee6219d 100644 --- a/src/EFCore.SqlServer/Update/Internal/ISqlServerUpdateSqlGenerator.cs +++ b/src/EFCore.SqlServer/Update/Internal/ISqlServerUpdateSqlGenerator.cs @@ -17,9 +17,9 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Update.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface ISqlServerUpdateSqlGenerator : IUpdateSqlGenerator diff --git a/src/EFCore.SqlServer/Update/Internal/SqlServerModificationCommandBatch.cs b/src/EFCore.SqlServer/Update/Internal/SqlServerModificationCommandBatch.cs index 17a5a4e5c9e..8e1592f57ae 100644 --- a/src/EFCore.SqlServer/Update/Internal/SqlServerModificationCommandBatch.cs +++ b/src/EFCore.SqlServer/Update/Internal/SqlServerModificationCommandBatch.cs @@ -163,7 +163,8 @@ private string GetBulkInsertCommandText(int lastIndex) } var stringBuilder = new StringBuilder(); - var resultSetMapping = UpdateSqlGenerator.AppendBulkInsertOperation(stringBuilder, _bulkInsertCommands, lastIndex - _bulkInsertCommands.Count); + var resultSetMapping = UpdateSqlGenerator.AppendBulkInsertOperation( + stringBuilder, _bulkInsertCommands, lastIndex - _bulkInsertCommands.Count); for (var i = lastIndex - _bulkInsertCommands.Count; i < lastIndex; i++) { CommandResultSet[i] = resultSetMapping; diff --git a/src/EFCore.SqlServer/Update/Internal/SqlServerModificationCommandBatchFactory.cs b/src/EFCore.SqlServer/Update/Internal/SqlServerModificationCommandBatchFactory.cs index 3cf4a6576a0..6e127a8fde9 100644 --- a/src/EFCore.SqlServer/Update/Internal/SqlServerModificationCommandBatchFactory.cs +++ b/src/EFCore.SqlServer/Update/Internal/SqlServerModificationCommandBatchFactory.cs @@ -19,8 +19,8 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Update.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.SqlServer/Update/Internal/SqlServerUpdateSqlGenerator.cs b/src/EFCore.SqlServer/Update/Internal/SqlServerUpdateSqlGenerator.cs index 58775242b0d..f0c3a42630e 100644 --- a/src/EFCore.SqlServer/Update/Internal/SqlServerUpdateSqlGenerator.cs +++ b/src/EFCore.SqlServer/Update/Internal/SqlServerUpdateSqlGenerator.cs @@ -22,9 +22,9 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Update.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class SqlServerUpdateSqlGenerator : UpdateSqlGenerator, ISqlServerUpdateSqlGenerator @@ -99,7 +99,8 @@ public virtual ResultSetMapping AppendBulkInsertOperation( if (defaultValuesOnly) { - return AppendBulkInsertWithServerValuesOnly(commandStringBuilder, modificationCommands, commandPosition, nonIdentityOperations, keyOperations, readOperations); + return AppendBulkInsertWithServerValuesOnly( + commandStringBuilder, modificationCommands, commandPosition, nonIdentityOperations, keyOperations, readOperations); } if (modificationCommands[0].Entries.SelectMany(e => e.EntityType.GetAllBaseTypesInclusive()) @@ -116,14 +117,16 @@ public virtual ResultSetMapping AppendBulkInsertOperation( { foreach (var modification in modificationCommands) { - AppendInsertOperationWithServerKeys(commandStringBuilder, modification, keyOperations, readOperations, commandPosition++); + AppendInsertOperationWithServerKeys( + commandStringBuilder, modification, keyOperations, readOperations, commandPosition++); } } return ResultSetMapping.LastInResultSet; } - return AppendBulkInsertWithServerValues(commandStringBuilder, modificationCommands, commandPosition, writeOperations, keyOperations, readOperations); + return AppendBulkInsertWithServerValues( + commandStringBuilder, modificationCommands, commandPosition, writeOperations, keyOperations, readOperations); } private ResultSetMapping AppendBulkInsertWithoutServerValues( @@ -190,7 +193,9 @@ private ResultSetMapping AppendBulkInsertWithServerValues( FullPositionColumnName); commandStringBuilder.AppendLine(SqlGenerationHelper.StatementTerminator); - AppendSelectCommand(commandStringBuilder, readOperations, keyOperations, InsertedTableBaseName, commandPosition, name, schema, orderColumn: PositionColumnName); + AppendSelectCommand( + commandStringBuilder, readOperations, keyOperations, InsertedTableBaseName, commandPosition, name, schema, + orderColumn: PositionColumnName); return ResultSetMapping.NotLastInResultSet; } @@ -425,7 +430,8 @@ private ResultSetMapping AppendInsertOperationWithServerKeys( AppendValues(commandStringBuilder, writeOperations); commandStringBuilder.Append(SqlGenerationHelper.StatementTerminator); - return AppendSelectCommand(commandStringBuilder, readOperations, keyOperations, InsertedTableBaseName, commandPosition, name, schema); + return AppendSelectCommand( + commandStringBuilder, readOperations, keyOperations, InsertedTableBaseName, commandPosition, name, schema); } private ResultSetMapping AppendSelectCommand( @@ -484,7 +490,8 @@ private ResultSetMapping AppendSelectCommand( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected override ResultSetMapping AppendSelectAffectedCountCommand(StringBuilder commandStringBuilder, string name, string schema, int commandPosition) + protected override ResultSetMapping AppendSelectAffectedCountCommand( + StringBuilder commandStringBuilder, string name, string schema, int commandPosition) { commandStringBuilder .Append("SELECT @@ROWCOUNT") diff --git a/src/EFCore.SqlServer/ValueGeneration/Internal/ISqlServerValueGeneratorCache.cs b/src/EFCore.SqlServer/ValueGeneration/Internal/ISqlServerValueGeneratorCache.cs index 3b2cb6dd612..840870ba822 100644 --- a/src/EFCore.SqlServer/ValueGeneration/Internal/ISqlServerValueGeneratorCache.cs +++ b/src/EFCore.SqlServer/ValueGeneration/Internal/ISqlServerValueGeneratorCache.cs @@ -17,9 +17,9 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.ValueGeneration.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface ISqlServerValueGeneratorCache : IValueGeneratorCache diff --git a/src/EFCore.SqlServer/ValueGeneration/Internal/SqlServerSequenceValueGeneratorFactory.cs b/src/EFCore.SqlServer/ValueGeneration/Internal/SqlServerSequenceValueGeneratorFactory.cs index 708f1f1ead7..b2cdf7267e3 100644 --- a/src/EFCore.SqlServer/ValueGeneration/Internal/SqlServerSequenceValueGeneratorFactory.cs +++ b/src/EFCore.SqlServer/ValueGeneration/Internal/SqlServerSequenceValueGeneratorFactory.cs @@ -51,52 +51,62 @@ public virtual ValueGenerator Create( if (type == typeof(long)) { - return new SqlServerSequenceHiLoValueGenerator(rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); + return new SqlServerSequenceHiLoValueGenerator( + rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); } if (type == typeof(int)) { - return new SqlServerSequenceHiLoValueGenerator(rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); + return new SqlServerSequenceHiLoValueGenerator( + rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); } if (type == typeof(decimal)) { - return new SqlServerSequenceHiLoValueGenerator(rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); + return new SqlServerSequenceHiLoValueGenerator( + rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); } if (type == typeof(short)) { - return new SqlServerSequenceHiLoValueGenerator(rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); + return new SqlServerSequenceHiLoValueGenerator( + rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); } if (type == typeof(byte)) { - return new SqlServerSequenceHiLoValueGenerator(rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); + return new SqlServerSequenceHiLoValueGenerator( + rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); } if (type == typeof(char)) { - return new SqlServerSequenceHiLoValueGenerator(rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); + return new SqlServerSequenceHiLoValueGenerator( + rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); } if (type == typeof(ulong)) { - return new SqlServerSequenceHiLoValueGenerator(rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); + return new SqlServerSequenceHiLoValueGenerator( + rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); } if (type == typeof(uint)) { - return new SqlServerSequenceHiLoValueGenerator(rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); + return new SqlServerSequenceHiLoValueGenerator( + rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); } if (type == typeof(ushort)) { - return new SqlServerSequenceHiLoValueGenerator(rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); + return new SqlServerSequenceHiLoValueGenerator( + rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); } if (type == typeof(sbyte)) { - return new SqlServerSequenceHiLoValueGenerator(rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); + return new SqlServerSequenceHiLoValueGenerator( + rawSqlCommandBuilder, _sqlGenerator, generatorState, connection, commandLogger); } throw new ArgumentException( diff --git a/src/EFCore.SqlServer/ValueGeneration/Internal/SqlServerValueGeneratorCache.cs b/src/EFCore.SqlServer/ValueGeneration/Internal/SqlServerValueGeneratorCache.cs index 95a37a4f14f..397572e1dc8 100644 --- a/src/EFCore.SqlServer/ValueGeneration/Internal/SqlServerValueGeneratorCache.cs +++ b/src/EFCore.SqlServer/ValueGeneration/Internal/SqlServerValueGeneratorCache.cs @@ -19,9 +19,9 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.ValueGeneration.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class SqlServerValueGeneratorCache : ValueGeneratorCache, ISqlServerValueGeneratorCache diff --git a/src/EFCore.SqlServer/ValueGeneration/Internal/SqlServerValueGeneratorSelector.cs b/src/EFCore.SqlServer/ValueGeneration/Internal/SqlServerValueGeneratorSelector.cs index d9ebd3af1c8..bd2957ac3a2 100644 --- a/src/EFCore.SqlServer/ValueGeneration/Internal/SqlServerValueGeneratorSelector.cs +++ b/src/EFCore.SqlServer/ValueGeneration/Internal/SqlServerValueGeneratorSelector.cs @@ -21,8 +21,8 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.ValueGeneration.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Sqlite.Core/Diagnostics/Internal/SqliteLoggingDefinitions.cs b/src/EFCore.Sqlite.Core/Diagnostics/Internal/SqliteLoggingDefinitions.cs index 0cce89d52e0..df54c8c4c9c 100644 --- a/src/EFCore.Sqlite.Core/Diagnostics/Internal/SqliteLoggingDefinitions.cs +++ b/src/EFCore.Sqlite.Core/Diagnostics/Internal/SqliteLoggingDefinitions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.Diagnostics; diff --git a/src/EFCore.Sqlite.Core/Diagnostics/SqliteEventId.cs b/src/EFCore.Sqlite.Core/Diagnostics/SqliteEventId.cs index 5fd46e75614..090c12d7480 100644 --- a/src/EFCore.Sqlite.Core/Diagnostics/SqliteEventId.cs +++ b/src/EFCore.Sqlite.Core/Diagnostics/SqliteEventId.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Diagnostics; @@ -88,7 +88,8 @@ private enum Id /// A foreign key references a missing table. /// This event is in the category. /// - public static readonly EventId ForeignKeyReferencesMissingTableWarning = MakeScaffoldingId(Id.ForeignKeyReferencesMissingTableWarning); + public static readonly EventId ForeignKeyReferencesMissingTableWarning = + MakeScaffoldingId(Id.ForeignKeyReferencesMissingTableWarning); /// /// A table was found. @@ -106,7 +107,8 @@ private enum Id /// A column referenced by a foreign key constraint was not found. /// This event is in the category. /// - public static readonly EventId ForeignKeyPrincipalColumnMissingWarning = MakeScaffoldingId(Id.ForeignKeyPrincipalColumnMissingWarning); + public static readonly EventId ForeignKeyPrincipalColumnMissingWarning = + MakeScaffoldingId(Id.ForeignKeyPrincipalColumnMissingWarning); /// /// An index was found. diff --git a/src/EFCore.Sqlite.Core/Extensions/SqliteMigrationBuilderExtensions.cs b/src/EFCore.Sqlite.Core/Extensions/SqliteMigrationBuilderExtensions.cs index 71331e387bd..03fe10cd0df 100644 --- a/src/EFCore.Sqlite.Core/Extensions/SqliteMigrationBuilderExtensions.cs +++ b/src/EFCore.Sqlite.Core/Extensions/SqliteMigrationBuilderExtensions.cs @@ -19,10 +19,14 @@ public static class SqliteMigrationBuilderExtensions /// Returns true if the database provider currently in use is the SQLite provider. /// /// - /// The migrationBuilder from the parameters on or . + /// + /// The migrationBuilder from the parameters on or + /// . + /// /// True if SQLite is being used; false otherwise. public static bool IsSqlite([NotNull] this MigrationBuilder migrationBuilder) - => string.Equals(migrationBuilder.ActiveProvider, + => string.Equals( + migrationBuilder.ActiveProvider, typeof(SqliteOptionsExtension).GetTypeInfo().Assembly.GetName().Name, StringComparison.Ordinal); } diff --git a/src/EFCore.Sqlite.Core/Extensions/SqlitePropertyBuilderExtensions.cs b/src/EFCore.Sqlite.Core/Extensions/SqlitePropertyBuilderExtensions.cs index e3a7fe59cd1..888ee11c340 100644 --- a/src/EFCore.Sqlite.Core/Extensions/SqlitePropertyBuilderExtensions.cs +++ b/src/EFCore.Sqlite.Core/Extensions/SqlitePropertyBuilderExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Sqlite.Core/Extensions/SqlitePropertyExtensions.cs b/src/EFCore.Sqlite.Core/Extensions/SqlitePropertyExtensions.cs index 8920c241113..0d5f52c9bc3 100644 --- a/src/EFCore.Sqlite.Core/Extensions/SqlitePropertyExtensions.cs +++ b/src/EFCore.Sqlite.Core/Extensions/SqlitePropertyExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Sqlite.Core/Extensions/SqliteServiceCollectionExtensions.cs b/src/EFCore.Sqlite.Core/Extensions/SqliteServiceCollectionExtensions.cs index 9392fa1dd7e..b81ba55c461 100644 --- a/src/EFCore.Sqlite.Core/Extensions/SqliteServiceCollectionExtensions.cs +++ b/src/EFCore.Sqlite.Core/Extensions/SqliteServiceCollectionExtensions.cs @@ -37,7 +37,7 @@ public static class SqliteServiceCollectionExtensions /// Calling this method is no longer necessary when building most applications, including those that /// use dependency injection in ASP.NET or elsewhere. /// It is only needed when building the internal service provider for use with - /// the method. + /// the method. /// This is not recommend other than for some advanced scenarios. /// /// @@ -70,7 +70,6 @@ public static IServiceCollection AddEntityFrameworkSqlite([NotNull] this IServic .TryAdd() .TryAdd() .TryAdd() - .TryAddProviderSpecificServices( b => b.TryAddScoped()); diff --git a/src/EFCore.Sqlite.Core/Infrastructure/SpatialiteLoader.cs b/src/EFCore.Sqlite.Core/Infrastructure/SpatialiteLoader.cs index ed4a9693d0c..e5b922fc225 100644 --- a/src/EFCore.Sqlite.Core/Infrastructure/SpatialiteLoader.cs +++ b/src/EFCore.Sqlite.Core/Infrastructure/SpatialiteLoader.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -13,7 +13,6 @@ using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyModel; - using RuntimeEnvironment = Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment; namespace Microsoft.EntityFrameworkCore.Infrastructure @@ -63,6 +62,7 @@ public static bool TryLoad([NotNull] DbConnection connection) connection.Open(); opened = true; } + try { Load(connection); diff --git a/src/EFCore.Sqlite.Core/Internal/SqliteLoggerExtensions.cs b/src/EFCore.Sqlite.Core/Internal/SqliteLoggerExtensions.cs index bd7409a65ea..d466a46c66a 100644 --- a/src/EFCore.Sqlite.Core/Internal/SqliteLoggerExtensions.cs +++ b/src/EFCore.Sqlite.Core/Internal/SqliteLoggerExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Sqlite.Core/Internal/SqliteModelValidator.cs b/src/EFCore.Sqlite.Core/Internal/SqliteModelValidator.cs index 5147ad36aa9..1ac22a3d41e 100644 --- a/src/EFCore.Sqlite.Core/Internal/SqliteModelValidator.cs +++ b/src/EFCore.Sqlite.Core/Internal/SqliteModelValidator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq; @@ -18,9 +18,9 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class SqliteModelValidator : RelationalModelValidator @@ -58,7 +58,8 @@ public override void Validate(IModel model, IDiagnosticsLogger - protected virtual void ValidateNoSchemas([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void ValidateNoSchemas( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { foreach (var entityType in model.GetEntityTypes().Where(e => e.GetSchema() != null)) { @@ -72,7 +73,8 @@ protected virtual void ValidateNoSchemas([NotNull] IModel model, [NotNull] IDiag /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected virtual void ValidateNoSequences([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void ValidateNoSequences( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { foreach (var sequence in model.GetSequences()) { diff --git a/src/EFCore.Sqlite.Core/Metadata/Conventions/SqliteConventionSetBuilder.cs b/src/EFCore.Sqlite.Core/Metadata/Conventions/SqliteConventionSetBuilder.cs index 08f74c02feb..a813b55bc4a 100644 --- a/src/EFCore.Sqlite.Core/Metadata/Conventions/SqliteConventionSetBuilder.cs +++ b/src/EFCore.Sqlite.Core/Metadata/Conventions/SqliteConventionSetBuilder.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Sqlite.Core/Migrations/Internal/SqliteHistoryRepository.cs b/src/EFCore.Sqlite.Core/Migrations/Internal/SqliteHistoryRepository.cs index efb280acee7..1e462a18674 100644 --- a/src/EFCore.Sqlite.Core/Migrations/Internal/SqliteHistoryRepository.cs +++ b/src/EFCore.Sqlite.Core/Migrations/Internal/SqliteHistoryRepository.cs @@ -18,8 +18,8 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Migrations.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Sqlite.Core/Migrations/Internal/SqliteMigrationsAnnotationProvider.cs b/src/EFCore.Sqlite.Core/Migrations/Internal/SqliteMigrationsAnnotationProvider.cs index 8e7f724b438..f81dee7da9f 100644 --- a/src/EFCore.Sqlite.Core/Migrations/Internal/SqliteMigrationsAnnotationProvider.cs +++ b/src/EFCore.Sqlite.Core/Migrations/Internal/SqliteMigrationsAnnotationProvider.cs @@ -22,9 +22,9 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Migrations.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class SqliteMigrationsAnnotationProvider : MigrationsAnnotationProvider @@ -84,6 +84,6 @@ public override IEnumerable For(IProperty property) } private static bool HasConverter(IProperty property) - => property.FindTypeMapping()?.Converter != null; + => property.FindTypeMapping()?.Converter != null; } } diff --git a/src/EFCore.Sqlite.Core/Migrations/SqliteMigrationsSqlGenerator.cs b/src/EFCore.Sqlite.Core/Migrations/SqliteMigrationsSqlGenerator.cs index ec84d45732e..3c3d94d7c4f 100644 --- a/src/EFCore.Sqlite.Core/Migrations/SqliteMigrationsSqlGenerator.cs +++ b/src/EFCore.Sqlite.Core/Migrations/SqliteMigrationsSqlGenerator.cs @@ -23,8 +23,8 @@ namespace Microsoft.EntityFrameworkCore.Migrations /// SQLite-specific implementation of . /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -34,7 +34,7 @@ public class SqliteMigrationsSqlGenerator : MigrationsSqlGenerator private readonly IMigrationsAnnotationProvider _migrationsAnnotations; /// - /// Creates a new instance. + /// Creates a new instance. /// /// Parameter object containing dependencies for this service. /// Provider-specific Migrations annotations to use. @@ -238,12 +238,7 @@ protected override void Generate(RenameIndexOperation operation, IModel model, M SqliteStrings.InvalidMigrationOperation(operation.GetType().ShortDisplayName())); } - var dropOperation = new DropIndexOperation - { - Schema = operation.Schema, - Table = operation.Table, - Name = operation.Name - }; + var dropOperation = new DropIndexOperation { Schema = operation.Schema, Table = operation.Table, Name = operation.Name }; dropOperation.AddAnnotations(_migrationsAnnotations.ForRemove(index)); var createOperation = new CreateIndexOperation @@ -352,9 +347,9 @@ protected override void Generate( else { builder - .Append("CREATE TABLE ") - .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Name, operation.Schema)) - .AppendLine(" ("); + .Append("CREATE TABLE ") + .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Name, operation.Schema)) + .AppendLine(" ("); using (builder.Indent()) { @@ -480,7 +475,8 @@ protected override void ColumnDefinition( /// The target model which may be null if the operations exist without a model. /// The command builder to use to build the commands. /// Indicates whether or not to terminate the command after generating SQL for the operation. - protected override void Generate(AddForeignKeyOperation operation, IModel model, MigrationCommandListBuilder builder, bool terminate = true) + protected override void Generate( + AddForeignKeyOperation operation, IModel model, MigrationCommandListBuilder builder, bool terminate = true) => throw new NotSupportedException( SqliteStrings.InvalidMigrationOperation(operation.GetType().ShortDisplayName())); @@ -492,7 +488,8 @@ protected override void Generate(AddForeignKeyOperation operation, IModel model, /// The target model which may be null if the operations exist without a model. /// The command builder to use to build the commands. /// Indicates whether or not to terminate the command after generating SQL for the operation. - protected override void Generate(AddPrimaryKeyOperation operation, IModel model, MigrationCommandListBuilder builder, bool terminate = true) + protected override void Generate( + AddPrimaryKeyOperation operation, IModel model, MigrationCommandListBuilder builder, bool terminate = true) => throw new NotSupportedException( SqliteStrings.InvalidMigrationOperation(operation.GetType().ShortDisplayName())); @@ -526,7 +523,8 @@ protected override void Generate(CreateCheckConstraintOperation operation, IMode /// The target model which may be null if the operations exist without a model. /// The command builder to use to build the commands. /// Indicates whether or not to terminate the command after generating SQL for the operation. - protected override void Generate(DropColumnOperation operation, IModel model, MigrationCommandListBuilder builder, bool terminate = true) + protected override void Generate( + DropColumnOperation operation, IModel model, MigrationCommandListBuilder builder, bool terminate = true) => throw new NotSupportedException( SqliteStrings.InvalidMigrationOperation(operation.GetType().ShortDisplayName())); @@ -538,7 +536,8 @@ protected override void Generate(DropColumnOperation operation, IModel model, Mi /// The target model which may be null if the operations exist without a model. /// The command builder to use to build the commands. /// Indicates whether or not to terminate the command after generating SQL for the operation. - protected override void Generate(DropForeignKeyOperation operation, IModel model, MigrationCommandListBuilder builder, bool terminate = true) + protected override void Generate( + DropForeignKeyOperation operation, IModel model, MigrationCommandListBuilder builder, bool terminate = true) => throw new NotSupportedException( SqliteStrings.InvalidMigrationOperation(operation.GetType().ShortDisplayName())); @@ -550,7 +549,8 @@ protected override void Generate(DropForeignKeyOperation operation, IModel model /// The target model which may be null if the operations exist without a model. /// The command builder to use to build the commands. /// Indicates whether or not to terminate the command after generating SQL for the operation. - protected override void Generate(DropPrimaryKeyOperation operation, IModel model, MigrationCommandListBuilder builder, bool terminate = true) + protected override void Generate( + DropPrimaryKeyOperation operation, IModel model, MigrationCommandListBuilder builder, bool terminate = true) => throw new NotSupportedException( SqliteStrings.InvalidMigrationOperation(operation.GetType().ShortDisplayName())); diff --git a/src/EFCore.Sqlite.Core/Properties/AssemblyInfo.cs b/src/EFCore.Sqlite.Core/Properties/AssemblyInfo.cs index 60591f60bb3..7007abe7014 100644 --- a/src/EFCore.Sqlite.Core/Properties/AssemblyInfo.cs +++ b/src/EFCore.Sqlite.Core/Properties/AssemblyInfo.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.Design; diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteDateTimeAddTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteDateTimeAddTranslator.cs index b0cd3240a1f..43fbcf58336 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteDateTimeAddTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteDateTimeAddTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -26,6 +26,7 @@ private static readonly MethodInfo _addTicks { typeof(DateTime).GetRuntimeMethod(nameof(DateTime.AddMinutes), new[] { typeof(double) }), " minutes" }, { typeof(DateTime).GetRuntimeMethod(nameof(DateTime.AddSeconds), new[] { typeof(double) }), " seconds" } }; + private readonly ISqlExpressionFactory _sqlExpressionFactory; public SqliteDateTimeAddTranslator(ISqlExpressionFactory sqlExpressionFactory) @@ -78,7 +79,7 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method method.ReturnType, "%Y-%m-%d %H:%M:%f", instance, - new [] { modifier }), + new[] { modifier }), _sqlExpressionFactory.Constant("0") }, method.ReturnType), diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteDateTimeMemberTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteDateTimeMemberTranslator.cs index cecf77073e5..558ac39f8e7 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteDateTimeMemberTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteDateTimeMemberTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteExpression.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteExpression.cs index 9a3b6c9b3e4..28c2fda6d07 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteExpression.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -54,11 +54,7 @@ public static SqlFunctionExpression Strftime( return sqlExpressionFactory.Function( "strftime", - new[] - { - sqlExpressionFactory.Constant(format), - timestring - }.Concat(modifiers), + new[] { sqlExpressionFactory.Constant(format), timestring }.Concat(modifiers), returnType, typeMapping); } diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteMathTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteMathTranslator.cs index c8469592a41..34382f6a04c 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteMathTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteMathTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteMemberTranslatorProvider.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteMemberTranslatorProvider.cs index fd59fb9e924..9e734b45188 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteMemberTranslatorProvider.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteMemberTranslatorProvider.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.Query; @@ -15,8 +15,7 @@ public SqliteMemberTranslatorProvider(RelationalMemberTranslatorProviderDependen AddTranslators( new IMemberTranslator[] { - new SqliteDateTimeMemberTranslator(sqlExpressionFactory), - new SqliteStringLengthTranslator(sqlExpressionFactory) + new SqliteDateTimeMemberTranslator(sqlExpressionFactory), new SqliteStringLengthTranslator(sqlExpressionFactory) }); } } diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteMethodCallTranslatorProvider.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteMethodCallTranslatorProvider.cs index d1df98b017a..91e577e648b 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteMethodCallTranslatorProvider.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteMethodCallTranslatorProvider.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; @@ -18,7 +18,7 @@ public SqliteMethodCallTranslatorProvider([NotNull] RelationalMethodCallTranslat { new SqliteMathTranslator(sqlExpressionFactory), new SqliteDateTimeAddTranslator(sqlExpressionFactory), - new SqliteStringMethodTranslator(sqlExpressionFactory), + new SqliteStringMethodTranslator(sqlExpressionFactory) }); } } diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteQuerySqlGenerator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteQuerySqlGenerator.cs index 374234907d6..f12b6881dd3 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteQuerySqlGenerator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteQuerySqlGenerator.cs @@ -1,11 +1,9 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; -using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal @@ -19,7 +17,7 @@ public SqliteQuerySqlGenerator(QuerySqlGeneratorDependencies dependencies) protected override string GenerateOperator(SqlBinaryExpression binaryExpression) => binaryExpression.OperatorType == ExpressionType.Add - && binaryExpression.Type == typeof(string) + && binaryExpression.Type == typeof(string) ? " || " : base.GenerateOperator(binaryExpression); @@ -33,7 +31,8 @@ protected override void GenerateLimitOffset(SelectExpression selectExpression) Sql.AppendLine() .Append("LIMIT "); - Visit(selectExpression.Limit + Visit( + selectExpression.Limit ?? new SqlConstantExpression(Expression.Constant(-1), selectExpression.Offset.TypeMapping)); if (selectExpression.Offset != null) diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteQuerySqlGeneratorFactory.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteQuerySqlGeneratorFactory.cs index a9ad0b36015..65111844334 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteQuerySqlGeneratorFactory.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteQuerySqlGeneratorFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.Query; diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteQueryableMethodTranslatingExpressionVisitor.cs index aa551713738..42266c77a06 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteQueryableMethodTranslatingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -31,7 +31,8 @@ protected SqliteQueryableMethodTranslatingExpressionVisitor( protected override QueryableMethodTranslatingExpressionVisitor CreateSubqueryVisitor() => new SqliteQueryableMethodTranslatingExpressionVisitor(this); - protected override ShapedQueryExpression TranslateOrderBy(ShapedQueryExpression source, LambdaExpression keySelector, bool ascending) + protected override ShapedQueryExpression TranslateOrderBy( + ShapedQueryExpression source, LambdaExpression keySelector, bool ascending) { var translation = base.TranslateOrderBy(source, keySelector, ascending); var orderingExpression = ((SelectExpression)translation.QueryExpression).Orderings.Last(); @@ -66,10 +67,8 @@ protected override ShapedQueryExpression TranslateThenBy(ShapedQueryExpression s } private static Type GetProviderType(SqlExpression expression) - => SharedTypeExtensions.UnwrapNullableType( - expression.TypeMapping?.Converter?.ProviderClrType - ?? expression.TypeMapping?.ClrType - ?? expression.Type); - + => (expression.TypeMapping?.Converter?.ProviderClrType + ?? expression.TypeMapping?.ClrType + ?? expression.Type).UnwrapNullableType(); } } diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteQueryableMethodTranslatingExpressionVisitorFactory.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteQueryableMethodTranslatingExpressionVisitorFactory.cs index e7deeedbf47..8d15281039a 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteQueryableMethodTranslatingExpressionVisitorFactory.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteQueryableMethodTranslatingExpressionVisitorFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.Metadata; diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteSqlTranslatingExpressionVisitor.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteSqlTranslatingExpressionVisitor.cs index 6eda10d06e5..caf8792ae58 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteSqlTranslatingExpressionVisitor.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteSqlTranslatingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -96,7 +96,6 @@ protected override Expression VisitUnary(UnaryExpression unaryExpression) if (visitedExpression is SqlUnaryExpression sqlUnary && sqlUnary.OperatorType == ExpressionType.Negate) { - var operandType = GetProviderType(sqlUnary.Operand); if (operandType == typeof(decimal) || operandType == typeof(TimeSpan)) @@ -118,9 +117,9 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression) } return visitedExpression is SqlBinaryExpression sqlBinary - && _restrictedBinaryExpressions.TryGetValue(sqlBinary.OperatorType, out var restrictedTypes) - && (restrictedTypes.Contains(GetProviderType(sqlBinary.Left)) - || restrictedTypes.Contains(GetProviderType(sqlBinary.Right))) + && _restrictedBinaryExpressions.TryGetValue(sqlBinary.OperatorType, out var restrictedTypes) + && (restrictedTypes.Contains(GetProviderType(sqlBinary.Left)) + || restrictedTypes.Contains(GetProviderType(sqlBinary.Right))) ? null : visitedExpression; } @@ -180,8 +179,8 @@ public override SqlExpression TranslateSum(Expression expression) private static Type GetProviderType(SqlExpression expression) { return (expression.TypeMapping?.Converter?.ProviderClrType - ?? expression.TypeMapping?.ClrType - ?? expression.Type).UnwrapNullableType(); + ?? expression.TypeMapping?.ClrType + ?? expression.Type).UnwrapNullableType(); } } } diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteSqlTranslatingExpressionVisitorFactory.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteSqlTranslatingExpressionVisitorFactory.cs index 86a1330a5be..c16c8763000 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteSqlTranslatingExpressionVisitorFactory.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteSqlTranslatingExpressionVisitorFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteStringLengthTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteStringLengthTranslator.cs index 8d41ef74e4a..c6253e36fa9 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteStringLengthTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteStringLengthTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -20,7 +20,7 @@ public SqliteStringLengthTranslator(ISqlExpressionFactory sqlExpressionFactory) public virtual SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType) { return instance?.Type == typeof(string) - && member.Name == nameof(string.Length) + && member.Name == nameof(string.Length) ? _sqlExpressionFactory.Function("length", new[] { instance }, returnType) : null; } diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteStringMethodTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteStringMethodTranslator.cs index 9b5464cfae6..8cea52f6310 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteStringMethodTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteStringMethodTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -15,44 +15,57 @@ public class SqliteStringMethodTranslator : IMethodCallTranslator { private static readonly MethodInfo _indexOfMethodInfo = typeof(string).GetRuntimeMethod(nameof(string.IndexOf), new[] { typeof(string) }); + private static readonly MethodInfo _replaceMethodInfo = typeof(string).GetRuntimeMethod(nameof(string.Replace), new[] { typeof(string), typeof(string) }); + private static readonly MethodInfo _toLowerMethodInfo = typeof(string).GetRuntimeMethod(nameof(string.ToLower), Array.Empty()); + private static readonly MethodInfo _toUpperMethodInfo = typeof(string).GetRuntimeMethod(nameof(string.ToUpper), Array.Empty()); + private static readonly MethodInfo _substringMethodInfo = typeof(string).GetRuntimeMethod(nameof(string.Substring), new[] { typeof(int), typeof(int) }); + private static readonly MethodInfo _isNullOrWhiteSpaceMethodInfo = typeof(string).GetRuntimeMethod(nameof(string.IsNullOrWhiteSpace), new[] { typeof(string) }); - // Method defined in netcoreapp2.0 only private static readonly MethodInfo _trimStartMethodInfoWithoutArgs = typeof(string).GetRuntimeMethod(nameof(string.TrimStart), Array.Empty()); + private static readonly MethodInfo _trimStartMethodInfoWithCharArg = typeof(string).GetRuntimeMethod(nameof(string.TrimStart), new[] { typeof(char) }); + private static readonly MethodInfo _trimEndMethodInfoWithoutArgs = typeof(string).GetRuntimeMethod(nameof(string.TrimEnd), Array.Empty()); + private static readonly MethodInfo _trimEndMethodInfoWithCharArg = typeof(string).GetRuntimeMethod(nameof(string.TrimEnd), new[] { typeof(char) }); + private static readonly MethodInfo _trimMethodInfoWithoutArgs = typeof(string).GetRuntimeMethod(nameof(string.Trim), Array.Empty()); + private static readonly MethodInfo _trimMethodInfoWithCharArg = typeof(string).GetRuntimeMethod(nameof(string.Trim), new[] { typeof(char) }); // Method defined in netstandard2.0 private static readonly MethodInfo _trimStartMethodInfoWithCharArrayArg = typeof(string).GetRuntimeMethod(nameof(string.TrimStart), new[] { typeof(char[]) }); + private static readonly MethodInfo _trimEndMethodInfoWithCharArrayArg = typeof(string).GetRuntimeMethod(nameof(string.TrimEnd), new[] { typeof(char[]) }); + private static readonly MethodInfo _trimMethodInfoWithCharArrayArg = typeof(string).GetRuntimeMethod(nameof(string.Trim), new[] { typeof(char[]) }); private static readonly MethodInfo _startsWithMethodInfo = typeof(string).GetRuntimeMethod(nameof(string.StartsWith), new[] { typeof(string) }); + private static readonly MethodInfo _containsMethodInfo = typeof(string).GetRuntimeMethod(nameof(string.Contains), new[] { typeof(string) }); + private static readonly MethodInfo _endsWithMethodInfo = typeof(string).GetRuntimeMethod(nameof(string.EndsWith), new[] { typeof(string) }); @@ -115,12 +128,7 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method { return _sqlExpressionFactory.Function( "substr", - new[] - { - instance, - _sqlExpressionFactory.Add(arguments[0], _sqlExpressionFactory.Constant(1)), - arguments[1], - }, + new[] { instance, _sqlExpressionFactory.Add(arguments[0], _sqlExpressionFactory.Constant(1)), arguments[1] }, method.ReturnType, instance.TypeMapping); } @@ -206,10 +214,12 @@ private SqlExpression TranslateStartsEndsWith(SqlExpression instance, SqlExpress { return _sqlExpressionFactory.Like(instance, _sqlExpressionFactory.Constant(null, stringTypeMapping)); } + if (constantString.Length == 0) { return _sqlExpressionFactory.Constant(true); } + return constantString.Any(c => IsLikeWildChar(c)) ? _sqlExpressionFactory.Like( instance, @@ -217,11 +227,11 @@ private SqlExpression TranslateStartsEndsWith(SqlExpression instance, SqlExpress startsWith ? EscapeLikePattern(constantString) + '%' : '%' + EscapeLikePattern(constantString)), - _sqlExpressionFactory.Constant(LikeEscapeChar.ToString())) // SQL Server has no char mapping, avoid value conversion warning) + _sqlExpressionFactory.Constant( + LikeEscapeChar.ToString())) // SQL Server has no char mapping, avoid value conversion warning) : _sqlExpressionFactory.Like( instance, - _sqlExpressionFactory.Constant(startsWith ? constantString + '%' : '%' + constantString), - null); + _sqlExpressionFactory.Constant(startsWith ? constantString + '%' : '%' + constantString)); } // The pattern is non-constant, we use LEFT or RIGHT to extract substring and compare. @@ -239,7 +249,8 @@ private SqlExpression TranslateStartsEndsWith(SqlExpression instance, SqlExpress _sqlExpressionFactory.Equal( _sqlExpressionFactory.Function( "substr", - new[] { + new[] + { instance, _sqlExpressionFactory.Constant(1), _sqlExpressionFactory.Function("length", new[] { pattern }, typeof(int)) @@ -256,7 +267,8 @@ private SqlExpression TranslateStartsEndsWith(SqlExpression instance, SqlExpress _sqlExpressionFactory.Equal( _sqlExpressionFactory.Function( "substr", - new[] { + new[] + { instance, _sqlExpressionFactory.Negate( _sqlExpressionFactory.Function("length", new[] { pattern }, typeof(int))) @@ -278,12 +290,15 @@ private string EscapeLikePattern(string pattern) for (var i = 0; i < pattern.Length; i++) { var c = pattern[i]; - if (IsLikeWildChar(c) || c == LikeEscapeChar) + if (IsLikeWildChar(c) + || c == LikeEscapeChar) { builder.Append(LikeEscapeChar); } + builder.Append(c); } + return builder.ToString(); } diff --git a/src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteCodeGenerator.cs b/src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteCodeGenerator.cs index 4eceae28931..58ac03204c0 100644 --- a/src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteCodeGenerator.cs +++ b/src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteCodeGenerator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteDatabaseModelFactory.cs b/src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteDatabaseModelFactory.cs index f673b3e0e31..b548c33900a 100644 --- a/src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteDatabaseModelFactory.cs +++ b/src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteDatabaseModelFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -268,10 +268,7 @@ private IEnumerable GetColumns(DbConnection connection, string t yield return new DatabaseColumn { - Name = columnName, - StoreType = dataType, - IsNullable = !notNull, - DefaultValueSql = defaultValue + Name = columnName, StoreType = dataType, IsNullable = !notNull, DefaultValueSql = defaultValue }; } } @@ -387,13 +384,7 @@ private static DatabasePrimaryKey GetRowidPrimaryKey( Debug.Assert(!reader.Read(), "Unexpected composite primary key."); - return new DatabasePrimaryKey - { - Columns = - { - column - } - }; + return new DatabasePrimaryKey { Columns = { column } }; } } } @@ -449,7 +440,8 @@ private IEnumerable GetUniqueConstraints( { var columnName = reader2.GetString(0); var column = columns.FirstOrDefault(c => c.Name == columnName) - ?? columns.FirstOrDefault(c => c.Name.Equals(columnName, StringComparison.OrdinalIgnoreCase)); + ?? columns.FirstOrDefault( + c => c.Name.Equals(columnName, StringComparison.OrdinalIgnoreCase)); Debug.Assert(column != null, "column is null."); uniqueConstraint.Columns.Add(column); @@ -486,11 +478,7 @@ private IEnumerable GetIndexes( { while (reader1.Read()) { - var index = new DatabaseIndex - { - Name = reader1.GetString(0), - IsUnique = reader1.GetBoolean(1) - }; + var index = new DatabaseIndex { Name = reader1.GetString(0), IsUnique = reader1.GetBoolean(1) }; _logger.IndexFound(index.Name, table, index.IsUnique); @@ -552,7 +540,8 @@ private IEnumerable GetForeignKeys(DbConnection connection, var foreignKey = new DatabaseForeignKey { PrincipalTable = tables.FirstOrDefault(t => t.Name == principalTableName) - ?? tables.FirstOrDefault(t => t.Name.Equals(principalTableName, StringComparison.OrdinalIgnoreCase)), + ?? tables.FirstOrDefault( + t => t.Name.Equals(principalTableName, StringComparison.OrdinalIgnoreCase)), OnDelete = ConvertToReferentialAction(onDelete) }; @@ -591,12 +580,15 @@ private IEnumerable GetForeignKeys(DbConnection connection, { var columnName = reader2.GetString(0); var column = table.Columns.FirstOrDefault(c => c.Name == columnName) - ?? table.Columns.FirstOrDefault(c => c.Name.Equals(columnName, StringComparison.OrdinalIgnoreCase)); + ?? table.Columns.FirstOrDefault( + c => c.Name.Equals(columnName, StringComparison.OrdinalIgnoreCase)); Debug.Assert(column != null, "column is null."); var principalColumnName = reader2.GetString(1); - var principalColumn = foreignKey.PrincipalTable.Columns.FirstOrDefault(c => c.Name == principalColumnName) - ?? foreignKey.PrincipalTable.Columns.FirstOrDefault(c => c.Name.Equals(principalColumnName, StringComparison.OrdinalIgnoreCase)); + var principalColumn = + foreignKey.PrincipalTable.Columns.FirstOrDefault(c => c.Name == principalColumnName) + ?? foreignKey.PrincipalTable.Columns.FirstOrDefault( + c => c.Name.Equals(principalColumnName, StringComparison.OrdinalIgnoreCase)); if (principalColumn == null) { invalid = true; diff --git a/src/EFCore.Sqlite.Core/Storage/Internal/ISqliteRelationalConnection.cs b/src/EFCore.Sqlite.Core/Storage/Internal/ISqliteRelationalConnection.cs index 547f79d3fc9..41ee2263665 100644 --- a/src/EFCore.Sqlite.Core/Storage/Internal/ISqliteRelationalConnection.cs +++ b/src/EFCore.Sqlite.Core/Storage/Internal/ISqliteRelationalConnection.cs @@ -14,8 +14,8 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Sqlite.Core/Storage/Internal/SqliteDatabaseCreator.cs b/src/EFCore.Sqlite.Core/Storage/Internal/SqliteDatabaseCreator.cs index 1ffcd9ddc94..d913c723d2a 100644 --- a/src/EFCore.Sqlite.Core/Storage/Internal/SqliteDatabaseCreator.cs +++ b/src/EFCore.Sqlite.Core/Storage/Internal/SqliteDatabaseCreator.cs @@ -17,8 +17,8 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Sqlite.Core/Storage/Internal/SqliteDecimalTypeMapping.cs b/src/EFCore.Sqlite.Core/Storage/Internal/SqliteDecimalTypeMapping.cs index 90c730619b8..365615f0e53 100644 --- a/src/EFCore.Sqlite.Core/Storage/Internal/SqliteDecimalTypeMapping.cs +++ b/src/EFCore.Sqlite.Core/Storage/Internal/SqliteDecimalTypeMapping.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Data; diff --git a/src/EFCore.Sqlite.Core/Storage/Internal/SqliteRelationalConnection.cs b/src/EFCore.Sqlite.Core/Storage/Internal/SqliteRelationalConnection.cs index a9e7a034100..6a5182c7ac1 100644 --- a/src/EFCore.Sqlite.Core/Storage/Internal/SqliteRelationalConnection.cs +++ b/src/EFCore.Sqlite.Core/Storage/Internal/SqliteRelationalConnection.cs @@ -21,8 +21,8 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -97,10 +97,7 @@ protected override DbConnection CreateDbConnection() /// public virtual ISqliteRelationalConnection CreateReadOnlyConnection() { - var connectionStringBuilder = new SqliteConnectionStringBuilder(ConnectionString) - { - Mode = SqliteOpenMode.ReadOnly - }; + var connectionStringBuilder = new SqliteConnectionStringBuilder(ConnectionString) { Mode = SqliteOpenMode.ReadOnly }; var contextOptions = new DbContextOptionsBuilder().UseSqlite(connectionStringBuilder.ToString()).Options; diff --git a/src/EFCore.Sqlite.Core/Storage/Internal/SqliteSqlGenerationHelper.cs b/src/EFCore.Sqlite.Core/Storage/Internal/SqliteSqlGenerationHelper.cs index 958e4f24cae..75119cb4ac2 100644 --- a/src/EFCore.Sqlite.Core/Storage/Internal/SqliteSqlGenerationHelper.cs +++ b/src/EFCore.Sqlite.Core/Storage/Internal/SqliteSqlGenerationHelper.cs @@ -16,9 +16,9 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class SqliteSqlGenerationHelper : RelationalSqlGenerationHelper diff --git a/src/EFCore.Sqlite.Core/Storage/Internal/SqliteTypeMappingSource.cs b/src/EFCore.Sqlite.Core/Storage/Internal/SqliteTypeMappingSource.cs index beacdd12e90..a67d9535474 100644 --- a/src/EFCore.Sqlite.Core/Storage/Internal/SqliteTypeMappingSource.cs +++ b/src/EFCore.Sqlite.Core/Storage/Internal/SqliteTypeMappingSource.cs @@ -18,9 +18,9 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class SqliteTypeMappingSource : RelationalTypeMappingSource @@ -75,10 +75,7 @@ private readonly Dictionary _clrTypeMappings private readonly Dictionary _storeTypeMappings = new Dictionary(StringComparer.OrdinalIgnoreCase) { - { IntegerTypeName, _integer }, - { RealTypeName, _real }, - { BlobTypeName, _blob }, - { TextTypeName, _text } + { IntegerTypeName, _integer }, { RealTypeName, _real }, { BlobTypeName, _blob }, { TextTypeName, _text } }; /// diff --git a/src/EFCore.Sqlite.Core/Storage/Internal/SqliteULongTypeMapping.cs b/src/EFCore.Sqlite.Core/Storage/Internal/SqliteULongTypeMapping.cs index c11bdde5071..77f89713ba9 100644 --- a/src/EFCore.Sqlite.Core/Storage/Internal/SqliteULongTypeMapping.cs +++ b/src/EFCore.Sqlite.Core/Storage/Internal/SqliteULongTypeMapping.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Data; diff --git a/src/EFCore.Sqlite.Core/Update/Internal/SqliteModificationCommandBatchFactory.cs b/src/EFCore.Sqlite.Core/Update/Internal/SqliteModificationCommandBatchFactory.cs index 1b01e5aaa16..3ad1ed5b84c 100644 --- a/src/EFCore.Sqlite.Core/Update/Internal/SqliteModificationCommandBatchFactory.cs +++ b/src/EFCore.Sqlite.Core/Update/Internal/SqliteModificationCommandBatchFactory.cs @@ -16,8 +16,8 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Update.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore.Sqlite.Core/Update/Internal/SqliteUpdateSqlGenerator.cs b/src/EFCore.Sqlite.Core/Update/Internal/SqliteUpdateSqlGenerator.cs index 274d20c8d83..e7b6f38e271 100644 --- a/src/EFCore.Sqlite.Core/Update/Internal/SqliteUpdateSqlGenerator.cs +++ b/src/EFCore.Sqlite.Core/Update/Internal/SqliteUpdateSqlGenerator.cs @@ -19,9 +19,9 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Update.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class SqliteUpdateSqlGenerator : UpdateSqlGenerator @@ -59,7 +59,8 @@ protected override void AppendIdentityWhereCondition(StringBuilder commandString /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected override ResultSetMapping AppendSelectAffectedCountCommand(StringBuilder commandStringBuilder, string name, string schema, int commandPosition) + protected override ResultSetMapping AppendSelectAffectedCountCommand( + StringBuilder commandStringBuilder, string name, string schema, int commandPosition) { Check.NotNull(commandStringBuilder, nameof(commandStringBuilder)); Check.NotEmpty(name, nameof(name)); diff --git a/src/EFCore.Sqlite.NTS/Design/Internal/SqliteNetTopologySuiteDesignTimeServices.cs b/src/EFCore.Sqlite.NTS/Design/Internal/SqliteNetTopologySuiteDesignTimeServices.cs index 48f8123d179..de1e092bb76 100644 --- a/src/EFCore.Sqlite.NTS/Design/Internal/SqliteNetTopologySuiteDesignTimeServices.cs +++ b/src/EFCore.Sqlite.NTS/Design/Internal/SqliteNetTopologySuiteDesignTimeServices.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.Design; diff --git a/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuiteDbContextOptionsBuilderExtensions.cs b/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuiteDbContextOptionsBuilderExtensions.cs index 4bf5201a72a..04f0c0602dd 100644 --- a/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuiteDbContextOptionsBuilderExtensions.cs +++ b/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuiteDbContextOptionsBuilderExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuitePropertyBuilderExtensions.cs b/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuitePropertyBuilderExtensions.cs index 4f58571433d..6de4acf6cee 100644 --- a/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuitePropertyBuilderExtensions.cs +++ b/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuitePropertyBuilderExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuiteServiceCollectionExtensions.cs b/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuiteServiceCollectionExtensions.cs index 25353c90531..c10f6698ff1 100644 --- a/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuiteServiceCollectionExtensions.cs +++ b/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuiteServiceCollectionExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore.Sqlite.NTS/Infrastructure/Internal/SqliteNetTopologySuiteOptionsExtension.cs b/src/EFCore.Sqlite.NTS/Infrastructure/Internal/SqliteNetTopologySuiteOptionsExtension.cs index fe4aa7d80bf..ff4590417dd 100644 --- a/src/EFCore.Sqlite.NTS/Infrastructure/Internal/SqliteNetTopologySuiteOptionsExtension.cs +++ b/src/EFCore.Sqlite.NTS/Infrastructure/Internal/SqliteNetTopologySuiteOptionsExtension.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMemberTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMemberTranslator.cs index 84483db0c52..118d816108b 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMemberTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMemberTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMethodTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMethodTranslator.cs index 73f6cb7e8ee..48986038292 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMethodTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMethodTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; @@ -25,7 +25,8 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method { return _sqlExpressionFactory.Function( "GeometryN", - new SqlExpression[] { + new[] + { instance, _sqlExpressionFactory.Add( arguments[0], diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMemberTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMemberTranslator.cs index 21a28872170..bc30675a485 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMemberTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMemberTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -69,10 +69,7 @@ public virtual SqlExpression Translate(SqlExpression instance, MemberInfo member { _sqlExpressionFactory.Function( "GeometryType", - new [] - { - instance, - }, + new[] { instance }, returnType), _sqlExpressionFactory.Constant(" ZM") }, @@ -81,9 +78,11 @@ public virtual SqlExpression Translate(SqlExpression instance, MemberInfo member new CaseWhenClause(_sqlExpressionFactory.Constant("LINESTRING"), _sqlExpressionFactory.Constant("LineString")), new CaseWhenClause(_sqlExpressionFactory.Constant("POLYGON"), _sqlExpressionFactory.Constant("Polygon")), new CaseWhenClause(_sqlExpressionFactory.Constant("MULTIPOINT"), _sqlExpressionFactory.Constant("MultiPoint")), - new CaseWhenClause(_sqlExpressionFactory.Constant("MULTILINESTRING"), _sqlExpressionFactory.Constant("MultiLineString")), + new CaseWhenClause( + _sqlExpressionFactory.Constant("MULTILINESTRING"), _sqlExpressionFactory.Constant("MultiLineString")), new CaseWhenClause(_sqlExpressionFactory.Constant("MULTIPOLYGON"), _sqlExpressionFactory.Constant("MultiPolygon")), - new CaseWhenClause(_sqlExpressionFactory.Constant("GEOMETRYCOLLECTION"), _sqlExpressionFactory.Constant("GeometryCollection"))); + new CaseWhenClause( + _sqlExpressionFactory.Constant("GEOMETRYCOLLECTION"), _sqlExpressionFactory.Constant("GeometryCollection"))); } if (Equals(member, _ogcGeometryType)) @@ -95,21 +94,24 @@ public virtual SqlExpression Translate(SqlExpression instance, MemberInfo member { _sqlExpressionFactory.Function( "GeometryType", - new [] - { - instance, - }, + new[] { instance }, typeof(string)), _sqlExpressionFactory.Constant(" ZM") }, typeof(string)), new CaseWhenClause(_sqlExpressionFactory.Constant("POINT"), _sqlExpressionFactory.Constant(OgcGeometryType.Point)), - new CaseWhenClause(_sqlExpressionFactory.Constant("LINESTRING"), _sqlExpressionFactory.Constant(OgcGeometryType.LineString)), + new CaseWhenClause( + _sqlExpressionFactory.Constant("LINESTRING"), _sqlExpressionFactory.Constant(OgcGeometryType.LineString)), new CaseWhenClause(_sqlExpressionFactory.Constant("POLYGON"), _sqlExpressionFactory.Constant(OgcGeometryType.Polygon)), - new CaseWhenClause(_sqlExpressionFactory.Constant("MULTIPOINT"), _sqlExpressionFactory.Constant(OgcGeometryType.MultiPoint)), - new CaseWhenClause(_sqlExpressionFactory.Constant("MULTILINESTRING"), _sqlExpressionFactory.Constant(OgcGeometryType.MultiLineString)), - new CaseWhenClause(_sqlExpressionFactory.Constant("MULTIPOLYGON"), _sqlExpressionFactory.Constant(OgcGeometryType.MultiPolygon)), - new CaseWhenClause(_sqlExpressionFactory.Constant("GEOMETRYCOLLECTION"), _sqlExpressionFactory.Constant(OgcGeometryType.GeometryCollection))); + new CaseWhenClause( + _sqlExpressionFactory.Constant("MULTIPOINT"), _sqlExpressionFactory.Constant(OgcGeometryType.MultiPoint)), + new CaseWhenClause( + _sqlExpressionFactory.Constant("MULTILINESTRING"), _sqlExpressionFactory.Constant(OgcGeometryType.MultiLineString)), + new CaseWhenClause( + _sqlExpressionFactory.Constant("MULTIPOLYGON"), _sqlExpressionFactory.Constant(OgcGeometryType.MultiPolygon)), + new CaseWhenClause( + _sqlExpressionFactory.Constant("GEOMETRYCOLLECTION"), + _sqlExpressionFactory.Constant(OgcGeometryType.GeometryCollection))); } return null; diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMethodTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMethodTranslator.cs index 2feb510e523..f2116ec5550 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMethodTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMethodTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -42,8 +42,11 @@ public class SqliteGeometryMethodTranslator : IMethodCallTranslator { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Within), new[] { typeof(Geometry) }), "Within" } }; - private static readonly MethodInfo _getGeometryN = typeof(Geometry).GetRuntimeMethod(nameof(Geometry.GetGeometryN), new[] { typeof(int) }); - private static readonly MethodInfo _isWithinDistance = typeof(Geometry).GetRuntimeMethod(nameof(Geometry.IsWithinDistance), new[] { typeof(Geometry), typeof(double) }); + private static readonly MethodInfo _getGeometryN = typeof(Geometry).GetRuntimeMethod( + nameof(Geometry.GetGeometryN), new[] { typeof(int) }); + + private static readonly MethodInfo _isWithinDistance = typeof(Geometry).GetRuntimeMethod( + nameof(Geometry.IsWithinDistance), new[] { typeof(Geometry), typeof(double) }); private readonly ISqlExpressionFactory _sqlExpressionFactory; @@ -64,10 +67,7 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method if (method.ReturnType == typeof(bool)) { translation = _sqlExpressionFactory.Case( - new[] - { - new CaseWhenClause(_sqlExpressionFactory.IsNotNull(instance), translation) - }, + new[] { new CaseWhenClause(_sqlExpressionFactory.IsNotNull(instance), translation) }, null); } @@ -78,7 +78,8 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method { return _sqlExpressionFactory.Function( "GeometryN", - new[] { + new[] + { instance, _sqlExpressionFactory.Add( arguments[0], diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMemberTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMemberTranslator.cs index c2508f2359a..5b4075aec5c 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMemberTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMemberTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMethodTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMethodTranslator.cs index c9ab74e0e7f..331d6fcc5da 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMethodTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMethodTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; @@ -13,6 +13,7 @@ public class SqliteLineStringMethodTranslator : IMethodCallTranslator { private static readonly MethodInfo _getPointN = typeof(LineString).GetRuntimeMethod(nameof(LineString.GetPointN), new[] { typeof(int) }); + private readonly ISqlExpressionFactory _sqlExpressionFactory; public SqliteLineStringMethodTranslator(ISqlExpressionFactory sqlExpressionFactory) @@ -26,7 +27,8 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method { return _sqlExpressionFactory.Function( "PointN", - new SqlExpression[] { + new[] + { instance, _sqlExpressionFactory.Add( arguments[0], diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteMultiLineStringMemberTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteMultiLineStringMemberTranslator.cs index b312922bd2b..cd956f5a69d 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteMultiLineStringMemberTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteMultiLineStringMemberTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -24,7 +24,8 @@ public virtual SqlExpression Translate(SqlExpression instance, MemberInfo member if (Equals(member, _isClosed)) { return _sqlExpressionFactory.Case( - new[] { + new[] + { new CaseWhenClause( _sqlExpressionFactory.IsNotNull(instance), _sqlExpressionFactory.Function( diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteNetTopologySuiteMemberTranslatorPlugin.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteNetTopologySuiteMemberTranslatorPlugin.cs index 0f70a8deabd..ddee3692b13 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteNetTopologySuiteMemberTranslatorPlugin.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteNetTopologySuiteMemberTranslatorPlugin.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; @@ -15,9 +15,9 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class SqliteNetTopologySuiteMemberTranslatorPlugin : IMemberTranslatorPlugin @@ -36,7 +36,6 @@ public SqliteNetTopologySuiteMemberTranslatorPlugin( }; } - /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteNetTopologySuiteMethodCallTranslatorPlugin.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteNetTopologySuiteMethodCallTranslatorPlugin.cs index 0937c85dbba..5b6c35e94d8 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteNetTopologySuiteMethodCallTranslatorPlugin.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteNetTopologySuiteMethodCallTranslatorPlugin.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; @@ -15,10 +15,10 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is and multiple registrations - /// are allowed. This means a single instance of each service is used by many + /// The service lifetime is and multiple registrations + /// are allowed. This means a single instance of each service is used by many /// instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public class SqliteNetTopologySuiteMethodCallTranslatorPlugin : IMethodCallTranslatorPlugin @@ -34,7 +34,6 @@ public SqliteNetTopologySuiteMethodCallTranslatorPlugin(ISqlExpressionFactory sq }; } - /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePointMemberTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePointMemberTranslator.cs index 9f3fde801fc..b49023da1a6 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePointMemberTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePointMemberTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -19,6 +19,7 @@ public class SqlitePointMemberTranslator : IMemberTranslator { typeof(Point).GetRuntimeProperty(nameof(Point.Y)), "Y" }, { typeof(Point).GetRuntimeProperty(nameof(Point.Z)), "Z" } }; + private readonly ISqlExpressionFactory _sqlExpressionFactory; public SqlitePointMemberTranslator(ISqlExpressionFactory sqlExpressionFactory) diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMemberTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMemberTranslator.cs index 0c712257629..9246f3cb137 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMemberTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMemberTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -18,6 +18,7 @@ private static readonly IDictionary _memberToFunctionName { typeof(Polygon).GetRuntimeProperty(nameof(Polygon.ExteriorRing)), "ExteriorRing" }, { typeof(Polygon).GetRuntimeProperty(nameof(Polygon.NumInteriorRings)), "NumInteriorRing" } }; + private readonly ISqlExpressionFactory _sqlExpressionFactory; public SqlitePolygonMemberTranslator(ISqlExpressionFactory sqlExpressionFactory) diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMethodTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMethodTranslator.cs index dc6b974f04b..aa213dfdf0c 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMethodTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMethodTranslator.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; @@ -27,10 +27,7 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method { return _sqlExpressionFactory.Function( "InteriorRingN", - new SqlExpression[] { - instance, - _sqlExpressionFactory.Add(arguments[0], _sqlExpressionFactory.Constant(1)) - }, + new[] { instance, _sqlExpressionFactory.Add(arguments[0], _sqlExpressionFactory.Constant(1)) }, method.ReturnType); } diff --git a/src/EFCore.Sqlite.NTS/Scaffolding/Internal/SqliteNetTopologySuiteCodeGeneratorPlugin.cs b/src/EFCore.Sqlite.NTS/Scaffolding/Internal/SqliteNetTopologySuiteCodeGeneratorPlugin.cs index 577d2711fc3..838771b327d 100644 --- a/src/EFCore.Sqlite.NTS/Scaffolding/Internal/SqliteNetTopologySuiteCodeGeneratorPlugin.cs +++ b/src/EFCore.Sqlite.NTS/Scaffolding/Internal/SqliteNetTopologySuiteCodeGeneratorPlugin.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.Design; diff --git a/src/EFCore.Sqlite.NTS/Storage/Internal/SqliteGeometryTypeMapping.cs b/src/EFCore.Sqlite.NTS/Storage/Internal/SqliteGeometryTypeMapping.cs index 76d6879ea48..e53909f5908 100644 --- a/src/EFCore.Sqlite.NTS/Storage/Internal/SqliteGeometryTypeMapping.cs +++ b/src/EFCore.Sqlite.NTS/Storage/Internal/SqliteGeometryTypeMapping.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore.Sqlite.NTS/Storage/Internal/SqliteNetTopologySuiteTypeMappingSourcePlugin.cs b/src/EFCore.Sqlite.NTS/Storage/Internal/SqliteNetTopologySuiteTypeMappingSourcePlugin.cs index 4a22cce018c..d1ecabf8294 100644 --- a/src/EFCore.Sqlite.NTS/Storage/Internal/SqliteNetTopologySuiteTypeMappingSourcePlugin.cs +++ b/src/EFCore.Sqlite.NTS/Storage/Internal/SqliteNetTopologySuiteTypeMappingSourcePlugin.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -20,10 +20,10 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is and multiple registrations - /// are allowed. This means a single instance of each service is used by many + /// The service lifetime is and multiple registrations + /// are allowed. This means a single instance of each service is used by many /// instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public class SqliteNetTopologySuiteTypeMappingSourcePlugin : IRelationalTypeMappingSourcePlugin diff --git a/src/EFCore.Sqlite.NTS/Storage/ValueConversion/Internal/GeometryValueConverter.cs b/src/EFCore.Sqlite.NTS/Storage/ValueConversion/Internal/GeometryValueConverter.cs index ae9e0822918..6f7717a7c4e 100644 --- a/src/EFCore.Sqlite.NTS/Storage/ValueConversion/Internal/GeometryValueConverter.cs +++ b/src/EFCore.Sqlite.NTS/Storage/ValueConversion/Internal/GeometryValueConverter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.Storage.ValueConversion; diff --git a/src/EFCore/ChangeTracking/ChangeTracker.cs b/src/EFCore/ChangeTracking/ChangeTracker.cs index 57816494e0d..a86b1e3a54e 100644 --- a/src/EFCore/ChangeTracking/ChangeTracker.cs +++ b/src/EFCore/ChangeTracking/ChangeTracker.cs @@ -293,7 +293,7 @@ public virtual void TrackGraph( /// /// Typically traversal of the graph should stop whenever an already tracked entity is encountered or when /// an entity is reached that should not be tracked. For this typical behavior, use the - /// overload. This overload, on the other hand, + /// overload. This overload, on the other hand, /// allows the callback to decide when traversal will end, but the onus is then on the caller to ensure that /// traversal will not enter an infinite loop. /// @@ -365,8 +365,8 @@ public event EventHandler StateChanged /// to manually force the deletes to have at a time controlled by the application. /// /// - /// If is true then this method - /// will call . + /// If is true then this method + /// will call . /// /// public virtual void CascadeChanges() diff --git a/src/EFCore/ChangeTracking/CollectionEntry.cs b/src/EFCore/ChangeTracking/CollectionEntry.cs index d012b47ba25..ac55fb285a5 100644 --- a/src/EFCore/ChangeTracking/CollectionEntry.cs +++ b/src/EFCore/ChangeTracking/CollectionEntry.cs @@ -7,8 +7,8 @@ using System.Threading.Tasks; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; -using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Metadata.Internal; @@ -60,9 +60,9 @@ private void LocalDetectChanges() var targetType = Metadata.GetTargetType(); var context = InternalEntry.StateManager.Context; var changeDetector = context.ChangeTracker.AutoDetectChangesEnabled - && (string)context.Model[ChangeDetector.SkipDetectChangesAnnotation] != "true" - ? context.GetDependencies().ChangeDetector - : null; + && (string)context.Model[ChangeDetector.SkipDetectChangesAnnotation] != "true" + ? context.GetDependencies().ChangeDetector + : null; foreach (var entity in collection.OfType().ToList()) { var entry = InternalEntry.StateManager.GetOrCreateEntry(entity, targetType); @@ -153,8 +153,8 @@ public virtual EntityEntry FindEntry([NotNull] object entity) { var entry = GetInternalTargetEntry(entity); return entry == null - ? null - : new EntityEntry(entry); + ? null + : new EntityEntry(entry); } /// @@ -166,7 +166,7 @@ public virtual EntityEntry FindEntry([NotNull] object entity) protected virtual InternalEntityEntry GetInternalTargetEntry([NotNull] object entity) => CurrentValue == null || !((Navigation)Metadata).CollectionAccessor.Contains(InternalEntry.Entity, entity) - ? null - : InternalEntry.StateManager.GetOrCreateEntry(entity, Metadata.GetTargetType()); + ? null + : InternalEntry.StateManager.GetOrCreateEntry(entity, Metadata.GetTargetType()); } } diff --git a/src/EFCore/ChangeTracking/CollectionEntry`.cs b/src/EFCore/ChangeTracking/CollectionEntry`.cs index 360ee1671a6..cac937c6ec0 100644 --- a/src/EFCore/ChangeTracking/CollectionEntry`.cs +++ b/src/EFCore/ChangeTracking/CollectionEntry`.cs @@ -93,8 +93,8 @@ public CollectionEntry([NotNull] InternalEntityEntry internalEntry, [NotNull] IN { var entry = GetInternalTargetEntry(entity); return entry == null - ? null - : new EntityEntry(entry); + ? null + : new EntityEntry(entry); } } } diff --git a/src/EFCore/ChangeTracking/EntityEntry.cs b/src/EFCore/ChangeTracking/EntityEntry.cs index d36d1703cbc..7c53262a47b 100644 --- a/src/EFCore/ChangeTracking/EntityEntry.cs +++ b/src/EFCore/ChangeTracking/EntityEntry.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/ChangeTracking/EntityEntry`.cs b/src/EFCore/ChangeTracking/EntityEntry`.cs index 96fc89b1c08..ef0cd954b8a 100644 --- a/src/EFCore/ChangeTracking/EntityEntry`.cs +++ b/src/EFCore/ChangeTracking/EntityEntry`.cs @@ -9,7 +9,6 @@ using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Utilities; diff --git a/src/EFCore/ChangeTracking/GeometryValueComparer.cs b/src/EFCore/ChangeTracking/GeometryValueComparer.cs index a9b2e999e92..1453fd7e6e7 100644 --- a/src/EFCore/ChangeTracking/GeometryValueComparer.cs +++ b/src/EFCore/ChangeTracking/GeometryValueComparer.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/ChangeTracking/IEntityEntryGraphIterator.cs b/src/EFCore/ChangeTracking/IEntityEntryGraphIterator.cs index 001ea31a35b..1206315e161 100644 --- a/src/EFCore/ChangeTracking/IEntityEntryGraphIterator.cs +++ b/src/EFCore/ChangeTracking/IEntityEntryGraphIterator.cs @@ -14,9 +14,9 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking /// A service to traverse a graph of entities and perform some action on at each node. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IEntityEntryGraphIterator diff --git a/src/EFCore/ChangeTracking/Internal/ChangeDetector.cs b/src/EFCore/ChangeTracking/Internal/ChangeDetector.cs index 57f44663b2a..5f5087e40e9 100644 --- a/src/EFCore/ChangeTracking/Internal/ChangeDetector.cs +++ b/src/EFCore/ChangeTracking/Internal/ChangeDetector.cs @@ -21,8 +21,8 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -272,7 +272,8 @@ private void DetectKeyChange(InternalEntityEntry entry, IProperty property) _logger.ForeignKeyChangeDetected(entry, property, snapshotValue, currentValue); } - entry.StateManager.InternalEntityEntryNotifier.KeyPropertyChanged(entry, property, keys, foreignKeys, snapshotValue, currentValue); + entry.StateManager.InternalEntityEntryNotifier.KeyPropertyChanged( + entry, property, keys, foreignKeys, snapshotValue, currentValue); } } } diff --git a/src/EFCore/ChangeTracking/Internal/ChangeTrackerFactory.cs b/src/EFCore/ChangeTracking/Internal/ChangeTrackerFactory.cs index 60b00f2d7c2..52edb14596f 100644 --- a/src/EFCore/ChangeTracking/Internal/ChangeTrackerFactory.cs +++ b/src/EFCore/ChangeTracking/Internal/ChangeTrackerFactory.cs @@ -16,8 +16,8 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/ChangeTracking/Internal/CompositeValueFactory.cs b/src/EFCore/ChangeTracking/Internal/CompositeValueFactory.cs index a58e1ee0807..784778a624f 100644 --- a/src/EFCore/ChangeTracking/Internal/CompositeValueFactory.cs +++ b/src/EFCore/ChangeTracking/Internal/CompositeValueFactory.cs @@ -223,6 +223,7 @@ public int GetHashCode(object[] obj) { hash.Add(value); } + return hash.ToHashCode(); } } diff --git a/src/EFCore/ChangeTracking/Internal/EntityEntryGraphIterator.cs b/src/EFCore/ChangeTracking/Internal/EntityEntryGraphIterator.cs index c5d5dd842fc..fba415957fc 100644 --- a/src/EFCore/ChangeTracking/Internal/EntityEntryGraphIterator.cs +++ b/src/EFCore/ChangeTracking/Internal/EntityEntryGraphIterator.cs @@ -20,9 +20,9 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class EntityEntryGraphIterator : IEntityEntryGraphIterator diff --git a/src/EFCore/ChangeTracking/Internal/EntityGraphAttacher.cs b/src/EFCore/ChangeTracking/Internal/EntityGraphAttacher.cs index 0f22fe043b6..4541d414ec7 100644 --- a/src/EFCore/ChangeTracking/Internal/EntityGraphAttacher.cs +++ b/src/EFCore/ChangeTracking/Internal/EntityGraphAttacher.cs @@ -17,8 +17,8 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/ChangeTracking/Internal/EntityReferenceMap.cs b/src/EFCore/ChangeTracking/Internal/EntityReferenceMap.cs index e56873bc9fd..ee6c3f432a5 100644 --- a/src/EFCore/ChangeTracking/Internal/EntityReferenceMap.cs +++ b/src/EFCore/ChangeTracking/Internal/EntityReferenceMap.cs @@ -294,14 +294,17 @@ var numberOfStates { return _unchangedReferenceMap.Values; } + if (returnAdded) { return _addedReferenceMap.Values; } + if (returnModified) { return _modifiedReferenceMap.Values; } + if (returnDeleted) { return _deletedReferenceMap.Values; diff --git a/src/EFCore/ChangeTracking/Internal/IChangeDetector.cs b/src/EFCore/ChangeTracking/Internal/IChangeDetector.cs index 2246602fbd7..7bd36c02a65 100644 --- a/src/EFCore/ChangeTracking/Internal/IChangeDetector.cs +++ b/src/EFCore/ChangeTracking/Internal/IChangeDetector.cs @@ -15,8 +15,8 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/ChangeTracking/Internal/IChangeTrackerFactory.cs b/src/EFCore/ChangeTracking/Internal/IChangeTrackerFactory.cs index de3d624c1a1..62d72994f69 100644 --- a/src/EFCore/ChangeTracking/Internal/IChangeTrackerFactory.cs +++ b/src/EFCore/ChangeTracking/Internal/IChangeTrackerFactory.cs @@ -13,8 +13,8 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/ChangeTracking/Internal/IEntityGraphAttacher.cs b/src/EFCore/ChangeTracking/Internal/IEntityGraphAttacher.cs index 5033969f733..df5a8efd6ee 100644 --- a/src/EFCore/ChangeTracking/Internal/IEntityGraphAttacher.cs +++ b/src/EFCore/ChangeTracking/Internal/IEntityGraphAttacher.cs @@ -16,8 +16,8 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/ChangeTracking/Internal/IIdentityMap.cs b/src/EFCore/ChangeTracking/Internal/IIdentityMap.cs index 93dbb38bed9..476f144b707 100644 --- a/src/EFCore/ChangeTracking/Internal/IIdentityMap.cs +++ b/src/EFCore/ChangeTracking/Internal/IIdentityMap.cs @@ -69,7 +69,8 @@ public interface IIdentityMap /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - InternalEntityEntry TryGetEntryUsingPreStoreGeneratedValues([NotNull] IForeignKey foreignKey, [NotNull] InternalEntityEntry dependentEntry); + InternalEntityEntry TryGetEntryUsingPreStoreGeneratedValues( + [NotNull] IForeignKey foreignKey, [NotNull] InternalEntityEntry dependentEntry); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -77,7 +78,8 @@ public interface IIdentityMap /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - InternalEntityEntry TryGetEntryUsingRelationshipSnapshot([NotNull] IForeignKey foreignKey, [NotNull] InternalEntityEntry dependentEntry); + InternalEntityEntry TryGetEntryUsingRelationshipSnapshot( + [NotNull] IForeignKey foreignKey, [NotNull] InternalEntityEntry dependentEntry); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore/ChangeTracking/Internal/IInternalEntityEntryFactory.cs b/src/EFCore/ChangeTracking/Internal/IInternalEntityEntryFactory.cs index 10cffd10f69..6c9c76833cf 100644 --- a/src/EFCore/ChangeTracking/Internal/IInternalEntityEntryFactory.cs +++ b/src/EFCore/ChangeTracking/Internal/IInternalEntityEntryFactory.cs @@ -16,9 +16,9 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IInternalEntityEntryFactory diff --git a/src/EFCore/ChangeTracking/Internal/IInternalEntityEntryNotifier.cs b/src/EFCore/ChangeTracking/Internal/IInternalEntityEntryNotifier.cs index 1c6d7617c90..4505d6454c7 100644 --- a/src/EFCore/ChangeTracking/Internal/IInternalEntityEntryNotifier.cs +++ b/src/EFCore/ChangeTracking/Internal/IInternalEntityEntryNotifier.cs @@ -16,8 +16,8 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/ChangeTracking/Internal/IInternalEntityEntrySubscriber.cs b/src/EFCore/ChangeTracking/Internal/IInternalEntityEntrySubscriber.cs index 6ced262400a..a5a7b7231a0 100644 --- a/src/EFCore/ChangeTracking/Internal/IInternalEntityEntrySubscriber.cs +++ b/src/EFCore/ChangeTracking/Internal/IInternalEntityEntrySubscriber.cs @@ -14,9 +14,9 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IInternalEntityEntrySubscriber diff --git a/src/EFCore/ChangeTracking/Internal/IKeyPropagator.cs b/src/EFCore/ChangeTracking/Internal/IKeyPropagator.cs index eb5c1601059..b35787e87a8 100644 --- a/src/EFCore/ChangeTracking/Internal/IKeyPropagator.cs +++ b/src/EFCore/ChangeTracking/Internal/IKeyPropagator.cs @@ -17,8 +17,8 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/ChangeTracking/Internal/ILocalViewListener.cs b/src/EFCore/ChangeTracking/Internal/ILocalViewListener.cs index 8a11d3abfa6..7371ef54c62 100644 --- a/src/EFCore/ChangeTracking/Internal/ILocalViewListener.cs +++ b/src/EFCore/ChangeTracking/Internal/ILocalViewListener.cs @@ -15,8 +15,8 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/ChangeTracking/Internal/INavigationFixer.cs b/src/EFCore/ChangeTracking/Internal/INavigationFixer.cs index b962856a691..f8309fabcea 100644 --- a/src/EFCore/ChangeTracking/Internal/INavigationFixer.cs +++ b/src/EFCore/ChangeTracking/Internal/INavigationFixer.cs @@ -16,8 +16,8 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/ChangeTracking/Internal/IStateManager.cs b/src/EFCore/ChangeTracking/Internal/IStateManager.cs index 37981dfd552..4f35f8b7c3c 100644 --- a/src/EFCore/ChangeTracking/Internal/IStateManager.cs +++ b/src/EFCore/ChangeTracking/Internal/IStateManager.cs @@ -25,8 +25,8 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -251,7 +251,8 @@ IEnumerable GetNonDeletedEntities() /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - void RecordReferencedUntrackedEntity([NotNull] object referencedEntity, [NotNull] INavigation navigation, [NotNull] InternalEntityEntry referencedFromEntry); + void RecordReferencedUntrackedEntity( + [NotNull] object referencedEntity, [NotNull] INavigation navigation, [NotNull] InternalEntityEntry referencedFromEntry); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -275,7 +276,8 @@ IEnumerable GetNonDeletedEntities() /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - InternalEntityEntry FindPrincipalUsingPreStoreGeneratedValues([NotNull] InternalEntityEntry dependentEntry, [NotNull] IForeignKey foreignKey); + InternalEntityEntry FindPrincipalUsingPreStoreGeneratedValues( + [NotNull] InternalEntityEntry dependentEntry, [NotNull] IForeignKey foreignKey); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -283,7 +285,8 @@ IEnumerable GetNonDeletedEntities() /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - InternalEntityEntry FindPrincipalUsingRelationshipSnapshot([NotNull] InternalEntityEntry dependentEntry, [NotNull] IForeignKey foreignKey); + InternalEntityEntry FindPrincipalUsingRelationshipSnapshot( + [NotNull] InternalEntityEntry dependentEntry, [NotNull] IForeignKey foreignKey); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -307,7 +310,8 @@ IEnumerable GetNonDeletedEntities() /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - IEnumerable GetDependentsFromNavigation([NotNull] InternalEntityEntry principalEntry, [NotNull] IForeignKey foreignKey); + IEnumerable GetDependentsFromNavigation( + [NotNull] InternalEntityEntry principalEntry, [NotNull] IForeignKey foreignKey); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore/ChangeTracking/Internal/IValueGenerationManager.cs b/src/EFCore/ChangeTracking/Internal/IValueGenerationManager.cs index 1f8c181556a..7a5b072c9b7 100644 --- a/src/EFCore/ChangeTracking/Internal/IValueGenerationManager.cs +++ b/src/EFCore/ChangeTracking/Internal/IValueGenerationManager.cs @@ -17,8 +17,8 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/ChangeTracking/Internal/IdentityMap.cs b/src/EFCore/ChangeTracking/Internal/IdentityMap.cs index f1978bcda7e..fa8c3cfa63a 100644 --- a/src/EFCore/ChangeTracking/Internal/IdentityMap.cs +++ b/src/EFCore/ChangeTracking/Internal/IdentityMap.cs @@ -134,27 +134,25 @@ public virtual InternalEntityEntry TryGetEntry(object[] keyValues, bool throwOnN return null; } - else - { - hasNullKey = false; - try - { - return _identityMap.TryGetValue((TKey)key, out var entry) - ? entry - : null; - } - catch (InvalidCastException e) - { - throw new InvalidOperationException( - // ReSharper disable once PossibleNullReferenceException - CoreStrings.ErrorMaterializingPropertyInvalidCast( - Key.DeclaringEntityType.DisplayName(), - Key.Properties.First().Name, - typeof(TKey), - key.GetType()), - e); - } + hasNullKey = false; + + try + { + return _identityMap.TryGetValue((TKey)key, out var entry) + ? entry + : null; + } + catch (InvalidCastException e) + { + throw new InvalidOperationException( + // ReSharper disable once PossibleNullReferenceException + CoreStrings.ErrorMaterializingPropertyInvalidCast( + Key.DeclaringEntityType.DisplayName(), + Key.Properties.First().Name, + typeof(TKey), + key.GetType()), + e); } } @@ -176,7 +174,8 @@ public virtual InternalEntityEntry TryGetEntry(IForeignKey foreignKey, InternalE /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalEntityEntry TryGetEntryUsingPreStoreGeneratedValues(IForeignKey foreignKey, InternalEntityEntry dependentEntry) + public virtual InternalEntityEntry TryGetEntryUsingPreStoreGeneratedValues( + IForeignKey foreignKey, InternalEntityEntry dependentEntry) => foreignKey.GetDependentKeyValueFactory().TryCreateFromPreStoreGeneratedCurrentValues(dependentEntry, out var key) && _identityMap.TryGetValue(key, out var entry) ? entry diff --git a/src/EFCore/ChangeTracking/Internal/IdentityMapFactoryFactory.cs b/src/EFCore/ChangeTracking/Internal/IdentityMapFactoryFactory.cs index 138cd700344..75bfd946b98 100644 --- a/src/EFCore/ChangeTracking/Internal/IdentityMapFactoryFactory.cs +++ b/src/EFCore/ChangeTracking/Internal/IdentityMapFactoryFactory.cs @@ -35,7 +35,8 @@ private static Func CreateFactory(IKey key) var factory = key.GetPrincipalKeyValueFactory(); return typeof(TKey).IsNullableType() - ? (Func)(sensitiveLoggingEnabled => new NullableKeyIdentityMap(key, factory, sensitiveLoggingEnabled)) + ? (Func)(sensitiveLoggingEnabled => + new NullableKeyIdentityMap(key, factory, sensitiveLoggingEnabled)) : sensitiveLoggingEnabled => new IdentityMap(key, factory, sensitiveLoggingEnabled); } } diff --git a/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs b/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs index 5be47957475..88bdc6455d5 100644 --- a/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs +++ b/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs @@ -607,7 +607,8 @@ public virtual void SetStoreGeneratedValue(IProperty property, object value) CoreStrings.StoreGenValue(property.Name, EntityType.DisplayName())); } - SetProperty(property, value, isMaterialization: false, setModified: true, isCascadeDelete: false, CurrentValueType.StoreGenerated); + SetProperty( + property, value, isMaterialization: false, setModified: true, isCascadeDelete: false, CurrentValueType.StoreGenerated); } /// @@ -698,7 +699,7 @@ public virtual TProperty GetOriginalValue(IProperty property) /// public virtual TProperty GetRelationshipSnapshotValue([NotNull] IPropertyBase propertyBase) => ((Func)propertyBase.GetPropertyAccessors().RelationshipSnapshotGetter)( - this); + this); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -1332,8 +1333,9 @@ public virtual void HandleConceptualNulls(bool sensitiveLoggingEnabled, bool for } } - var cascadeFk = fks.FirstOrDefault(fk => fk.DeleteBehavior == DeleteBehavior.Cascade - || fk.DeleteBehavior == DeleteBehavior.ClientCascade); + var cascadeFk = fks.FirstOrDefault( + fk => fk.DeleteBehavior == DeleteBehavior.Cascade + || fk.DeleteBehavior == DeleteBehavior.ClientCascade); if (cascadeFk != null && (force || (!isCascadeDelete diff --git a/src/EFCore/ChangeTracking/Internal/InternalEntityEntryFactory.cs b/src/EFCore/ChangeTracking/Internal/InternalEntityEntryFactory.cs index 287df56b408..38a5011b339 100644 --- a/src/EFCore/ChangeTracking/Internal/InternalEntityEntryFactory.cs +++ b/src/EFCore/ChangeTracking/Internal/InternalEntityEntryFactory.cs @@ -17,9 +17,9 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class InternalEntityEntryFactory : IInternalEntityEntryFactory @@ -39,7 +39,8 @@ public virtual InternalEntityEntry Create(IStateManager stateManager, IEntityTyp /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual InternalEntityEntry Create(IStateManager stateManager, IEntityType entityType, object entity, in ValueBuffer valueBuffer) + public virtual InternalEntityEntry Create( + IStateManager stateManager, IEntityType entityType, object entity, in ValueBuffer valueBuffer) => NewInternalEntityEntry(stateManager, entityType, entity, valueBuffer); private static InternalEntityEntry NewInternalEntityEntry(IStateManager stateManager, IEntityType entityType, object entity) diff --git a/src/EFCore/ChangeTracking/Internal/InternalEntityEntryNotifier.cs b/src/EFCore/ChangeTracking/Internal/InternalEntityEntryNotifier.cs index cf55d105958..ddef24bb595 100644 --- a/src/EFCore/ChangeTracking/Internal/InternalEntityEntryNotifier.cs +++ b/src/EFCore/ChangeTracking/Internal/InternalEntityEntryNotifier.cs @@ -16,8 +16,8 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/ChangeTracking/Internal/InternalEntityEntrySubscriber.cs b/src/EFCore/ChangeTracking/Internal/InternalEntityEntrySubscriber.cs index 0d772bc42db..6078c573600 100644 --- a/src/EFCore/ChangeTracking/Internal/InternalEntityEntrySubscriber.cs +++ b/src/EFCore/ChangeTracking/Internal/InternalEntityEntrySubscriber.cs @@ -21,9 +21,9 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class InternalEntityEntrySubscriber : IInternalEntityEntrySubscriber diff --git a/src/EFCore/ChangeTracking/Internal/InternalMixedEntityEntry.cs b/src/EFCore/ChangeTracking/Internal/InternalMixedEntityEntry.cs index 579e5bd5029..e673214d14d 100644 --- a/src/EFCore/ChangeTracking/Internal/InternalMixedEntityEntry.cs +++ b/src/EFCore/ChangeTracking/Internal/InternalMixedEntityEntry.cs @@ -122,7 +122,7 @@ protected override void WritePropertyValue(IPropertyBase propertyBase, object va public override object GetOrCreateCollection(INavigation navigation, bool forMaterialization) => navigation.IsShadowProperty() ? GetOrCreateCollectionTyped(navigation) - : base.GetOrCreateCollection(navigation,forMaterialization); + : base.GetOrCreateCollection(navigation, forMaterialization); private ICollection GetOrCreateCollectionTyped(INavigation navigation) { diff --git a/src/EFCore/ChangeTracking/Internal/KeyPropagator.cs b/src/EFCore/ChangeTracking/Internal/KeyPropagator.cs index ebe477a9269..0e41275087e 100644 --- a/src/EFCore/ChangeTracking/Internal/KeyPropagator.cs +++ b/src/EFCore/ChangeTracking/Internal/KeyPropagator.cs @@ -21,8 +21,8 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -176,7 +176,9 @@ private ValueGenerator TryGetValueGenerator(IProperty property) { var generationProperty = property.GetGenerationProperty(); - return generationProperty != null ? _valueGeneratorSelector.Select(generationProperty, generationProperty.DeclaringEntityType) : null; + return generationProperty != null + ? _valueGeneratorSelector.Select(generationProperty, generationProperty.DeclaringEntityType) + : null; } } } diff --git a/src/EFCore/ChangeTracking/Internal/LocalViewListener.cs b/src/EFCore/ChangeTracking/Internal/LocalViewListener.cs index a25ded74a2b..6c06e8d6192 100644 --- a/src/EFCore/ChangeTracking/Internal/LocalViewListener.cs +++ b/src/EFCore/ChangeTracking/Internal/LocalViewListener.cs @@ -15,8 +15,8 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/ChangeTracking/Internal/NavigationFixer.cs b/src/EFCore/ChangeTracking/Internal/NavigationFixer.cs index fef003874cb..ca4efbffb8a 100644 --- a/src/EFCore/ChangeTracking/Internal/NavigationFixer.cs +++ b/src/EFCore/ChangeTracking/Internal/NavigationFixer.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections; @@ -19,8 +19,8 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -241,7 +241,7 @@ public virtual void NavigationCollectionChanged( && ReferenceEquals(oldTargetEntry[inverse], entry.Entity) && (!foreignKey.IsOwnership || (oldTargetEntry.EntityState != EntityState.Deleted - && oldTargetEntry.EntityState != EntityState.Detached))) + && oldTargetEntry.EntityState != EntityState.Detached))) { SetNavigation(oldTargetEntry, inverse, null, fromQuery: false); } @@ -560,8 +560,8 @@ private void DeleteFixup(InternalEntityEntry entry) if (dependentToPrincipal != null && (!foreignKey.IsOwnership - || (entry.EntityState != EntityState.Deleted - && entry.EntityState != EntityState.Detached)) + || (entry.EntityState != EntityState.Deleted + && entry.EntityState != EntityState.Detached)) && dependentEntry[dependentToPrincipal] == entry.Entity) { SetNavigation(dependentEntry, dependentToPrincipal, null, fromQuery: false); @@ -607,9 +607,9 @@ private void InitialFixup( if (dependentEntry != null) { if ((!foreignKey.IsOwnership - || (dependentEntry.EntityState != EntityState.Deleted + || (dependentEntry.EntityState != EntityState.Deleted && dependentEntry.EntityState != EntityState.Detached)) - && (foreignKey.PrincipalToDependent == null + && (foreignKey.PrincipalToDependent == null || entry[foreignKey.PrincipalToDependent] == null || entry[foreignKey.PrincipalToDependent] == dependentEntry.Entity)) { @@ -625,7 +625,7 @@ private void InitialFixup( { if (!foreignKey.IsOwnership || (dependentEntry.EntityState != EntityState.Deleted - && dependentEntry.EntityState != EntityState.Detached)) + && dependentEntry.EntityState != EntityState.Detached)) { // Add to collection on principal indicated by FK and set inverse navigation AddToCollection(entry, foreignKey.PrincipalToDependent, dependentEntry, fromQuery); @@ -863,8 +863,8 @@ private static bool PrincipalValueEqualsDependentValue( object principalValue) => (principalProperty.GetKeyValueComparer() ?? principalProperty.GetTypeMapping().KeyComparer) - ?.Equals(dependentValue, principalValue) - ?? StructuralComparisons.StructuralEqualityComparer.Equals( + ?.Equals(dependentValue, principalValue) + ?? StructuralComparisons.StructuralEqualityComparer.Equals( dependentValue, principalValue); diff --git a/src/EFCore/ChangeTracking/Internal/NullableKeyIdentityMap.cs b/src/EFCore/ChangeTracking/Internal/NullableKeyIdentityMap.cs index 3c4d088c476..d2870fd0810 100644 --- a/src/EFCore/ChangeTracking/Internal/NullableKeyIdentityMap.cs +++ b/src/EFCore/ChangeTracking/Internal/NullableKeyIdentityMap.cs @@ -5,7 +5,6 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Metadata.Internal; namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal { diff --git a/src/EFCore/ChangeTracking/Internal/SimpleNullableDependentKeyValueFactory.cs b/src/EFCore/ChangeTracking/Internal/SimpleNullableDependentKeyValueFactory.cs index 5696a52cc24..3a1aa2e50b0 100644 --- a/src/EFCore/ChangeTracking/Internal/SimpleNullableDependentKeyValueFactory.cs +++ b/src/EFCore/ChangeTracking/Internal/SimpleNullableDependentKeyValueFactory.cs @@ -65,7 +65,8 @@ public virtual bool TryCreateFromCurrentValues(InternalEntityEntry entry, out TK /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual bool TryCreateFromPreStoreGeneratedCurrentValues(InternalEntityEntry entry, out TKey key) - => HandleNullableValue(((Func)_propertyAccessors.PreStoreGeneratedCurrentValueGetter)(entry), out key); + => HandleNullableValue( + ((Func)_propertyAccessors.PreStoreGeneratedCurrentValueGetter)(entry), out key); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore/ChangeTracking/Internal/SnapshotFactoryFactory.cs b/src/EFCore/ChangeTracking/Internal/SnapshotFactoryFactory.cs index a4901a8e542..e084d5c672d 100644 --- a/src/EFCore/ChangeTracking/Internal/SnapshotFactoryFactory.cs +++ b/src/EFCore/ChangeTracking/Internal/SnapshotFactoryFactory.cs @@ -160,10 +160,7 @@ private Expression CreateSnapshotExpression( return UseEntityVariable && entityVariable != null ? (Expression)Expression.Block( - new List - { - entityVariable - }, + new List { entityVariable }, new List { Expression.Assign( diff --git a/src/EFCore/ChangeTracking/Internal/StateManager.cs b/src/EFCore/ChangeTracking/Internal/StateManager.cs index b5db82689b4..e77056700b5 100644 --- a/src/EFCore/ChangeTracking/Internal/StateManager.cs +++ b/src/EFCore/ChangeTracking/Internal/StateManager.cs @@ -28,8 +28,8 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -70,7 +70,8 @@ public StateManager([NotNull] StateManagerDependencies dependencies) _database = dependencies.Database; _concurrencyDetector = dependencies.ConcurrencyDetector; Context = dependencies.CurrentContext.Context; - EntityFinderFactory = new EntityFinderFactory(dependencies.EntityFinderSource, this, dependencies.SetSource, dependencies.CurrentContext.Context); + EntityFinderFactory = new EntityFinderFactory( + dependencies.EntityFinderSource, this, dependencies.SetSource, dependencies.CurrentContext.Context); EntityMaterializerSource = dependencies.EntityMaterializerSource; if (dependencies.LoggingOptions.IsSensitiveDataLoggingEnabled) @@ -239,9 +240,11 @@ public virtual InternalEntityEntry GetOrCreateEntry(object entity, IEntityType e { if (!entityType.IsAssignableFrom(runtimeEntityType)) { - throw new InvalidOperationException(CoreStrings.TrackingTypeMismatch( - runtimeEntityType.DisplayName(), entityType.DisplayName())); + throw new InvalidOperationException( + CoreStrings.TrackingTypeMismatch( + runtimeEntityType.DisplayName(), entityType.DisplayName())); } + entityType = runtimeEntityType; } @@ -403,13 +406,12 @@ public virtual InternalEntityEntry TryGetEntry(object entity, IEntityType entity { if (throwOnTypeMismatch) { - throw new InvalidOperationException(CoreStrings.TrackingTypeMismatch( - entry.EntityType.DisplayName(), entityType.DisplayName())); - } - else - { - return null; + throw new InvalidOperationException( + CoreStrings.TrackingTypeMismatch( + entry.EntityType.DisplayName(), entityType.DisplayName())); } + + return null; } return found ? entry : null; @@ -756,7 +758,8 @@ public virtual InternalEntityEntry FindPrincipalUsingRelationshipSnapshot( FindIdentityMap(foreignKey.PrincipalKey) ?.TryGetEntryUsingRelationshipSnapshot(foreignKey, dependentEntry)); - private static InternalEntityEntry FilterIncompatiblePrincipal(IForeignKey foreignKey, + private static InternalEntityEntry FilterIncompatiblePrincipal( + IForeignKey foreignKey, InternalEntityEntry principalEntry) => principalEntry != null && foreignKey.PrincipalEntityType.IsAssignableFrom(principalEntry.EntityType) @@ -840,7 +843,8 @@ public virtual IEnumerable GetDependentsUsingRelationshipSn /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual IEnumerable GetDependentsFromNavigation(InternalEntityEntry principalEntry, IForeignKey foreignKey) + public virtual IEnumerable GetDependentsFromNavigation( + InternalEntityEntry principalEntry, IForeignKey foreignKey) { var navigation = foreignKey.PrincipalToDependent; if (navigation == null @@ -1033,7 +1037,8 @@ public virtual void CascadeDelete(InternalEntityEntry entry, bool force, IEnumer { foreach (var dependentProperty in fk.Properties) { - dependent.SetProperty(dependentProperty, null, isMaterialization: false, setModified: true, isCascadeDelete: true); + dependent.SetProperty( + dependentProperty, null, isMaterialization: false, setModified: true, isCascadeDelete: true); } if (dependent.HasConceptualNull) diff --git a/src/EFCore/ChangeTracking/Internal/StateManagerDependencies.cs b/src/EFCore/ChangeTracking/Internal/StateManagerDependencies.cs index 6751d235fa7..570f25c2862 100644 --- a/src/EFCore/ChangeTracking/Internal/StateManagerDependencies.cs +++ b/src/EFCore/ChangeTracking/Internal/StateManagerDependencies.cs @@ -29,8 +29,8 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/ChangeTracking/Internal/ValueGenerationManager.cs b/src/EFCore/ChangeTracking/Internal/ValueGenerationManager.cs index 1e160f9c791..895010fa2ec 100644 --- a/src/EFCore/ChangeTracking/Internal/ValueGenerationManager.cs +++ b/src/EFCore/ChangeTracking/Internal/ValueGenerationManager.cs @@ -21,8 +21,8 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/ChangeTracking/LocalView.cs b/src/EFCore/ChangeTracking/LocalView.cs index c91f9338314..1e95a9a7dfd 100644 --- a/src/EFCore/ChangeTracking/LocalView.cs +++ b/src/EFCore/ChangeTracking/LocalView.cs @@ -48,7 +48,12 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking /// /// /// The type of the entity in the local view. - public class LocalView : ICollection, INotifyCollectionChanged, INotifyPropertyChanged, INotifyPropertyChanging, IListSource + public class LocalView : + ICollection, + INotifyCollectionChanged, + INotifyPropertyChanged, + INotifyPropertyChanging, + IListSource where TEntity : class { private ObservableBackedBindingList _bindingList; diff --git a/src/EFCore/ChangeTracking/NavigationEntry.cs b/src/EFCore/ChangeTracking/NavigationEntry.cs index 9f07dfa4021..b11ee4b3f10 100644 --- a/src/EFCore/ChangeTracking/NavigationEntry.cs +++ b/src/EFCore/ChangeTracking/NavigationEntry.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -62,7 +62,8 @@ private static INavigation GetNavigation(InternalEntityEntry internalEntry, stri throw new InvalidOperationException( CoreStrings.NavigationIsProperty( name, internalEntry.EntityType.DisplayName(), - nameof(ChangeTracking.EntityEntry.Reference), nameof(ChangeTracking.EntityEntry.Collection), nameof(ChangeTracking.EntityEntry.Property))); + nameof(ChangeTracking.EntityEntry.Reference), nameof(ChangeTracking.EntityEntry.Collection), + nameof(ChangeTracking.EntityEntry.Property))); } throw new InvalidOperationException(CoreStrings.PropertyNotFound(name, internalEntry.EntityType.DisplayName())); diff --git a/src/EFCore/ChangeTracking/ReferenceEntry.cs b/src/EFCore/ChangeTracking/ReferenceEntry.cs index 9b5052130be..96002da71d7 100644 --- a/src/EFCore/ChangeTracking/ReferenceEntry.cs +++ b/src/EFCore/ChangeTracking/ReferenceEntry.cs @@ -3,8 +3,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; -using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Metadata; namespace Microsoft.EntityFrameworkCore.ChangeTracking diff --git a/src/EFCore/ChangeTracking/ValueComparer.cs b/src/EFCore/ChangeTracking/ValueComparer.cs index 8b02883736c..e83b71ddd97 100644 --- a/src/EFCore/ChangeTracking/ValueComparer.cs +++ b/src/EFCore/ChangeTracking/ValueComparer.cs @@ -137,10 +137,8 @@ public virtual Expression ExtractEqualsBody( var original2 = EqualsExpression.Parameters[1]; return new ReplacingExpressionVisitor( - new Dictionary { - { original1, leftExpression }, - { original2, rightExpression } - }).Visit(EqualsExpression.Body); + new Dictionary { { original1, leftExpression }, { original2, rightExpression } }) + .Visit(EqualsExpression.Body); } /// diff --git a/src/EFCore/DbContext.cs b/src/EFCore/DbContext.cs index eaabafe678b..4e459d618ec 100644 --- a/src/EFCore/DbContext.cs +++ b/src/EFCore/DbContext.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/DbContextOptions.cs b/src/EFCore/DbContextOptions.cs index a760a5e6e61..f5daaf37048 100644 --- a/src/EFCore/DbContextOptions.cs +++ b/src/EFCore/DbContextOptions.cs @@ -64,7 +64,7 @@ public virtual TExtension GetExtension() /// /// Adds the given extension to the underlying options and creates a new - /// with the extension added. + /// with the extension added. /// /// The type of extension to be added. /// The extension to be added. diff --git a/src/EFCore/DbContextOptions`.cs b/src/EFCore/DbContextOptions`.cs index e64e19a0b33..4509c7b0611 100644 --- a/src/EFCore/DbContextOptions`.cs +++ b/src/EFCore/DbContextOptions`.cs @@ -43,7 +43,7 @@ public DbContextOptions( /// /// Adds the given extension to the underlying options and creates a new - /// with the extension added. + /// with the extension added. /// /// The type of extension to be added. /// The extension to be added. diff --git a/src/EFCore/DbFunctions.cs b/src/EFCore/DbFunctions.cs index fcbb7a1bab4..e42d3c1fbf3 100644 --- a/src/EFCore/DbFunctions.cs +++ b/src/EFCore/DbFunctions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.ComponentModel; diff --git a/src/EFCore/DbFunctionsExtensions.cs b/src/EFCore/DbFunctionsExtensions.cs index ddf19d2908f..f8181f7f564 100644 --- a/src/EFCore/DbFunctionsExtensions.cs +++ b/src/EFCore/DbFunctionsExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/DbSet.cs b/src/EFCore/DbSet.cs index 77d290824eb..8c970572014 100644 --- a/src/EFCore/DbSet.cs +++ b/src/EFCore/DbSet.cs @@ -163,7 +163,7 @@ public virtual ValueTask> AddAsync( /// to anything other than the CLR default for the property type. /// /// - /// For entity types without generated keys, the state set is always . + /// For entity types without generated keys, the state set is always . /// /// /// Use to set the state of only a single entity. @@ -225,7 +225,7 @@ public virtual ValueTask> AddAsync( /// to anything other than the CLR default for the property type. /// /// - /// For entity types without generated keys, the state set is always . + /// For entity types without generated keys, the state set is always . /// /// /// Use to set the state of only a single entity. @@ -285,7 +285,7 @@ public virtual ValueTask> AddAsync( /// to anything other than the CLR default for the property type. /// /// - /// For entity types without generated keys, the state set is always . + /// For entity types without generated keys, the state set is always . /// /// /// Use to set the state of only a single entity. @@ -336,7 +336,7 @@ public virtual ValueTask> AddAsync( /// to anything other than the CLR default for the property type. /// /// - /// For entity types without generated keys, the state set is always . + /// For entity types without generated keys, the state set is always . /// /// /// Use to set the state of only a single entity. @@ -395,7 +395,7 @@ public virtual Task AddRangeAsync( /// to anything other than the CLR default for the property type. /// /// - /// For entity types without generated keys, the state set is always . + /// For entity types without generated keys, the state set is always . /// /// /// Use to set the state of only a single entity. @@ -446,7 +446,7 @@ public virtual Task AddRangeAsync( /// to anything other than the CLR default for the property type. /// /// - /// For entity types without generated keys, the state set is always . + /// For entity types without generated keys, the state set is always . /// /// /// Use to set the state of only a single entity. diff --git a/src/EFCore/DeleteBehavior.cs b/src/EFCore/DeleteBehavior.cs index 09b42d98430..dee2b4f8a45 100644 --- a/src/EFCore/DeleteBehavior.cs +++ b/src/EFCore/DeleteBehavior.cs @@ -71,7 +71,7 @@ public enum DeleteBehavior /// method, then the behavior in the database is /// the same as is described above for tracked entities. Keep in mind that some databases cannot easily /// support this behavior, especially if there are cycles in relationships, in which case it may - /// be better to use which will allow EF to cascade null values + /// be better to use which will allow EF to cascade null values /// on loaded entities even if the database does not support this. /// /// @@ -87,7 +87,7 @@ public enum DeleteBehavior /// method, then the behavior in the database is /// the same as is described above for tracked entities. Keep in mind that some databases cannot easily /// support this behavior, especially if there are cycles in relationships, in which case it may - /// be better to use which will allow EF to perform cascade deletes + /// be better to use which will allow EF to perform cascade deletes /// on loaded entities even if the database does not support this. /// /// @@ -126,10 +126,9 @@ public enum DeleteBehavior /// NoAction, - /// /// - /// Note: it is unusual to use this value. Consider using instead to match + /// Note: it is unusual to use this value. Consider using instead to match /// the behavior of EF6 with cascading deletes disabled. /// /// diff --git a/src/EFCore/Design/IDesignTimeServices.cs b/src/EFCore/Design/IDesignTimeServices.cs index 2ac32281173..aaafff54604 100644 --- a/src/EFCore/Design/IDesignTimeServices.cs +++ b/src/EFCore/Design/IDesignTimeServices.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore/Diagnostics/CoreEventId.cs b/src/EFCore/Diagnostics/CoreEventId.cs index 650b258ac4c..93dc34fb6dc 100644 --- a/src/EFCore/Diagnostics/CoreEventId.cs +++ b/src/EFCore/Diagnostics/CoreEventId.cs @@ -134,7 +134,8 @@ private enum Id /// The same entity is being tracked as a different weak entity type. /// This event is in the category. /// - public static readonly EventId DuplicateDependentEntityTypeInstanceWarning = MakeUpdateId(Id.DuplicateDependentEntityTypeInstanceWarning); + public static readonly EventId DuplicateDependentEntityTypeInstanceWarning = + MakeUpdateId(Id.DuplicateDependentEntityTypeInstanceWarning); private static readonly string _queryPrefix = DbLoggerCategory.Query.Name + "."; private static EventId MakeQueryId(Id id) => new EventId((int)id, _queryPrefix + id); @@ -172,7 +173,8 @@ private enum Id /// /// [Obsolete] - public static readonly EventId RowLimitingOperationWithoutOrderByWarning = MakeQueryId(Id.RowLimitingOperationWithoutOrderByWarning); + public static readonly EventId RowLimitingOperationWithoutOrderByWarning = + MakeQueryId(Id.RowLimitingOperationWithoutOrderByWarning); /// /// @@ -573,7 +575,8 @@ public static readonly EventId PossibleUnintendedReferenceComparisonWarning /// . /// /// - public static readonly EventId MultipleInversePropertiesSameTargetWarning = MakeModelId(Id.MultipleInversePropertiesSameTargetWarning); + public static readonly EventId MultipleInversePropertiesSameTargetWarning = + MakeModelId(Id.MultipleInversePropertiesSameTargetWarning); /// /// @@ -616,7 +619,8 @@ public static readonly EventId PossibleUnintendedReferenceComparisonWarning /// . /// /// - public static readonly EventId ForeignKeyAttributesOnBothPropertiesWarning = MakeModelId(Id.ForeignKeyAttributesOnBothPropertiesWarning); + public static readonly EventId ForeignKeyAttributesOnBothPropertiesWarning = + MakeModelId(Id.ForeignKeyAttributesOnBothPropertiesWarning); /// /// diff --git a/src/EFCore/Diagnostics/CoreLoggerExtensions.cs b/src/EFCore/Diagnostics/CoreLoggerExtensions.cs index 01263a115e0..190089b4ae1 100644 --- a/src/EFCore/Diagnostics/CoreLoggerExtensions.cs +++ b/src/EFCore/Diagnostics/CoreLoggerExtensions.cs @@ -13,7 +13,6 @@ using Microsoft.EntityFrameworkCore.Diagnostics.Internal; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure.Internal; -using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Query; @@ -1219,14 +1218,8 @@ public static void RequiredAttributeOnBothNavigations( new TwoPropertyBaseCollectionsEventData( definition, RequiredAttributeOnBothNavigations, - new[] - { - firstNavigation - }, - new[] - { - secondNavigation - })); + new[] { firstNavigation }, + new[] { secondNavigation })); } } @@ -1275,14 +1268,8 @@ public static void NonNullableReferenceOnBothNavigations( new TwoPropertyBaseCollectionsEventData( definition, NonNullableReferenceOnBothNavigations, - new[] - { - firstNavigation - }, - new[] - { - secondNavigation - })); + new[] { firstNavigation }, + new[] { secondNavigation })); } } @@ -1488,14 +1475,8 @@ public static void MultiplePrimaryKeyCandidates( new TwoPropertyBaseCollectionsEventData( definition, MultiplePrimaryKeyCandidates, - new[] - { - firstProperty - }, - new[] - { - secondProperty - })); + new[] { firstProperty }, + new[] { secondProperty })); } } @@ -1592,10 +1573,7 @@ public static void MultipleInversePropertiesSameTargetWarning( definition, MultipleInversePropertiesSameTargetWarning, conflictingNavigations, - new[] - { - new Tuple(inverseNavigation, targetType) - })); + new[] { new Tuple(inverseNavigation, targetType) })); } } @@ -1648,10 +1626,7 @@ public static void NonDefiningInverseNavigationWarning( new TwoUnmappedPropertyCollectionsEventData( definition, NonDefiningInverseNavigationWarning, - new[] - { - new Tuple(navigation, declaringType.ClrType) - }, + new[] { new Tuple(navigation, declaringType.ClrType) }, new[] { new Tuple(inverseNavigation, targetType.ClrType), @@ -1714,10 +1689,7 @@ public static void NonOwnershipInverseNavigationWarning( new TwoUnmappedPropertyCollectionsEventData( definition, NonOwnershipInverseNavigationWarning, - new[] - { - new Tuple(navigation, declaringType.ClrType) - }, + new[] { new Tuple(navigation, declaringType.ClrType) }, new[] { new Tuple(inverseNavigation, targetType.ClrType), @@ -1843,14 +1815,8 @@ public static void ForeignKeyAttributesOnBothNavigationsWarning( new TwoPropertyBaseCollectionsEventData( definition, ForeignKeyAttributesOnBothNavigationsWarning, - new[] - { - firstNavigation - }, - new[] - { - secondNavigation - })); + new[] { firstNavigation }, + new[] { secondNavigation })); } } @@ -1903,10 +1869,7 @@ public static void ConflictingForeignKeyAttributesOnNavigationAndPropertyWarning { new Tuple(navigation.GetIdentifyingMemberInfo(), navigation.DeclaringEntityType.ClrType) }, - new[] - { - new Tuple(property, property.DeclaringType) - })); + new[] { new Tuple(property, property.DeclaringType) })); } } diff --git a/src/EFCore/Diagnostics/EventDefinitionBase.cs b/src/EFCore/Diagnostics/EventDefinitionBase.cs index a0df460cf17..c6da7d7d4b6 100644 --- a/src/EFCore/Diagnostics/EventDefinitionBase.cs +++ b/src/EFCore/Diagnostics/EventDefinitionBase.cs @@ -22,7 +22,7 @@ public abstract class EventDefinitionBase /// Logging options. /// The . /// The at which the event will be logged. - /// A string representing the code that should be passed to . + /// A string representing the code that should be passed to . protected EventDefinitionBase( [NotNull] ILoggingOptions loggingOptions, EventId eventId, @@ -47,9 +47,9 @@ protected EventDefinitionBase( var behavior = warningsConfiguration.GetBehavior(eventId); _warningBehavior = behavior ?? (level == LogLevel.Warning - && warningsConfiguration.DefaultBehavior == WarningBehavior.Throw - ? WarningBehavior.Throw - : WarningBehavior.Log); + && warningsConfiguration.DefaultBehavior == WarningBehavior.Throw + ? WarningBehavior.Throw + : WarningBehavior.Log); } else { @@ -70,7 +70,8 @@ protected EventDefinitionBase( public virtual LogLevel Level { [DebuggerStepThrough] get; } /// - /// A string representing the code that should be passed to to suppress this event as an error. + /// A string representing the code that should be passed to to suppress this event + /// as an error. /// public virtual string EventIdCode { get; } @@ -99,10 +100,12 @@ internal sealed class MessageExtractingLogger : ILogger { private string _message; - public string Message { + public string Message + { get => _message ?? throw new InvalidOperationException(); private set => _message = value; } + void ILogger.Log( LogLevel logLevel, EventId eventId, diff --git a/src/EFCore/Diagnostics/IDiagnosticsLogger.cs b/src/EFCore/Diagnostics/IDiagnosticsLogger.cs index 7cf4f5b3a1b..a772d754345 100644 --- a/src/EFCore/Diagnostics/IDiagnosticsLogger.cs +++ b/src/EFCore/Diagnostics/IDiagnosticsLogger.cs @@ -14,9 +14,9 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics /// for ASP.NET and for everything else. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IDiagnosticsLogger diff --git a/src/EFCore/Diagnostics/IDiagnosticsLogger`.cs b/src/EFCore/Diagnostics/IDiagnosticsLogger`.cs index ac7fccec166..5b043f95a52 100644 --- a/src/EFCore/Diagnostics/IDiagnosticsLogger`.cs +++ b/src/EFCore/Diagnostics/IDiagnosticsLogger`.cs @@ -19,8 +19,8 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics /// sensitive data or not can be made. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/Diagnostics/IInterceptor.cs b/src/EFCore/Diagnostics/IInterceptor.cs index 840beec2b5a..88f3054c129 100644 --- a/src/EFCore/Diagnostics/IInterceptor.cs +++ b/src/EFCore/Diagnostics/IInterceptor.cs @@ -16,7 +16,7 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics /// to register application interceptors. /// /// - /// Extensions can also register multiple s in the internal service provider. + /// Extensions can also register multiple s in the internal service provider. /// If both injected and application interceptors are found, then the injected interceptors are run in the /// order that they are resolved from the service provider, and then the application interceptors are run /// in the order that they were added to the context. diff --git a/src/EFCore/Diagnostics/ILoggingOptions.cs b/src/EFCore/Diagnostics/ILoggingOptions.cs index 9e325fe564e..723aa35a2c9 100644 --- a/src/EFCore/Diagnostics/ILoggingOptions.cs +++ b/src/EFCore/Diagnostics/ILoggingOptions.cs @@ -13,9 +13,9 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics /// messages are logged and/or thrown in exceptions. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface ILoggingOptions : ISingletonOptions diff --git a/src/EFCore/Diagnostics/InterceptionResult.cs b/src/EFCore/Diagnostics/InterceptionResult.cs index 025f7b343eb..0b3ddab75f3 100644 --- a/src/EFCore/Diagnostics/InterceptionResult.cs +++ b/src/EFCore/Diagnostics/InterceptionResult.cs @@ -5,14 +5,14 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics { /// /// - /// Represents a result from an such as an 'IDbConnectionInterceptor' to allow + /// Represents a result from an such as an 'IDbConnectionInterceptor' to allow /// suppression of the normal operation being intercepted. /// /// /// A value of this type is passed to all interceptor methods that are called before the operation /// being intercepted is executed. /// Typically the interceptor should return the value passed in. - /// However, creating a result with causes the operation being + /// However, creating a result with causes the operation being /// intercepted to be suppressed; that is, the operation is not executed. /// /// diff --git a/src/EFCore/Diagnostics/InterceptionResult`.cs b/src/EFCore/Diagnostics/InterceptionResult`.cs index 3a62ffddcbe..fa896f64233 100644 --- a/src/EFCore/Diagnostics/InterceptionResult`.cs +++ b/src/EFCore/Diagnostics/InterceptionResult`.cs @@ -15,7 +15,7 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics /// A value of this type is passed to all interceptor methods that are called before the operation /// being intercepted is executed. /// Typically the interceptor should return the value passed in. - /// However, creating a result with causes the operation being + /// However, creating a result with causes the operation being /// intercepted to be suppressed; that is, the operation is not executed. /// The value in the result is then used as a substitute return value for the operation that was suppressed. /// @@ -45,7 +45,7 @@ private InterceptionResult(TResult result) /// /// /// The property can only be accessed if is true. The concept here - /// is the same as and + /// is the same as and /// /// when is false. /// @@ -63,7 +63,7 @@ public TResult Result } /// - /// If true, then interception is suppressed, and contains the result to use. + /// If true, then interception is suppressed, and contains the result to use. /// public bool HasResult { get; } } diff --git a/src/EFCore/Diagnostics/Internal/Interceptors.cs b/src/EFCore/Diagnostics/Internal/Interceptors.cs index 0ae3aa2e480..6c2d0beed10 100644 --- a/src/EFCore/Diagnostics/Internal/Interceptors.cs +++ b/src/EFCore/Diagnostics/Internal/Interceptors.cs @@ -30,7 +30,8 @@ public class Interceptors : IInterceptors /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public Interceptors([NotNull] IServiceProvider serviceProvider, + public Interceptors( + [NotNull] IServiceProvider serviceProvider, [NotNull] IEnumerable injectedInterceptors, [NotNull] IEnumerable interceptorAggregators) { @@ -71,7 +72,7 @@ public virtual TInterceptor Aggregate() /// /// We resolve this lazily because loggers are created very early in the initialization - /// process where is not yet available from D.I. + /// process where is not yet available from D.I. /// This means those loggers can't do interception, but that's okay because nothing /// else is ready for them to do interception anyway. /// @@ -81,6 +82,5 @@ private CoreOptionsExtension CoreOptionsExtension .Extensions .OfType() .FirstOrDefault(); - } } diff --git a/src/EFCore/Diagnostics/ValueConverterEventData.cs b/src/EFCore/Diagnostics/ValueConverterEventData.cs index 7b5b60ab4c3..4d1ae3504c3 100644 --- a/src/EFCore/Diagnostics/ValueConverterEventData.cs +++ b/src/EFCore/Diagnostics/ValueConverterEventData.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Extensions/ConventionAnnotatableExtensions.cs b/src/EFCore/Extensions/ConventionAnnotatableExtensions.cs index 2a55aecbbf9..8c354a921b8 100644 --- a/src/EFCore/Extensions/ConventionAnnotatableExtensions.cs +++ b/src/EFCore/Extensions/ConventionAnnotatableExtensions.cs @@ -21,7 +21,8 @@ public static class ConventionAnnotatableExtensions /// The object to find the annotation on. /// The key of the annotation to find. /// The annotation with the specified name. - public static IConventionAnnotation GetAnnotation([NotNull] this IConventionAnnotatable annotatable, [NotNull] string annotationName) + public static IConventionAnnotation GetAnnotation( + [NotNull] this IConventionAnnotatable annotatable, [NotNull] string annotationName) => (IConventionAnnotation)((IAnnotatable)annotatable).GetAnnotation(annotationName); /// diff --git a/src/EFCore/Extensions/ConventionEntityTypeExtensions.cs b/src/EFCore/Extensions/ConventionEntityTypeExtensions.cs index 903209cd80f..823f0c31adf 100644 --- a/src/EFCore/Extensions/ConventionEntityTypeExtensions.cs +++ b/src/EFCore/Extensions/ConventionEntityTypeExtensions.cs @@ -304,7 +304,7 @@ public static IConventionForeignKey FindForeignKey( } /// - /// Gets the foreign keys declared on the given using the given properties. + /// Gets the foreign keys declared on the given using the given properties. /// /// The entity type. /// The properties to find the foreign keys on. @@ -484,7 +484,8 @@ public static IConventionProperty AddProperty( [NotNull] this IConventionEntityType entityType, [NotNull] MemberInfo memberInfo, bool fromDataAnnotation = false) - => Check.NotNull(entityType, nameof(entityType)).AddProperty(memberInfo.GetSimpleMemberName(), memberInfo.GetMemberType(), + => Check.NotNull(entityType, nameof(entityType)).AddProperty( + memberInfo.GetSimpleMemberName(), memberInfo.GetMemberType(), memberInfo, setTypeConfigurationSource: true, fromDataAnnotation); /// @@ -497,7 +498,8 @@ public static IConventionProperty AddProperty( public static IConventionProperty AddProperty( [NotNull] this IConventionEntityType entityType, [NotNull] string name, bool fromDataAnnotation = false) - => ((EntityType)entityType).AddProperty(name, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); + => ((EntityType)entityType).AddProperty( + name, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// /// Adds a property to this entity type. @@ -513,7 +515,6 @@ public static IConventionProperty AddProperty( bool setTypeConfigurationSource = true, bool fromDataAnnotation = false) => entityType.AddProperty(name, propertyType, null, setTypeConfigurationSource, fromDataAnnotation); - /// /// Gets the index defined on the given property. Returns null if no index is defined. /// diff --git a/src/EFCore/Extensions/ConventionModelExtensions.cs b/src/EFCore/Extensions/ConventionModelExtensions.cs index 3d70d838ae7..b0ab60396b7 100644 --- a/src/EFCore/Extensions/ConventionModelExtensions.cs +++ b/src/EFCore/Extensions/ConventionModelExtensions.cs @@ -59,7 +59,8 @@ public static IReadOnlyCollection GetEntityTypes([NotNull /// The name of the entity type to find. /// The entity types found. [DebuggerStepThrough] - public static IReadOnlyCollection GetEntityTypes([NotNull] this IConventionModel model, [NotNull] string name) + public static IReadOnlyCollection GetEntityTypes( + [NotNull] this IConventionModel model, [NotNull] string name) => ((Model)model).GetEntityTypes(name); /// @@ -296,7 +297,7 @@ public static void AddIgnored([NotNull] this IConventionModel model, [NotNull] T /// /// Forces post-processing on the model such that it is ready for use by the runtime. This post - /// processing happens automatically when using ; this method allows it to be run + /// processing happens automatically when using ; this method allows it to be run /// explicitly in cases where the automatic execution is not possible. /// /// The model to finalize. diff --git a/src/EFCore/Extensions/ConventionTypeBaseExtensions.cs b/src/EFCore/Extensions/ConventionTypeBaseExtensions.cs index bfba70d169e..734bc793edc 100644 --- a/src/EFCore/Extensions/ConventionTypeBaseExtensions.cs +++ b/src/EFCore/Extensions/ConventionTypeBaseExtensions.cs @@ -3,8 +3,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.EntityFrameworkCore.Metadata.Internal; +using Microsoft.EntityFrameworkCore.Utilities; // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore diff --git a/src/EFCore/Extensions/EntityFrameworkQueryableExtensions.cs b/src/EFCore/Extensions/EntityFrameworkQueryableExtensions.cs index ea465b83469..26d3338ce91 100644 --- a/src/EFCore/Extensions/EntityFrameworkQueryableExtensions.cs +++ b/src/EFCore/Extensions/EntityFrameworkQueryableExtensions.cs @@ -644,7 +644,8 @@ public static Task SingleOrDefaultAsync( Check.NotNull(source, nameof(source)); Check.NotNull(predicate, nameof(predicate)); - return ExecuteAsync>(QueryableMethods.SingleOrDefaultWithPredicate, source, predicate, cancellationToken); + return ExecuteAsync>( + QueryableMethods.SingleOrDefaultWithPredicate, source, predicate, cancellationToken); } #endregion @@ -836,7 +837,8 @@ public static Task SumAsync( { Check.NotNull(source, nameof(source)); - return ExecuteAsync>(QueryableMethods.GetSumWithoutSelector(typeof(decimal?)), source, cancellationToken); + return ExecuteAsync>( + QueryableMethods.GetSumWithoutSelector(typeof(decimal?)), source, cancellationToken); } /// @@ -866,7 +868,8 @@ public static Task SumAsync( Check.NotNull(source, nameof(source)); Check.NotNull(selector, nameof(selector)); - return ExecuteAsync>(QueryableMethods.GetSumWithSelector(typeof(decimal)), source, selector, cancellationToken); + return ExecuteAsync>( + QueryableMethods.GetSumWithSelector(typeof(decimal)), source, selector, cancellationToken); } /// @@ -896,7 +899,8 @@ public static Task SumAsync( Check.NotNull(source, nameof(source)); Check.NotNull(selector, nameof(selector)); - return ExecuteAsync>(QueryableMethods.GetSumWithSelector(typeof(decimal?)), source, selector, cancellationToken); + return ExecuteAsync>( + QueryableMethods.GetSumWithSelector(typeof(decimal?)), source, selector, cancellationToken); } /// @@ -1008,7 +1012,8 @@ public static Task SumAsync( Check.NotNull(source, nameof(source)); Check.NotNull(selector, nameof(selector)); - return ExecuteAsync>(QueryableMethods.GetSumWithSelector(typeof(int?)), source, selector, cancellationToken); + return ExecuteAsync>( + QueryableMethods.GetSumWithSelector(typeof(int?)), source, selector, cancellationToken); } /// @@ -1090,7 +1095,8 @@ public static Task SumAsync( Check.NotNull(source, nameof(source)); Check.NotNull(selector, nameof(selector)); - return ExecuteAsync>(QueryableMethods.GetSumWithSelector(typeof(long)), source, selector, cancellationToken); + return ExecuteAsync>( + QueryableMethods.GetSumWithSelector(typeof(long)), source, selector, cancellationToken); } /// @@ -1120,7 +1126,8 @@ public static Task SumAsync( Check.NotNull(source, nameof(source)); Check.NotNull(selector, nameof(selector)); - return ExecuteAsync>(QueryableMethods.GetSumWithSelector(typeof(long?)), source, selector, cancellationToken); + return ExecuteAsync>( + QueryableMethods.GetSumWithSelector(typeof(long?)), source, selector, cancellationToken); } /// @@ -1202,7 +1209,8 @@ public static Task SumAsync( Check.NotNull(source, nameof(source)); Check.NotNull(selector, nameof(selector)); - return ExecuteAsync>(QueryableMethods.GetSumWithSelector(typeof(double)), source, selector, cancellationToken); + return ExecuteAsync>( + QueryableMethods.GetSumWithSelector(typeof(double)), source, selector, cancellationToken); } /// @@ -1232,7 +1240,8 @@ public static Task SumAsync( Check.NotNull(source, nameof(source)); Check.NotNull(selector, nameof(selector)); - return ExecuteAsync>(QueryableMethods.GetSumWithSelector(typeof(double?)), source, selector, cancellationToken); + return ExecuteAsync>( + QueryableMethods.GetSumWithSelector(typeof(double?)), source, selector, cancellationToken); } /// @@ -1314,7 +1323,8 @@ public static Task SumAsync( Check.NotNull(source, nameof(source)); Check.NotNull(selector, nameof(selector)); - return ExecuteAsync>(QueryableMethods.GetSumWithSelector(typeof(float)), source, selector, cancellationToken); + return ExecuteAsync>( + QueryableMethods.GetSumWithSelector(typeof(float)), source, selector, cancellationToken); } /// @@ -1344,7 +1354,8 @@ public static Task SumAsync( Check.NotNull(source, nameof(source)); Check.NotNull(selector, nameof(selector)); - return ExecuteAsync>(QueryableMethods.GetSumWithSelector(typeof(float?)), source, selector, cancellationToken); + return ExecuteAsync>( + QueryableMethods.GetSumWithSelector(typeof(float?)), source, selector, cancellationToken); } #endregion @@ -1374,7 +1385,8 @@ public static Task AverageAsync( { Check.NotNull(source, nameof(source)); - return ExecuteAsync>(QueryableMethods.GetAverageWithoutSelector(typeof(decimal)), source, cancellationToken); + return ExecuteAsync>( + QueryableMethods.GetAverageWithoutSelector(typeof(decimal)), source, cancellationToken); } /// @@ -1400,7 +1412,8 @@ public static Task AverageAsync( { Check.NotNull(source, nameof(source)); - return ExecuteAsync>(QueryableMethods.GetAverageWithoutSelector(typeof(decimal?)), source, cancellationToken); + return ExecuteAsync>( + QueryableMethods.GetAverageWithoutSelector(typeof(decimal?)), source, cancellationToken); } /// @@ -1431,7 +1444,8 @@ public static Task AverageAsync( Check.NotNull(source, nameof(source)); Check.NotNull(selector, nameof(selector)); - return ExecuteAsync>(QueryableMethods.GetAverageWithSelector(typeof(decimal)), source, selector, cancellationToken); + return ExecuteAsync>( + QueryableMethods.GetAverageWithSelector(typeof(decimal)), source, selector, cancellationToken); } /// @@ -1462,7 +1476,8 @@ public static Task AverageAsync( Check.NotNull(source, nameof(source)); Check.NotNull(selector, nameof(selector)); - return ExecuteAsync>(QueryableMethods.GetAverageWithSelector(typeof(decimal?)), source, selector, cancellationToken); + return ExecuteAsync>( + QueryableMethods.GetAverageWithSelector(typeof(decimal?)), source, selector, cancellationToken); } /// @@ -1545,7 +1560,8 @@ public static Task AverageAsync( Check.NotNull(source, nameof(source)); Check.NotNull(selector, nameof(selector)); - return ExecuteAsync>(QueryableMethods.GetAverageWithSelector(typeof(int)), source, selector, cancellationToken); + return ExecuteAsync>( + QueryableMethods.GetAverageWithSelector(typeof(int)), source, selector, cancellationToken); } /// @@ -1576,7 +1592,8 @@ public static Task AverageAsync( Check.NotNull(source, nameof(source)); Check.NotNull(selector, nameof(selector)); - return ExecuteAsync>(QueryableMethods.GetAverageWithSelector(typeof(int?)), source, selector, cancellationToken); + return ExecuteAsync>( + QueryableMethods.GetAverageWithSelector(typeof(int?)), source, selector, cancellationToken); } /// @@ -1659,7 +1676,8 @@ public static Task AverageAsync( Check.NotNull(source, nameof(source)); Check.NotNull(selector, nameof(selector)); - return ExecuteAsync>(QueryableMethods.GetAverageWithSelector(typeof(long)), source, selector, cancellationToken); + return ExecuteAsync>( + QueryableMethods.GetAverageWithSelector(typeof(long)), source, selector, cancellationToken); } /// @@ -1690,7 +1708,8 @@ public static Task AverageAsync( Check.NotNull(source, nameof(source)); Check.NotNull(selector, nameof(selector)); - return ExecuteAsync>(QueryableMethods.GetAverageWithSelector(typeof(long?)), source, selector, cancellationToken); + return ExecuteAsync>( + QueryableMethods.GetAverageWithSelector(typeof(long?)), source, selector, cancellationToken); } /// @@ -1716,7 +1735,8 @@ public static Task AverageAsync( { Check.NotNull(source, nameof(source)); - return ExecuteAsync>(QueryableMethods.GetAverageWithoutSelector(typeof(double)), source, cancellationToken); + return ExecuteAsync>( + QueryableMethods.GetAverageWithoutSelector(typeof(double)), source, cancellationToken); } /// @@ -1742,7 +1762,8 @@ public static Task AverageAsync( { Check.NotNull(source, nameof(source)); - return ExecuteAsync>(QueryableMethods.GetAverageWithoutSelector(typeof(double?)), source, cancellationToken); + return ExecuteAsync>( + QueryableMethods.GetAverageWithoutSelector(typeof(double?)), source, cancellationToken); } /// @@ -1773,7 +1794,8 @@ public static Task AverageAsync( Check.NotNull(source, nameof(source)); Check.NotNull(selector, nameof(selector)); - return ExecuteAsync>(QueryableMethods.GetAverageWithSelector(typeof(double)), source, selector, cancellationToken); + return ExecuteAsync>( + QueryableMethods.GetAverageWithSelector(typeof(double)), source, selector, cancellationToken); } /// @@ -1804,7 +1826,8 @@ public static Task AverageAsync( Check.NotNull(source, nameof(source)); Check.NotNull(selector, nameof(selector)); - return ExecuteAsync>(QueryableMethods.GetAverageWithSelector(typeof(double?)), source, selector, cancellationToken); + return ExecuteAsync>( + QueryableMethods.GetAverageWithSelector(typeof(double?)), source, selector, cancellationToken); } /// @@ -1856,7 +1879,8 @@ public static Task AverageAsync( { Check.NotNull(source, nameof(source)); - return ExecuteAsync>(QueryableMethods.GetAverageWithoutSelector(typeof(float?)), source, cancellationToken); + return ExecuteAsync>( + QueryableMethods.GetAverageWithoutSelector(typeof(float?)), source, cancellationToken); } /// @@ -1887,7 +1911,8 @@ public static Task AverageAsync( Check.NotNull(source, nameof(source)); Check.NotNull(selector, nameof(selector)); - return ExecuteAsync>(QueryableMethods.GetAverageWithSelector(typeof(float)), source, selector, cancellationToken); + return ExecuteAsync>( + QueryableMethods.GetAverageWithSelector(typeof(float)), source, selector, cancellationToken); } /// @@ -1918,7 +1943,8 @@ public static Task AverageAsync( Check.NotNull(source, nameof(source)); Check.NotNull(selector, nameof(selector)); - return ExecuteAsync>(QueryableMethods.GetAverageWithSelector(typeof(float?)), source, selector, cancellationToken); + return ExecuteAsync>( + QueryableMethods.GetAverageWithSelector(typeof(float?)), source, selector, cancellationToken); } #endregion @@ -2188,7 +2214,8 @@ source.Provider is EntityQueryProvider ? source.Provider.CreateQuery( Expression.Call( instance: null, - method: ThenIncludeAfterEnumerableMethodInfo.MakeGenericMethod(typeof(TEntity), typeof(TPreviousProperty), typeof(TProperty)), + method: ThenIncludeAfterEnumerableMethodInfo.MakeGenericMethod( + typeof(TEntity), typeof(TPreviousProperty), typeof(TProperty)), arguments: new[] { source.Expression, Expression.Quote(navigationPropertyPath) })) : source); @@ -2252,7 +2279,8 @@ source.Provider is EntityQueryProvider ? source.Provider.CreateQuery( Expression.Call( instance: null, - method: ThenIncludeAfterReferenceMethodInfo.MakeGenericMethod(typeof(TEntity), typeof(TPreviousProperty), typeof(TProperty)), + method: ThenIncludeAfterReferenceMethodInfo.MakeGenericMethod( + typeof(TEntity), typeof(TPreviousProperty), typeof(TProperty)), arguments: new[] { source.Expression, Expression.Quote(navigationPropertyPath) })) : source); diff --git a/src/EFCore/Extensions/EntityTypeExtensions.cs b/src/EFCore/Extensions/EntityTypeExtensions.cs index fd792886bb6..2d90e0a59c7 100644 --- a/src/EFCore/Extensions/EntityTypeExtensions.cs +++ b/src/EFCore/Extensions/EntityTypeExtensions.cs @@ -118,7 +118,7 @@ public static bool IsAssignableFrom([NotNull] this IEntityType entityType, [NotN /// An entity type. /// Another entity type. /// - /// The closest common parent of and , + /// The closest common parent of and , /// or null if they have not common parent. /// public static IEntityType GetClosestCommonParent([NotNull] this IEntityType entityType1, [NotNull] IEntityType entityType2) @@ -453,10 +453,7 @@ public static IForeignKey FindForeignKey( [NotNull] IEntityType principalEntityType) => Check.NotNull(entityType, nameof(entityType)) .FindForeignKey( - new[] - { - property - }, principalKey, principalEntityType); + new[] { property }, principalKey, principalEntityType); /// /// Gets all foreign keys that target a given entity type (i.e. foreign keys where the given entity type diff --git a/src/EFCore/Extensions/Internal/EFPropertyExtensions.cs b/src/EFCore/Extensions/Internal/EFPropertyExtensions.cs index ac0d113594c..2f0f33413b1 100644 --- a/src/EFCore/Extensions/Internal/EFPropertyExtensions.cs +++ b/src/EFCore/Extensions/Internal/EFPropertyExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Extensions/Internal/ExpressionExtensions.cs b/src/EFCore/Extensions/Internal/ExpressionExtensions.cs index a60ac856ea2..4d8a53a70a9 100644 --- a/src/EFCore/Extensions/Internal/ExpressionExtensions.cs +++ b/src/EFCore/Extensions/Internal/ExpressionExtensions.cs @@ -153,10 +153,10 @@ public static bool IsEntityQueryable([NotNull] this ConstantExpression constantE /// public static LambdaExpression GetLambdaOrNull(this Expression expression) => expression is LambdaExpression lambda - ? lambda - : expression is UnaryExpression unary && expression.NodeType == ExpressionType.Quote - ? (LambdaExpression)unary.Operand - : null; + ? lambda + : expression is UnaryExpression unary && expression.NodeType == ExpressionType.Quote + ? (LambdaExpression)unary.Operand + : null; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -166,7 +166,7 @@ public static LambdaExpression GetLambdaOrNull(this Expression expression) /// public static LambdaExpression UnwrapLambdaFromQuote(this Expression expression) => (LambdaExpression)(expression is UnaryExpression unary && expression.NodeType == ExpressionType.Quote - ? unary.Operand - : expression); + ? unary.Operand + : expression); } } diff --git a/src/EFCore/Extensions/Internal/MethodInfoExtensions.cs b/src/EFCore/Extensions/Internal/MethodInfoExtensions.cs index aa331ec133c..975e3938a30 100644 --- a/src/EFCore/Extensions/Internal/MethodInfoExtensions.cs +++ b/src/EFCore/Extensions/Internal/MethodInfoExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Diagnostics; diff --git a/src/EFCore/Extensions/Internal/QueryableExtensions.cs b/src/EFCore/Extensions/Internal/QueryableExtensions.cs index c952d5c0247..23a1d30dadc 100644 --- a/src/EFCore/Extensions/Internal/QueryableExtensions.cs +++ b/src/EFCore/Extensions/Internal/QueryableExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -19,8 +19,7 @@ namespace Microsoft.EntityFrameworkCore.Internal public static class QueryableExtensions { internal static readonly MethodInfo LeftJoinMethodInfo = typeof(QueryableExtensions).GetTypeInfo() - .GetDeclaredMethods(nameof(QueryableExtensions.LeftJoin)).Single(mi => mi.GetParameters().Length == 5); - + .GetDeclaredMethods(nameof(LeftJoin)).Single(mi => mi.GetParameters().Length == 5); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore/Extensions/Internal/TypeExtensions.cs b/src/EFCore/Extensions/Internal/TypeExtensions.cs index 9e0e50de72b..8b74bdfe446 100644 --- a/src/EFCore/Extensions/Internal/TypeExtensions.cs +++ b/src/EFCore/Extensions/Internal/TypeExtensions.cs @@ -7,7 +7,6 @@ using System.Reflection; using System.Text; using JetBrains.Annotations; -using Microsoft.EntityFrameworkCore.Query; // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore.Internal @@ -206,7 +205,8 @@ public static string GenerateParameterName(this Type type) /// public static bool IsQueryableType(this Type type) { - if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IQueryable<>)) + if (type.IsGenericType + && type.GetGenericTypeDefinition() == typeof(IQueryable<>)) { return true; } diff --git a/src/EFCore/Extensions/MutableEntityTypeExtensions.cs b/src/EFCore/Extensions/MutableEntityTypeExtensions.cs index f620c002aed..015d7df7b3a 100644 --- a/src/EFCore/Extensions/MutableEntityTypeExtensions.cs +++ b/src/EFCore/Extensions/MutableEntityTypeExtensions.cs @@ -272,7 +272,7 @@ public static IMutableForeignKey FindForeignKey( } /// - /// Gets the foreign keys declared on the given using the given properties. + /// Gets the foreign keys declared on the given using the given properties. /// /// The entity type. /// The properties to find the foreign keys on. @@ -394,7 +394,7 @@ public static IMutableNavigation FindDefiningNavigation([NotNull] this IMutableE /// The entity type to get navigation properties for. /// All navigation properties on the given entity type. public static IEnumerable GetNavigations([NotNull] this IMutableEntityType entityType) - => ((EntityType)entityType).GetNavigations(); + => ((EntityType)entityType).GetNavigations(); /// /// diff --git a/src/EFCore/Extensions/MutableModelExtensions.cs b/src/EFCore/Extensions/MutableModelExtensions.cs index c88e1fa2561..37e675c8246 100644 --- a/src/EFCore/Extensions/MutableModelExtensions.cs +++ b/src/EFCore/Extensions/MutableModelExtensions.cs @@ -239,7 +239,7 @@ public static void RemoveOwned([NotNull] this IMutableModel model, [NotNull] Typ /// /// Forces post-processing on the model such that it is ready for use by the runtime. This post - /// processing happens automatically when using ; this method allows it to be run + /// processing happens automatically when using ; this method allows it to be run /// explicitly in cases where the automatic execution is not possible. /// /// The model to finalize. diff --git a/src/EFCore/Extensions/TransactionsDatabaseFacadeExtensions.cs b/src/EFCore/Extensions/TransactionsDatabaseFacadeExtensions.cs index 021c147c1e5..c0faf162365 100644 --- a/src/EFCore/Extensions/TransactionsDatabaseFacadeExtensions.cs +++ b/src/EFCore/Extensions/TransactionsDatabaseFacadeExtensions.cs @@ -26,7 +26,8 @@ public static class TransactionsDatabaseFacadeExtensions public static void EnlistTransaction([NotNull] this DatabaseFacade databaseFacade, [CanBeNull] Transaction transaction) { Check.NotNull(databaseFacade, nameof(databaseFacade)); - if (((IDatabaseFacadeDependenciesAccessor)databaseFacade).Dependencies.TransactionManager is ITransactionEnlistmentManager transactionManager) + if (((IDatabaseFacadeDependenciesAccessor)databaseFacade).Dependencies.TransactionManager is ITransactionEnlistmentManager + transactionManager) { transactionManager.EnlistTransaction(transaction); } @@ -44,7 +45,8 @@ public static void EnlistTransaction([NotNull] this DatabaseFacade databaseFacad public static Transaction GetEnlistedTransaction([NotNull] this DatabaseFacade databaseFacade) { Check.NotNull(databaseFacade, nameof(databaseFacade)); - if (((IDatabaseFacadeDependenciesAccessor)databaseFacade).Dependencies.TransactionManager is ITransactionEnlistmentManager transactionManager) + if (((IDatabaseFacadeDependenciesAccessor)databaseFacade).Dependencies.TransactionManager is ITransactionEnlistmentManager + transactionManager) { return transactionManager.EnlistedTransaction; } diff --git a/src/EFCore/IQueryTypeConfiguration.cs b/src/EFCore/IQueryTypeConfiguration.cs index b143503f8ed..68c377d69a0 100644 --- a/src/EFCore/IQueryTypeConfiguration.cs +++ b/src/EFCore/IQueryTypeConfiguration.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Infrastructure/AccessorExtensions.cs b/src/EFCore/Infrastructure/AccessorExtensions.cs index 127234974f9..881003a1a81 100644 --- a/src/EFCore/Infrastructure/AccessorExtensions.cs +++ b/src/EFCore/Infrastructure/AccessorExtensions.cs @@ -5,7 +5,6 @@ using System.Diagnostics; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure.Internal; -using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Infrastructure diff --git a/src/EFCore/Infrastructure/Annotatable.cs b/src/EFCore/Infrastructure/Annotatable.cs index e759a22824a..ebafcb64e66 100644 --- a/src/EFCore/Infrastructure/Annotatable.cs +++ b/src/EFCore/Infrastructure/Annotatable.cs @@ -73,7 +73,7 @@ public virtual void SetAnnotation(string name, object value) { var oldAnnotation = FindAnnotation(name); if (oldAnnotation != null - && Equals(oldAnnotation.Value, value)) + && Equals(oldAnnotation.Value, value)) { return; } diff --git a/src/EFCore/Infrastructure/CoreOptionsExtension.cs b/src/EFCore/Infrastructure/CoreOptionsExtension.cs index 5a3a32ce512..bd1ec68f448 100644 --- a/src/EFCore/Infrastructure/CoreOptionsExtension.cs +++ b/src/EFCore/Infrastructure/CoreOptionsExtension.cs @@ -82,7 +82,7 @@ protected CoreOptionsExtension([NotNull] CoreOptionsExtension copyFrom) } /// - /// Information/metadata about the extension. + /// Information/metadata about the extension. /// public virtual DbContextOptionsExtensionInfo Info => _info ??= new ExtensionInfo(this); diff --git a/src/EFCore/Infrastructure/DbContextOptionsExtensionInfo.cs b/src/EFCore/Infrastructure/DbContextOptionsExtensionInfo.cs index 4cc1dd3483d..4867dc5ba53 100644 --- a/src/EFCore/Infrastructure/DbContextOptionsExtensionInfo.cs +++ b/src/EFCore/Infrastructure/DbContextOptionsExtensionInfo.cs @@ -8,7 +8,7 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure { /// - /// Information/metadata for an . + /// Information/metadata for an . /// public abstract class DbContextOptionsExtensionInfo { diff --git a/src/EFCore/Infrastructure/EntityFrameworkServicesBuilder.cs b/src/EFCore/Infrastructure/EntityFrameworkServicesBuilder.cs index 620027f712c..bb7df6d5cae 100644 --- a/src/EFCore/Infrastructure/EntityFrameworkServicesBuilder.cs +++ b/src/EFCore/Infrastructure/EntityFrameworkServicesBuilder.cs @@ -131,8 +131,12 @@ public static readonly IDictionary CoreServices { typeof(IQueryContextFactory), new ServiceCharacteristics(ServiceLifetime.Scoped) }, { typeof(IQueryCompilationContextFactory), new ServiceCharacteristics(ServiceLifetime.Scoped) }, { typeof(ILazyLoader), new ServiceCharacteristics(ServiceLifetime.Transient) }, - { typeof(IParameterBindingFactory), new ServiceCharacteristics(ServiceLifetime.Singleton, multipleRegistrations: true) }, - { typeof(ITypeMappingSourcePlugin), new ServiceCharacteristics(ServiceLifetime.Singleton, multipleRegistrations: true) }, + { + typeof(IParameterBindingFactory), new ServiceCharacteristics(ServiceLifetime.Singleton, multipleRegistrations: true) + }, + { + typeof(ITypeMappingSourcePlugin), new ServiceCharacteristics(ServiceLifetime.Singleton, multipleRegistrations: true) + }, { typeof(ISingletonOptions), new ServiceCharacteristics(ServiceLifetime.Singleton, multipleRegistrations: true) }, { typeof(IConventionSetPlugin), new ServiceCharacteristics(ServiceLifetime.Scoped, multipleRegistrations: true) }, { typeof(IResettableService), new ServiceCharacteristics(ServiceLifetime.Scoped, multipleRegistrations: true) } diff --git a/src/EFCore/Infrastructure/ExpressionExtensions.cs b/src/EFCore/Infrastructure/ExpressionExtensions.cs index efc797c9aa0..dedb580b49f 100644 --- a/src/EFCore/Infrastructure/ExpressionExtensions.cs +++ b/src/EFCore/Infrastructure/ExpressionExtensions.cs @@ -73,10 +73,7 @@ public static Expression Assign( _assignBinaryExpressionType, BindingFlags.NonPublic | BindingFlags.Instance, null, - new object[] - { - memberExpression, valueExpression - }, + new object[] { memberExpression, valueExpression }, null); } diff --git a/src/EFCore/Infrastructure/IConcurrencyDetector.cs b/src/EFCore/Infrastructure/IConcurrencyDetector.cs index 543d40ea17e..b1f194b4496 100644 --- a/src/EFCore/Infrastructure/IConcurrencyDetector.cs +++ b/src/EFCore/Infrastructure/IConcurrencyDetector.cs @@ -12,8 +12,8 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure /// resources. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -21,7 +21,7 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure public interface IConcurrencyDetector { /// - /// Call to enter the critical section. + /// Call to enter the critical section. /// /// A disposer that will exit the critical section when disposed. IDisposable EnterCriticalSection(); diff --git a/src/EFCore/Infrastructure/ICoreSingletonOptions.cs b/src/EFCore/Infrastructure/ICoreSingletonOptions.cs index 0f681586889..873705294f2 100644 --- a/src/EFCore/Infrastructure/ICoreSingletonOptions.cs +++ b/src/EFCore/Infrastructure/ICoreSingletonOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -11,9 +11,9 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure /// Options set at the singleton level to control core options. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface ICoreSingletonOptions : ISingletonOptions diff --git a/src/EFCore/Infrastructure/ICurrentDbContext.cs b/src/EFCore/Infrastructure/ICurrentDbContext.cs index 639f678ef27..7c52d4974f1 100644 --- a/src/EFCore/Infrastructure/ICurrentDbContext.cs +++ b/src/EFCore/Infrastructure/ICurrentDbContext.cs @@ -8,15 +8,15 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure /// /// /// Registered as a scoped service in Entity Framework's internal service provider to provide access - /// to the current being used. + /// to the current being used. /// /// /// This type is typically used by database providers (and other extensions). It is generally /// not used in application code. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -24,7 +24,7 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure public interface ICurrentDbContext { /// - /// The currently being used. + /// The currently being used. /// DbContext Context { get; } } diff --git a/src/EFCore/Infrastructure/IDbContextOptions.cs b/src/EFCore/Infrastructure/IDbContextOptions.cs index 93e98cdf274..b285c7d63eb 100644 --- a/src/EFCore/Infrastructure/IDbContextOptions.cs +++ b/src/EFCore/Infrastructure/IDbContextOptions.cs @@ -14,8 +14,8 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure /// in your application code. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/Infrastructure/IModelCacheKeyFactory.cs b/src/EFCore/Infrastructure/IModelCacheKeyFactory.cs index 8889ae8ab8b..3fc3ffb4837 100644 --- a/src/EFCore/Infrastructure/IModelCacheKeyFactory.cs +++ b/src/EFCore/Infrastructure/IModelCacheKeyFactory.cs @@ -16,9 +16,9 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure /// not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IModelCacheKeyFactory diff --git a/src/EFCore/Infrastructure/IModelCustomizer.cs b/src/EFCore/Infrastructure/IModelCustomizer.cs index ae4faba97a0..365d25d5e66 100644 --- a/src/EFCore/Infrastructure/IModelCustomizer.cs +++ b/src/EFCore/Infrastructure/IModelCustomizer.cs @@ -19,9 +19,9 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure /// 'RelationalModelCustomizer' to preserve the default behavior. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IModelCustomizer diff --git a/src/EFCore/Infrastructure/IModelSource.cs b/src/EFCore/Infrastructure/IModelSource.cs index b83faf9f885..1d6ae451f7c 100644 --- a/src/EFCore/Infrastructure/IModelSource.cs +++ b/src/EFCore/Infrastructure/IModelSource.cs @@ -18,9 +18,9 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure /// not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IModelSource diff --git a/src/EFCore/Infrastructure/IModelValidator.cs b/src/EFCore/Infrastructure/IModelValidator.cs index 8a871d9ebbb..0607223ab59 100644 --- a/src/EFCore/Infrastructure/IModelValidator.cs +++ b/src/EFCore/Infrastructure/IModelValidator.cs @@ -13,9 +13,9 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure /// Validates a model after it is built. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IModelValidator diff --git a/src/EFCore/Infrastructure/IResettableService.cs b/src/EFCore/Infrastructure/IResettableService.cs index 2dfeeb496b9..c77cb2b0173 100644 --- a/src/EFCore/Infrastructure/IResettableService.cs +++ b/src/EFCore/Infrastructure/IResettableService.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading; @@ -17,8 +17,8 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure /// not used in application code. /// /// - /// The service lifetime is and multiple registrations - /// are allowed. This means that each instance will use its own + /// The service lifetime is and multiple registrations + /// are allowed. This means that each instance will use its own /// set of instances of this service. /// The implementations may depend on other services registered with any lifetime. /// The implementations do not need to be thread-safe. diff --git a/src/EFCore/Infrastructure/ISingletonOptions.cs b/src/EFCore/Infrastructure/ISingletonOptions.cs index 36a854c8b1c..2bfa3cdb92c 100644 --- a/src/EFCore/Infrastructure/ISingletonOptions.cs +++ b/src/EFCore/Infrastructure/ISingletonOptions.cs @@ -13,10 +13,10 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure /// singleton level. /// /// - /// The service lifetime is and multiple registrations - /// are allowed. This means a single instance of each service is used by many + /// The service lifetime is and multiple registrations + /// are allowed. This means a single instance of each service is used by many /// instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public interface ISingletonOptions diff --git a/src/EFCore/Infrastructure/Internal/DbContextOptionsExtensions.cs b/src/EFCore/Infrastructure/Internal/DbContextOptionsExtensions.cs index 35fdd0fef1e..15351e562aa 100644 --- a/src/EFCore/Infrastructure/Internal/DbContextOptionsExtensions.cs +++ b/src/EFCore/Infrastructure/Internal/DbContextOptionsExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Text; diff --git a/src/EFCore/Infrastructure/ModelCacheKeyFactory.cs b/src/EFCore/Infrastructure/ModelCacheKeyFactory.cs index 5629eecca25..694f2028735 100644 --- a/src/EFCore/Infrastructure/ModelCacheKeyFactory.cs +++ b/src/EFCore/Infrastructure/ModelCacheKeyFactory.cs @@ -18,9 +18,9 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure /// not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class ModelCacheKeyFactory : IModelCacheKeyFactory diff --git a/src/EFCore/Infrastructure/ModelCacheKeyFactoryDependencies.cs b/src/EFCore/Infrastructure/ModelCacheKeyFactoryDependencies.cs index 879dd5e96e2..3df41cb9513 100644 --- a/src/EFCore/Infrastructure/ModelCacheKeyFactoryDependencies.cs +++ b/src/EFCore/Infrastructure/ModelCacheKeyFactoryDependencies.cs @@ -22,10 +22,10 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . - /// This means a single instance of each service is used by many instances. + /// The service lifetime is . + /// This means a single instance of each service is used by many instances. /// The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public sealed class ModelCacheKeyFactoryDependencies diff --git a/src/EFCore/Infrastructure/ModelCustomizer.cs b/src/EFCore/Infrastructure/ModelCustomizer.cs index 736b6ab4913..8b390ac0315 100644 --- a/src/EFCore/Infrastructure/ModelCustomizer.cs +++ b/src/EFCore/Infrastructure/ModelCustomizer.cs @@ -17,9 +17,9 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure /// not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class ModelCustomizer : IModelCustomizer diff --git a/src/EFCore/Infrastructure/ModelCustomizerDependencies.cs b/src/EFCore/Infrastructure/ModelCustomizerDependencies.cs index 22a978a84bf..d6e289b635a 100644 --- a/src/EFCore/Infrastructure/ModelCustomizerDependencies.cs +++ b/src/EFCore/Infrastructure/ModelCustomizerDependencies.cs @@ -25,10 +25,10 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . - /// This means a single instance of each service is used by many instances. + /// The service lifetime is . + /// This means a single instance of each service is used by many instances. /// The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public sealed class ModelCustomizerDependencies diff --git a/src/EFCore/Infrastructure/ModelSource.cs b/src/EFCore/Infrastructure/ModelSource.cs index 8857954db9f..90f6c2a462e 100644 --- a/src/EFCore/Infrastructure/ModelSource.cs +++ b/src/EFCore/Infrastructure/ModelSource.cs @@ -23,9 +23,9 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure /// not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class ModelSource : IModelSource @@ -34,7 +34,7 @@ private readonly ConcurrentDictionary> _models = new ConcurrentDictionary>(); /// - /// Creates a new instance. + /// Creates a new instance. /// /// The dependencies to use. public ModelSource([NotNull] ModelSourceDependencies dependencies) diff --git a/src/EFCore/Infrastructure/ModelSourceDependencies.cs b/src/EFCore/Infrastructure/ModelSourceDependencies.cs index 4bf34ff7e80..84a3db370e9 100644 --- a/src/EFCore/Infrastructure/ModelSourceDependencies.cs +++ b/src/EFCore/Infrastructure/ModelSourceDependencies.cs @@ -24,10 +24,10 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . - /// This means a single instance of each service is used by many instances. + /// The service lifetime is . + /// This means a single instance of each service is used by many instances. /// The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public sealed class ModelSourceDependencies diff --git a/src/EFCore/Infrastructure/ModelValidator.cs b/src/EFCore/Infrastructure/ModelValidator.cs index 587bdaad6e3..517bfe77eb4 100644 --- a/src/EFCore/Infrastructure/ModelValidator.cs +++ b/src/EFCore/Infrastructure/ModelValidator.cs @@ -82,7 +82,8 @@ public virtual void Validate(IModel model, IDiagnosticsLogger /// The model. /// The logger to use. - protected virtual void ValidateRelationships([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void ValidateRelationships( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { Check.NotNull(model, nameof(model)); @@ -112,7 +113,8 @@ protected virtual void ValidateRelationships([NotNull] IModel model, [NotNull] I /// /// The model. /// The logger to use. - protected virtual void ValidatePropertyMapping([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void ValidatePropertyMapping( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { Check.NotNull(model, nameof(model)); @@ -189,7 +191,8 @@ var isTargetWeakOrOwned if ((!entityType.IsKeyless || targetSequenceType == null) && entityType.GetDerivedTypes().All( - dt => dt.GetDeclaredNavigations().FirstOrDefault(n => n.Name == actualProperty.GetSimpleMemberName()) == null) + dt => dt.GetDeclaredNavigations().FirstOrDefault(n => n.Name == actualProperty.GetSimpleMemberName()) + == null) && (!isTargetWeakOrOwned || (!targetType.Equals(entityType.ClrType) && (!entityType.IsInOwnershipPath(targetType) @@ -203,7 +206,8 @@ var isTargetWeakOrOwned && conventionModel.IsOwned(targetType)) { throw new InvalidOperationException( - CoreStrings.AmbiguousOwnedNavigation(entityType.ClrType.ShortDisplayName(), targetType.ShortDisplayName())); + CoreStrings.AmbiguousOwnedNavigation( + entityType.ClrType.ShortDisplayName(), targetType.ShortDisplayName())); } throw new InvalidOperationException( @@ -238,7 +242,8 @@ private Type FindCandidateNavigationPropertyType(PropertyInfo propertyInfo) /// /// The model. /// The logger to use. - protected virtual void ValidateIgnoredMembers([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void ValidateIgnoredMembers( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { Check.NotNull(model, nameof(model)); @@ -290,7 +295,8 @@ protected virtual void ValidateIgnoredMembers([NotNull] IModel model, [NotNull] /// /// The model to validate. /// The logger to use. - protected virtual void ValidateNoShadowEntities([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void ValidateNoShadowEntities( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { Check.NotNull(model, nameof(model)); @@ -307,7 +313,8 @@ protected virtual void ValidateNoShadowEntities([NotNull] IModel model, [NotNull /// /// The model to validate. /// The logger to use. - protected virtual void ValidateNoShadowKeys([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void ValidateNoShadowKeys( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { Check.NotNull(model, nameof(model)); @@ -347,7 +354,8 @@ protected virtual void ValidateNoShadowKeys([NotNull] IModel model, [NotNull] ID /// /// The model to validate. /// The logger to use. - protected virtual void ValidateNoMutableKeys([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void ValidateNoMutableKeys( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { Check.NotNull(model, nameof(model)); @@ -369,7 +377,8 @@ protected virtual void ValidateNoMutableKeys([NotNull] IModel model, [NotNull] I /// /// The model to validate. /// The logger to use. - protected virtual void ValidateNoCycles([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void ValidateNoCycles( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { Check.NotNull(model, nameof(model)); @@ -414,7 +423,8 @@ protected virtual void ValidateNoCycles([NotNull] IModel model, [NotNull] IDiagn /// /// The model to validate. /// The logger to use. - protected virtual void ValidateNonNullPrimaryKeys([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void ValidateNonNullPrimaryKeys( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { Check.NotNull(model, nameof(model)); @@ -434,7 +444,8 @@ var entityTypeWithNullPk /// /// The model to validate. /// The logger to use. - protected virtual void ValidateClrInheritance([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void ValidateClrInheritance( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { Check.NotNull(model, nameof(model)); @@ -497,7 +508,8 @@ private void ValidateClrInheritance( /// /// The model to validate. /// The logger to use. - protected virtual void ValidateDiscriminatorValues([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void ValidateDiscriminatorValues( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { foreach (var rootEntityType in model.GetRootEntityTypes()) { @@ -550,7 +562,8 @@ private static void ValidateDiscriminatorValues(IEntityType rootEntityType) /// /// The model to validate. /// The logger to use. - protected virtual void ValidateChangeTrackingStrategy([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void ValidateChangeTrackingStrategy( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { Check.NotNull(model, nameof(model)); @@ -569,7 +582,8 @@ protected virtual void ValidateChangeTrackingStrategy([NotNull] IModel model, [N /// /// The model to validate. /// The logger to use. - protected virtual void ValidateOwnership([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void ValidateOwnership( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { Check.NotNull(model, nameof(model)); @@ -619,7 +633,8 @@ protected virtual void ValidateOwnership([NotNull] IModel model, [NotNull] IDiag ownership.PrincipalEntityType.DisplayName())); } } - else if (entityType.HasClrType() && ((IMutableModel)model).IsOwned(entityType.ClrType)) + else if (entityType.HasClrType() + && ((IMutableModel)model).IsOwned(entityType.ClrType)) { throw new InvalidOperationException(CoreStrings.OwnerlessOwnedType(entityType.DisplayName())); } @@ -636,7 +651,8 @@ private bool Contains(IForeignKey inheritedFk, IForeignKey derivedFk) /// /// The model to validate. /// The logger to use. - protected virtual void ValidateForeignKeys([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void ValidateForeignKeys( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { Check.NotNull(model, nameof(model)); @@ -685,7 +701,8 @@ protected virtual void ValidateForeignKeys([NotNull] IModel model, [NotNull] IDi /// /// The model to validate. /// The logger to use. - protected virtual void ValidateDefiningNavigations([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void ValidateDefiningNavigations( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { Check.NotNull(model, nameof(model)); @@ -735,7 +752,8 @@ protected virtual void ValidateDefiningNavigations([NotNull] IModel model, [NotN /// /// The model to validate. /// The logger to use. - protected virtual void ValidateFieldMapping([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void ValidateFieldMapping( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { Check.NotNull(model, nameof(model)); @@ -795,7 +813,8 @@ protected virtual void ValidateFieldMapping([NotNull] IModel model, [NotNull] ID /// /// The model to validate. /// The logger to use. - protected virtual void ValidateKeylessTypes([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void ValidateKeylessTypes( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { Check.NotNull(model, nameof(model)); @@ -823,7 +842,8 @@ protected virtual void ValidateKeylessTypes([NotNull] IModel model, [NotNull] ID /// /// The model to validate. /// The logger to use. - protected virtual void ValidateQueryFilters([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void ValidateQueryFilters( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { Check.NotNull(model, nameof(model)); @@ -994,7 +1014,8 @@ protected virtual void ValidateData([NotNull] IModel model, [NotNull] IDiagnosti /// /// The model to validate. /// The logger to use. - protected virtual void LogShadowProperties([NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) + protected virtual void LogShadowProperties( + [NotNull] IModel model, [NotNull] IDiagnosticsLogger logger) { Check.NotNull(model, nameof(model)); diff --git a/src/EFCore/Infrastructure/ModelValidatorDependencies.cs b/src/EFCore/Infrastructure/ModelValidatorDependencies.cs index a6e7197bec7..2e0c97eeccd 100644 --- a/src/EFCore/Infrastructure/ModelValidatorDependencies.cs +++ b/src/EFCore/Infrastructure/ModelValidatorDependencies.cs @@ -26,10 +26,10 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . - /// This means a single instance of each service is used by many instances. + /// The service lifetime is . + /// This means a single instance of each service is used by many instances. /// The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public sealed class ModelValidatorDependencies diff --git a/src/EFCore/Infrastructure/TypeExtensions.cs b/src/EFCore/Infrastructure/TypeExtensions.cs index 2549c02a2ee..8b19379fce5 100644 --- a/src/EFCore/Infrastructure/TypeExtensions.cs +++ b/src/EFCore/Infrastructure/TypeExtensions.cs @@ -9,7 +9,7 @@ namespace Microsoft.EntityFrameworkCore.Infrastructure { /// /// - /// Extension methods for instances. + /// Extension methods for instances. /// /// /// These extensions are typically used by database providers (and other extensions). They are generally diff --git a/src/EFCore/Infrastructure/Uniquifier.cs b/src/EFCore/Infrastructure/Uniquifier.cs index 1c4aa34d507..5b2b32b76e4 100644 --- a/src/EFCore/Infrastructure/Uniquifier.cs +++ b/src/EFCore/Infrastructure/Uniquifier.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Internal/ConcurrencyDetector.cs b/src/EFCore/Internal/ConcurrencyDetector.cs index 928f2bfed9d..33cc17b0473 100644 --- a/src/EFCore/Internal/ConcurrencyDetector.cs +++ b/src/EFCore/Internal/ConcurrencyDetector.cs @@ -18,8 +18,8 @@ namespace Microsoft.EntityFrameworkCore.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/Internal/CoreOptions.cs b/src/EFCore/Internal/CoreOptions.cs index 6f5c7c30883..955c2c6254f 100644 --- a/src/EFCore/Internal/CoreOptions.cs +++ b/src/EFCore/Internal/CoreOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -17,9 +17,9 @@ namespace Microsoft.EntityFrameworkCore.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class CoreSingletonOptions : ICoreSingletonOptions diff --git a/src/EFCore/Internal/CurrentDbContext.cs b/src/EFCore/Internal/CurrentDbContext.cs index 5b2a517fee8..c1655b717e0 100644 --- a/src/EFCore/Internal/CurrentDbContext.cs +++ b/src/EFCore/Internal/CurrentDbContext.cs @@ -16,8 +16,8 @@ namespace Microsoft.EntityFrameworkCore.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/Internal/DbContextPool.cs b/src/EFCore/Internal/DbContextPool.cs index 8b5c4848a50..5c4aed8d890 100644 --- a/src/EFCore/Internal/DbContextPool.cs +++ b/src/EFCore/Internal/DbContextPool.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Internal/DbContextPoolConfigurationSnapshot.cs b/src/EFCore/Internal/DbContextPoolConfigurationSnapshot.cs index fadd5cd866c..b2d518639bb 100644 --- a/src/EFCore/Internal/DbContextPoolConfigurationSnapshot.cs +++ b/src/EFCore/Internal/DbContextPoolConfigurationSnapshot.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.ChangeTracking; diff --git a/src/EFCore/Internal/DbContextServices.cs b/src/EFCore/Internal/DbContextServices.cs index e89d192f6c3..fdbab321a49 100644 --- a/src/EFCore/Internal/DbContextServices.cs +++ b/src/EFCore/Internal/DbContextServices.cs @@ -21,8 +21,8 @@ namespace Microsoft.EntityFrameworkCore.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/Internal/DbSetFinder.cs b/src/EFCore/Internal/DbSetFinder.cs index ef55bb6ca67..953bef610e0 100644 --- a/src/EFCore/Internal/DbSetFinder.cs +++ b/src/EFCore/Internal/DbSetFinder.cs @@ -19,9 +19,9 @@ namespace Microsoft.EntityFrameworkCore.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class DbSetFinder : IDbSetFinder diff --git a/src/EFCore/Internal/DbSetInitializer.cs b/src/EFCore/Internal/DbSetInitializer.cs index 00999f376b3..f5b168d643a 100644 --- a/src/EFCore/Internal/DbSetInitializer.cs +++ b/src/EFCore/Internal/DbSetInitializer.cs @@ -15,9 +15,9 @@ namespace Microsoft.EntityFrameworkCore.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class DbSetInitializer : IDbSetInitializer diff --git a/src/EFCore/Internal/DbSetProperty.cs b/src/EFCore/Internal/DbSetProperty.cs index 06a4f8be786..68fd6bb2b43 100644 --- a/src/EFCore/Internal/DbSetProperty.cs +++ b/src/EFCore/Internal/DbSetProperty.cs @@ -4,7 +4,6 @@ using System; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Metadata.Internal; namespace Microsoft.EntityFrameworkCore.Internal { diff --git a/src/EFCore/Internal/DbSetSource.cs b/src/EFCore/Internal/DbSetSource.cs index 19aff53d9bb..f0358b2089d 100644 --- a/src/EFCore/Internal/DbSetSource.cs +++ b/src/EFCore/Internal/DbSetSource.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -17,9 +17,9 @@ namespace Microsoft.EntityFrameworkCore.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class DbSetSource : IDbSetSource diff --git a/src/EFCore/Internal/DiagnosticsLogger.cs b/src/EFCore/Internal/DiagnosticsLogger.cs index 9f329670b96..f67d913b9d5 100644 --- a/src/EFCore/Internal/DiagnosticsLogger.cs +++ b/src/EFCore/Internal/DiagnosticsLogger.cs @@ -17,8 +17,8 @@ namespace Microsoft.EntityFrameworkCore.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/Internal/EntityFinder.cs b/src/EFCore/Internal/EntityFinder.cs index 70d6ba9570a..2d87043a011 100644 --- a/src/EFCore/Internal/EntityFinder.cs +++ b/src/EFCore/Internal/EntityFinder.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -82,7 +82,8 @@ object IEntityFinder.Find(object[] keyValues) /// public virtual ValueTask FindAsync(object[] keyValues, CancellationToken cancellationToken = default) { - if (keyValues == null || keyValues.Any(v => v == null)) + if (keyValues == null + || keyValues.Any(v => v == null)) { return new ValueTask((TEntity)null); } @@ -90,7 +91,8 @@ public virtual ValueTask FindAsync(object[] keyValues, CancellationToke var tracked = FindTracked(keyValues, out var keyProperties); return tracked != null ? new ValueTask(tracked) - : new ValueTask(_queryRoot.FirstOrDefaultAsync(BuildLambda(keyProperties, new ValueBuffer(keyValues)), cancellationToken)); + : new ValueTask( + _queryRoot.FirstOrDefaultAsync(BuildLambda(keyProperties, new ValueBuffer(keyValues)), cancellationToken)); } /// @@ -101,7 +103,8 @@ public virtual ValueTask FindAsync(object[] keyValues, CancellationToke /// ValueTask IEntityFinder.FindAsync(object[] keyValues, CancellationToken cancellationToken) { - if (keyValues == null || keyValues.Any(v => v == null)) + if (keyValues == null + || keyValues.Any(v => v == null)) { return new ValueTask((object)null); } @@ -109,8 +112,9 @@ ValueTask IEntityFinder.FindAsync(object[] keyValues, CancellationToken var tracked = FindTracked(keyValues, out var keyProperties); return tracked != null ? new ValueTask(tracked) - : new ValueTask(_queryRoot.FirstOrDefaultAsync( - BuildObjectLambda(keyProperties, new ValueBuffer(keyValues)), cancellationToken)); + : new ValueTask( + _queryRoot.FirstOrDefaultAsync( + BuildObjectLambda(keyProperties, new ValueBuffer(keyValues)), cancellationToken)); } /// @@ -219,6 +223,7 @@ private IQueryable GetDatabaseValuesQuery(InternalEntityEntry entry) { return null; } + keyValues[i] = keyValue; } @@ -254,6 +259,7 @@ private static object[] GetLoadValues(INavigation navigation, InternalEntityEntr { return null; } + values[i] = value; } diff --git a/src/EFCore/Internal/EntityFinderSource.cs b/src/EFCore/Internal/EntityFinderSource.cs index 196c4c48b91..6483747f988 100644 --- a/src/EFCore/Internal/EntityFinderSource.cs +++ b/src/EFCore/Internal/EntityFinderSource.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -19,9 +19,9 @@ namespace Microsoft.EntityFrameworkCore.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class EntityFinderSource : IEntityFinderSource diff --git a/src/EFCore/Internal/Graph.cs b/src/EFCore/Internal/Graph.cs index 740b9688d34..a5b0978ffdf 100644 --- a/src/EFCore/Internal/Graph.cs +++ b/src/EFCore/Internal/Graph.cs @@ -28,7 +28,7 @@ public abstract class Graph /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public abstract IEnumerable GetOutgoingNeighbors([NotNull] TVertex @from); + public abstract IEnumerable GetOutgoingNeighbors([NotNull] TVertex from); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore/Internal/IDatabaseFacadeDependencies.cs b/src/EFCore/Internal/IDatabaseFacadeDependencies.cs index 117ed76dd0c..9691b309f1d 100644 --- a/src/EFCore/Internal/IDatabaseFacadeDependencies.cs +++ b/src/EFCore/Internal/IDatabaseFacadeDependencies.cs @@ -17,8 +17,8 @@ namespace Microsoft.EntityFrameworkCore.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/Internal/IDbContextDependencies.cs b/src/EFCore/Internal/IDbContextDependencies.cs index 3bff01e0a68..179402a79e9 100644 --- a/src/EFCore/Internal/IDbContextDependencies.cs +++ b/src/EFCore/Internal/IDbContextDependencies.cs @@ -17,8 +17,8 @@ namespace Microsoft.EntityFrameworkCore.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/Internal/IDbContextPool.cs b/src/EFCore/Internal/IDbContextPool.cs index e554495c9cb..9af03d2b7b6 100644 --- a/src/EFCore/Internal/IDbContextPool.cs +++ b/src/EFCore/Internal/IDbContextPool.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore/Internal/IDbContextPoolable.cs b/src/EFCore/Internal/IDbContextPoolable.cs index 766522c05e4..4e4c9225fad 100644 --- a/src/EFCore/Internal/IDbContextPoolable.cs +++ b/src/EFCore/Internal/IDbContextPoolable.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore/Internal/IDbContextServices.cs b/src/EFCore/Internal/IDbContextServices.cs index 68e68989def..0ce83dc7709 100644 --- a/src/EFCore/Internal/IDbContextServices.cs +++ b/src/EFCore/Internal/IDbContextServices.cs @@ -17,8 +17,8 @@ namespace Microsoft.EntityFrameworkCore.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/Internal/IDbSetFinder.cs b/src/EFCore/Internal/IDbSetFinder.cs index 94110ec7715..cd005c19a9f 100644 --- a/src/EFCore/Internal/IDbSetFinder.cs +++ b/src/EFCore/Internal/IDbSetFinder.cs @@ -16,9 +16,9 @@ namespace Microsoft.EntityFrameworkCore.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IDbSetFinder diff --git a/src/EFCore/Internal/IDbSetInitializer.cs b/src/EFCore/Internal/IDbSetInitializer.cs index 70ae6365f1d..47e918da2f7 100644 --- a/src/EFCore/Internal/IDbSetInitializer.cs +++ b/src/EFCore/Internal/IDbSetInitializer.cs @@ -14,9 +14,9 @@ namespace Microsoft.EntityFrameworkCore.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IDbSetInitializer diff --git a/src/EFCore/Internal/IDbSetSource.cs b/src/EFCore/Internal/IDbSetSource.cs index e32e5b4a569..0fcbf48238b 100644 --- a/src/EFCore/Internal/IDbSetSource.cs +++ b/src/EFCore/Internal/IDbSetSource.cs @@ -15,9 +15,9 @@ namespace Microsoft.EntityFrameworkCore.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IDbSetSource diff --git a/src/EFCore/Internal/IEntityFinderSource.cs b/src/EFCore/Internal/IEntityFinderSource.cs index 39373fba3d6..e2ad78680da 100644 --- a/src/EFCore/Internal/IEntityFinderSource.cs +++ b/src/EFCore/Internal/IEntityFinderSource.cs @@ -16,9 +16,9 @@ namespace Microsoft.EntityFrameworkCore.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IEntityFinderSource diff --git a/src/EFCore/Internal/IRegisteredServices.cs b/src/EFCore/Internal/IRegisteredServices.cs index 0d18e1d0680..a56ee6c5a68 100644 --- a/src/EFCore/Internal/IRegisteredServices.cs +++ b/src/EFCore/Internal/IRegisteredServices.cs @@ -15,9 +15,9 @@ namespace Microsoft.EntityFrameworkCore.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IRegisteredServices diff --git a/src/EFCore/Internal/ISingletonOptionsInitializer.cs b/src/EFCore/Internal/ISingletonOptionsInitializer.cs index 4d15a738071..cf6679f52ed 100644 --- a/src/EFCore/Internal/ISingletonOptionsInitializer.cs +++ b/src/EFCore/Internal/ISingletonOptionsInitializer.cs @@ -16,9 +16,9 @@ namespace Microsoft.EntityFrameworkCore.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface ISingletonOptionsInitializer diff --git a/src/EFCore/Internal/InternalDbSet.cs b/src/EFCore/Internal/InternalDbSet.cs index 45d564dbe76..7c2c07b4a86 100644 --- a/src/EFCore/Internal/InternalDbSet.cs +++ b/src/EFCore/Internal/InternalDbSet.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Internal/LazyLoader.cs b/src/EFCore/Internal/LazyLoader.cs index 692148f5f75..bcc86625aa5 100644 --- a/src/EFCore/Internal/LazyLoader.cs +++ b/src/EFCore/Internal/LazyLoader.cs @@ -22,7 +22,7 @@ namespace Microsoft.EntityFrameworkCore.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each + /// The service lifetime is . This means that each /// entity instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. @@ -123,7 +123,8 @@ public virtual Task LoadAsync( : Task.CompletedTask; } - private bool ShouldLoad(object entity, string navigationName, + private bool ShouldLoad( + object entity, string navigationName, out NavigationEntry navigationEntry) { if (_loadedStates != null diff --git a/src/EFCore/Internal/LoggingOptions.cs b/src/EFCore/Internal/LoggingOptions.cs index 721c0150c89..360fc34e973 100644 --- a/src/EFCore/Internal/LoggingOptions.cs +++ b/src/EFCore/Internal/LoggingOptions.cs @@ -17,9 +17,9 @@ namespace Microsoft.EntityFrameworkCore.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class LoggingOptions : ILoggingOptions diff --git a/src/EFCore/Internal/Multigraph.cs b/src/EFCore/Internal/Multigraph.cs index 53d1ff076f8..849dd8bfd04 100644 --- a/src/EFCore/Internal/Multigraph.cs +++ b/src/EFCore/Internal/Multigraph.cs @@ -244,10 +244,7 @@ public virtual IReadOnlyList TopologicalSort( { // Failed to break the cycle var currentCycleVertex = _vertices.First(v => predecessorCounts.ContainsKey(v)); - var cycle = new List - { - currentCycleVertex - }; + var cycle = new List { currentCycleVertex }; var finished = false; while (!finished) { @@ -383,10 +380,7 @@ public virtual IReadOnlyList> BatchingTopologicalSort( { var currentCycleVertex = _vertices.First( v => predecessorCounts.TryGetValue(v, out var predecessorNumber) ? predecessorNumber != 0 : false); - var cyclicWalk = new List - { - currentCycleVertex - }; + var cyclicWalk = new List { currentCycleVertex }; var finished = false; while (!finished) { @@ -448,7 +442,7 @@ public virtual IReadOnlyList> BatchingTopologicalSort( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public override IEnumerable GetOutgoingNeighbors(TVertex @from) + public override IEnumerable GetOutgoingNeighbors(TVertex from) => _successorMap.TryGetValue(from, out var successorSet) ? successorSet.Keys : Enumerable.Empty(); diff --git a/src/EFCore/Internal/ReferenceEnumerableEqualityComparer.cs b/src/EFCore/Internal/ReferenceEnumerableEqualityComparer.cs index 1319c34e9ef..9790d732685 100644 --- a/src/EFCore/Internal/ReferenceEnumerableEqualityComparer.cs +++ b/src/EFCore/Internal/ReferenceEnumerableEqualityComparer.cs @@ -37,6 +37,7 @@ public int GetHashCode(TEnumerable obj) { hash.Add(value); } + return hash.ToHashCode(); } } diff --git a/src/EFCore/Internal/RegisteredServices.cs b/src/EFCore/Internal/RegisteredServices.cs index 0a62305208d..36678f7cace 100644 --- a/src/EFCore/Internal/RegisteredServices.cs +++ b/src/EFCore/Internal/RegisteredServices.cs @@ -16,9 +16,9 @@ namespace Microsoft.EntityFrameworkCore.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class RegisteredServices : IRegisteredServices diff --git a/src/EFCore/Internal/SemanticVersionComparer.cs b/src/EFCore/Internal/SemanticVersionComparer.cs index 8ca4d8b57c6..85e712f10c4 100644 --- a/src/EFCore/Internal/SemanticVersionComparer.cs +++ b/src/EFCore/Internal/SemanticVersionComparer.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Internal/ServiceProviderCache.cs b/src/EFCore/Internal/ServiceProviderCache.cs index 97463689782..c4188c920ad 100644 --- a/src/EFCore/Internal/ServiceProviderCache.cs +++ b/src/EFCore/Internal/ServiceProviderCache.cs @@ -21,8 +21,9 @@ namespace Microsoft.EntityFrameworkCore.Internal /// public class ServiceProviderCache { - private readonly ConcurrentDictionary DebugInfo)> _configurations - = new ConcurrentDictionary)>(); + private readonly ConcurrentDictionary DebugInfo)> + _configurations + = new ConcurrentDictionary)>(); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -87,7 +88,7 @@ public virtual IServiceProvider GetOrAdd([NotNull] IDbContextOptions options, bo { if (replacedServices.TryGetValue(descriptor.ServiceType, out var replacementType)) { - ((IList) updatedServices).Add( + ((IList)updatedServices).Add( new ServiceDescriptor(descriptor.ServiceType, replacementType, descriptor.Lifetime)); } } diff --git a/src/EFCore/Internal/SingletonOptionsInitializer.cs b/src/EFCore/Internal/SingletonOptionsInitializer.cs index f2f5ed7ffdc..805054b1345 100644 --- a/src/EFCore/Internal/SingletonOptionsInitializer.cs +++ b/src/EFCore/Internal/SingletonOptionsInitializer.cs @@ -16,9 +16,9 @@ namespace Microsoft.EntityFrameworkCore.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class SingletonOptionsInitializer : ISingletonOptionsInitializer diff --git a/src/EFCore/Metadata/Builders/CollectionNavigationBuilder`.cs b/src/EFCore/Metadata/Builders/CollectionNavigationBuilder`.cs index ca54b5e03e7..bc29c48d522 100644 --- a/src/EFCore/Metadata/Builders/CollectionNavigationBuilder`.cs +++ b/src/EFCore/Metadata/Builders/CollectionNavigationBuilder`.cs @@ -6,7 +6,6 @@ using System.Reflection; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Builders diff --git a/src/EFCore/Metadata/Builders/EntityTypeBuilder`.cs b/src/EFCore/Metadata/Builders/EntityTypeBuilder`.cs index 440e0cf09c9..065b01d9ad0 100644 --- a/src/EFCore/Metadata/Builders/EntityTypeBuilder`.cs +++ b/src/EFCore/Metadata/Builders/EntityTypeBuilder`.cs @@ -8,7 +8,6 @@ using System.Reflection; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal; using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; @@ -770,7 +769,7 @@ public virtual DiscriminatorBuilder HasDiscriminator( - Builder.DiscriminatorBuilder(Property(propertyExpression).GetInfrastructure(), ConfigurationSource.Explicit)); + Builder.DiscriminatorBuilder(Property(propertyExpression).GetInfrastructure(), ConfigurationSource.Explicit)); } /// diff --git a/src/EFCore/Metadata/Builders/IConventionPropertyBuilder.cs b/src/EFCore/Metadata/Builders/IConventionPropertyBuilder.cs index 34a08c6b31d..706a87ed696 100644 --- a/src/EFCore/Metadata/Builders/IConventionPropertyBuilder.cs +++ b/src/EFCore/Metadata/Builders/IConventionPropertyBuilder.cs @@ -302,7 +302,7 @@ IConventionPropertyBuilder HasValueGenerator( /// true if the can be configured for this property. /// bool CanSetValueGenerator( - [CanBeNull] Func factory, bool fromDataAnnotation = false); + [CanBeNull] Func factory, bool fromDataAnnotation = false); /// /// Configures the property so that the property value is converted to and from the database diff --git a/src/EFCore/Metadata/Builders/IConventionServicePropertyBuilder.cs b/src/EFCore/Metadata/Builders/IConventionServicePropertyBuilder.cs index 6f66b5e85ad..09853f9cb05 100644 --- a/src/EFCore/Metadata/Builders/IConventionServicePropertyBuilder.cs +++ b/src/EFCore/Metadata/Builders/IConventionServicePropertyBuilder.cs @@ -71,7 +71,8 @@ public interface IConventionServicePropertyBuilder : IConventionAnnotatableBuild /// The same builder instance if the configuration was applied, /// null otherwise. /// - IConventionServicePropertyBuilder HasParameterBinding([CanBeNull] ServiceParameterBinding parameterBinding, bool fromDataAnnotation = false); + IConventionServicePropertyBuilder HasParameterBinding( + [CanBeNull] ServiceParameterBinding parameterBinding, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the can be set for this property. diff --git a/src/EFCore/Metadata/Builders/IndexBuilder.cs b/src/EFCore/Metadata/Builders/IndexBuilder.cs index e8468f8e083..62c0ad3bb74 100644 --- a/src/EFCore/Metadata/Builders/IndexBuilder.cs +++ b/src/EFCore/Metadata/Builders/IndexBuilder.cs @@ -76,7 +76,7 @@ public virtual IndexBuilder IsUnique(bool unique = true) return this; } - private InternalIndexBuilder Builder => this.GetInfrastructure(); + private InternalIndexBuilder Builder => this.GetInfrastructure(); #region Hidden System.Object members diff --git a/src/EFCore/Metadata/Builders/KeyBuilder.cs b/src/EFCore/Metadata/Builders/KeyBuilder.cs index 39fac40ef91..0d6f913fb73 100644 --- a/src/EFCore/Metadata/Builders/KeyBuilder.cs +++ b/src/EFCore/Metadata/Builders/KeyBuilder.cs @@ -64,7 +64,7 @@ public virtual KeyBuilder HasAnnotation([NotNull] string annotation, [NotNull] o return this; } - private InternalKeyBuilder Builder => this.GetInfrastructure(); + private InternalKeyBuilder Builder => this.GetInfrastructure(); #region Hidden System.Object members diff --git a/src/EFCore/Metadata/Builders/OwnedEntityTypeBuilder.cs b/src/EFCore/Metadata/Builders/OwnedEntityTypeBuilder.cs index bccc850a814..c5f6fed89b1 100644 --- a/src/EFCore/Metadata/Builders/OwnedEntityTypeBuilder.cs +++ b/src/EFCore/Metadata/Builders/OwnedEntityTypeBuilder.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.ComponentModel; diff --git a/src/EFCore/Metadata/Builders/OwnedEntityTypeBuilder`.cs b/src/EFCore/Metadata/Builders/OwnedEntityTypeBuilder`.cs index 71788c1727a..ef49e6a848d 100644 --- a/src/EFCore/Metadata/Builders/OwnedEntityTypeBuilder`.cs +++ b/src/EFCore/Metadata/Builders/OwnedEntityTypeBuilder`.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. namespace Microsoft.EntityFrameworkCore.Metadata.Builders diff --git a/src/EFCore/Metadata/Builders/OwnedNavigationBuilder`.cs b/src/EFCore/Metadata/Builders/OwnedNavigationBuilder`.cs index 1ea536329e5..89e26186175 100644 --- a/src/EFCore/Metadata/Builders/OwnedNavigationBuilder`.cs +++ b/src/EFCore/Metadata/Builders/OwnedNavigationBuilder`.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Metadata/Builders/OwnershipBuilder`.cs b/src/EFCore/Metadata/Builders/OwnershipBuilder`.cs index 371e8c5afc3..fe9adccfc57 100644 --- a/src/EFCore/Metadata/Builders/OwnershipBuilder`.cs +++ b/src/EFCore/Metadata/Builders/OwnershipBuilder`.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Metadata/Builders/QueryTypeBuilder`.cs b/src/EFCore/Metadata/Builders/QueryTypeBuilder`.cs index 42da6dbeb94..6c310598a63 100644 --- a/src/EFCore/Metadata/Builders/QueryTypeBuilder`.cs +++ b/src/EFCore/Metadata/Builders/QueryTypeBuilder`.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Metadata/Builders/ReferenceNavigationBuilder.cs b/src/EFCore/Metadata/Builders/ReferenceNavigationBuilder.cs index b352757792e..bd4cbde5d07 100644 --- a/src/EFCore/Metadata/Builders/ReferenceNavigationBuilder.cs +++ b/src/EFCore/Metadata/Builders/ReferenceNavigationBuilder.cs @@ -179,12 +179,12 @@ private InternalRelationshipBuilder WithManyBuilder(MemberIdentity collection) } return collection.MemberInfo == null || ReferenceMember == null - ? builder.HasNavigations( - ReferenceName, collection.Name, - (EntityType)RelatedEntityType, (EntityType)DeclaringEntityType, ConfigurationSource.Explicit) - : builder.HasNavigations( - ReferenceMember, collection.MemberInfo, - (EntityType)RelatedEntityType, (EntityType)DeclaringEntityType, ConfigurationSource.Explicit); + ? builder.HasNavigations( + ReferenceName, collection.Name, + (EntityType)RelatedEntityType, (EntityType)DeclaringEntityType, ConfigurationSource.Explicit) + : builder.HasNavigations( + ReferenceMember, collection.MemberInfo, + (EntityType)RelatedEntityType, (EntityType)DeclaringEntityType, ConfigurationSource.Explicit); } /// diff --git a/src/EFCore/Metadata/Builders/ReferenceNavigationBuilder`.cs b/src/EFCore/Metadata/Builders/ReferenceNavigationBuilder`.cs index e74632d4559..d469c0a1283 100644 --- a/src/EFCore/Metadata/Builders/ReferenceNavigationBuilder`.cs +++ b/src/EFCore/Metadata/Builders/ReferenceNavigationBuilder`.cs @@ -7,7 +7,6 @@ using System.Reflection; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Utilities; namespace Microsoft.EntityFrameworkCore.Metadata.Builders diff --git a/src/EFCore/Metadata/Conventions/CascadeDeleteConvention.cs b/src/EFCore/Metadata/Conventions/CascadeDeleteConvention.cs index 2ee432de068..bd5fde2b74f 100644 --- a/src/EFCore/Metadata/Conventions/CascadeDeleteConvention.cs +++ b/src/EFCore/Metadata/Conventions/CascadeDeleteConvention.cs @@ -8,8 +8,8 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// - /// A convention that sets the delete behavior to for required foreign keys - /// and for optional ones. + /// A convention that sets the delete behavior to for required foreign keys + /// and for optional ones. /// public class CascadeDeleteConvention : IForeignKeyAddedConvention, IForeignKeyRequirednessChangedConvention { diff --git a/src/EFCore/Metadata/Conventions/ChangeTrackingStrategyConvention.cs b/src/EFCore/Metadata/Conventions/ChangeTrackingStrategyConvention.cs index 560150378b3..407b23f78c6 100644 --- a/src/EFCore/Metadata/Conventions/ChangeTrackingStrategyConvention.cs +++ b/src/EFCore/Metadata/Conventions/ChangeTrackingStrategyConvention.cs @@ -10,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// /// A convention that sets a flag on the model to always skip detecting changes if no entity type is using the - /// strategy. + /// strategy. /// public class ChangeTrackingStrategyConvention : IModelFinalizedConvention { diff --git a/src/EFCore/Metadata/Conventions/ConcurrencyCheckAttributeConvention.cs b/src/EFCore/Metadata/Conventions/ConcurrencyCheckAttributeConvention.cs index 8d5734a694a..f01b9ae6a60 100644 --- a/src/EFCore/Metadata/Conventions/ConcurrencyCheckAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/ConcurrencyCheckAttributeConvention.cs @@ -10,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// - /// A convention that configures a property as a concurrency token if it has the . + /// A convention that configures a property as a concurrency token if it has the . /// public class ConcurrencyCheckAttributeConvention : PropertyAttributeConventionBase { diff --git a/src/EFCore/Metadata/Conventions/DatabaseGeneratedAttributeConvention.cs b/src/EFCore/Metadata/Conventions/DatabaseGeneratedAttributeConvention.cs index 32c32b366e4..109eeb68730 100644 --- a/src/EFCore/Metadata/Conventions/DatabaseGeneratedAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/DatabaseGeneratedAttributeConvention.cs @@ -10,10 +10,10 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// - /// A convention that configures a property as if - /// is specified, if - /// is specified or if - /// is specified using a . + /// A convention that configures a property as if + /// is specified, if + /// is specified or if + /// is specified using a . /// public class DatabaseGeneratedAttributeConvention : PropertyAttributeConventionBase { diff --git a/src/EFCore/Metadata/Conventions/DbSetFindingConvention.cs b/src/EFCore/Metadata/Conventions/DbSetFindingConvention.cs index 4e3f79ee57b..532f2de0ce1 100644 --- a/src/EFCore/Metadata/Conventions/DbSetFindingConvention.cs +++ b/src/EFCore/Metadata/Conventions/DbSetFindingConvention.cs @@ -8,8 +8,8 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// - /// A convention that adds entity types based on the properties defined on the - /// derived class. + /// A convention that adds entity types based on the properties defined on the + /// derived class. /// public class DbSetFindingConvention : IModelInitializedConvention { @@ -32,7 +32,8 @@ public DbSetFindingConvention([NotNull] ProviderConventionSetBuilderDependencies /// /// The builder for the model. /// Additional information associated with convention execution. - public virtual void ProcessModelInitialized(IConventionModelBuilder modelBuilder, IConventionContext context) + public virtual void ProcessModelInitialized( + IConventionModelBuilder modelBuilder, IConventionContext context) { foreach (var setInfo in Dependencies.SetFinder.FindSets(Dependencies.ContextType)) { diff --git a/src/EFCore/Metadata/Conventions/ForeignKeyAttributeConvention.cs b/src/EFCore/Metadata/Conventions/ForeignKeyAttributeConvention.cs index a14a227f474..db1b4e3fddc 100644 --- a/src/EFCore/Metadata/Conventions/ForeignKeyAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/ForeignKeyAttributeConvention.cs @@ -18,7 +18,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions /// /// /// A convention that configures the foreign key properties associated with a navigation property - /// based on the specified on the properties or the navigation properties. + /// based on the specified on the properties or the navigation properties. /// /// /// For one-to-one relationships the attribute has to be specified on the navigation property pointing to the principal. @@ -116,10 +116,7 @@ var fkPropertiesOnDependentToPrincipal if (fkPropertyOnDependent != null) { - fkPropertiesToSet = new List - { - fkPropertyOnDependent.GetSimpleMemberName() - }; + fkPropertiesToSet = new List { fkPropertyOnDependent.GetSimpleMemberName() }; upgradeDependentToPrincipalNavigationSource = true; } else @@ -131,10 +128,7 @@ var fkPropertiesOnDependentToPrincipal } shouldInvert = true; - fkPropertiesToSet = new List - { - fkPropertyOnPrincipal.GetSimpleMemberName() - }; + fkPropertiesToSet = new List { fkPropertyOnPrincipal.GetSimpleMemberName() }; upgradePrincipalToDependentNavigationSource = true; } } @@ -237,7 +231,8 @@ var fkPropertiesOnDependentToPrincipal } } - private static IConventionRelationshipBuilder SplitNavigationsToSeparateRelationships(IConventionRelationshipBuilder relationshipBuilder) + private static IConventionRelationshipBuilder SplitNavigationsToSeparateRelationships( + IConventionRelationshipBuilder relationshipBuilder) { var foreignKey = relationshipBuilder.Metadata; var dependentToPrincipalNavigationName = foreignKey.DependentToPrincipal.Name; diff --git a/src/EFCore/Metadata/Conventions/ForeignKeyIndexConvention.cs b/src/EFCore/Metadata/Conventions/ForeignKeyIndexConvention.cs index 4c99c8e159d..b6e80d447ab 100644 --- a/src/EFCore/Metadata/Conventions/ForeignKeyIndexConvention.cs +++ b/src/EFCore/Metadata/Conventions/ForeignKeyIndexConvention.cs @@ -91,7 +91,8 @@ public virtual void ProcessForeignKeyPropertiesChanged( } } - private static void OnForeignKeyRemoved(IConventionEntityType declaringType, IReadOnlyList foreignKeyProperties) + private static void OnForeignKeyRemoved( + IConventionEntityType declaringType, IReadOnlyList foreignKeyProperties) { var index = declaringType.FindIndex(foreignKeyProperties); if (index == null) diff --git a/src/EFCore/Metadata/Conventions/ForeignKeyPropertyDiscoveryConvention.cs b/src/EFCore/Metadata/Conventions/ForeignKeyPropertyDiscoveryConvention.cs index 6a6835ab000..71bae1ca76c 100644 --- a/src/EFCore/Metadata/Conventions/ForeignKeyPropertyDiscoveryConvention.cs +++ b/src/EFCore/Metadata/Conventions/ForeignKeyPropertyDiscoveryConvention.cs @@ -28,7 +28,6 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions /// the exact name as principal key properties if they are a proper subset of the dependent PK. /// /// - /// /// /// /// If a match was found, but the property types are not compatible with the principal key types no further matches are searched for. @@ -223,7 +222,7 @@ private IConventionRelationshipBuilder DiscoverProperties( var invertedRelationshipBuilder = relationshipBuilder .HasEntityTypes(foreignKey.DeclaringEntityType, foreignKey.PrincipalEntityType); return batch.Run( - invertedRelationshipBuilder.HasForeignKey(candidatePropertiesOnPrincipal).Metadata) + invertedRelationshipBuilder.HasForeignKey(candidatePropertiesOnPrincipal).Metadata) ?.Builder; } } @@ -241,8 +240,9 @@ private IConventionRelationshipBuilder DiscoverProperties( && dependentPk.Properties.Count > foreignKey.PrincipalKey.Properties.Count && TryFindMatchingProperties(foreignKey, "", onDependent: true, matchPk: false, out foreignKeyProperties) && foreignKeyProperties != null - && foreignKeyProperties.Any(p => !dependentPk.Properties.Contains(p) - || p.Name.Equals("Id", StringComparison.OrdinalIgnoreCase))) + && foreignKeyProperties.Any( + p => !dependentPk.Properties.Contains(p) + || p.Name.Equals("Id", StringComparison.OrdinalIgnoreCase))) { foreignKeyProperties = null; } @@ -705,7 +705,8 @@ public virtual void ProcessEntityTypePrimaryKeyChanged( IConventionKey previousPrimaryKey, IConventionContext context) { - if (newPrimaryKey != null && newPrimaryKey.Builder == null) + if (newPrimaryKey != null + && newPrimaryKey.Builder == null) { return; } diff --git a/src/EFCore/Metadata/Conventions/IEntityTypeRemovedConvention.cs b/src/EFCore/Metadata/Conventions/IEntityTypeRemovedConvention.cs index b00585f8a6a..fe032fb2cb3 100644 --- a/src/EFCore/Metadata/Conventions/IEntityTypeRemovedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IEntityTypeRemovedConvention.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore/Metadata/Conventions/IForeignKeyRequirednessChangedConvention.cs b/src/EFCore/Metadata/Conventions/IForeignKeyRequirednessChangedConvention.cs index f5275ffd941..0e8bac3a649 100644 --- a/src/EFCore/Metadata/Conventions/IForeignKeyRequirednessChangedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IForeignKeyRequirednessChangedConvention.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore/Metadata/Conventions/IModelAnnotationChangedConvention.cs b/src/EFCore/Metadata/Conventions/IModelAnnotationChangedConvention.cs index 3595198e4ac..bcad10acc93 100644 --- a/src/EFCore/Metadata/Conventions/IModelAnnotationChangedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IModelAnnotationChangedConvention.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore/Metadata/Conventions/IModelFinalizedConvention.cs b/src/EFCore/Metadata/Conventions/IModelFinalizedConvention.cs index baf7f592f5f..789898a2809 100644 --- a/src/EFCore/Metadata/Conventions/IModelFinalizedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IModelFinalizedConvention.cs @@ -16,6 +16,7 @@ public interface IModelFinalizedConvention : IConvention /// /// The builder for the model. /// Additional information associated with convention execution. - void ProcessModelFinalized([NotNull] IConventionModelBuilder modelBuilder, [NotNull] IConventionContext context); + void ProcessModelFinalized( + [NotNull] IConventionModelBuilder modelBuilder, [NotNull] IConventionContext context); } } diff --git a/src/EFCore/Metadata/Conventions/IModelInitializedConvention.cs b/src/EFCore/Metadata/Conventions/IModelInitializedConvention.cs index 2bec8b0c758..84dc6404fcd 100644 --- a/src/EFCore/Metadata/Conventions/IModelInitializedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IModelInitializedConvention.cs @@ -16,6 +16,7 @@ public interface IModelInitializedConvention : IConvention /// /// The builder for the model. /// Additional information associated with convention execution. - void ProcessModelInitialized([NotNull] IConventionModelBuilder modelBuilder, [NotNull] IConventionContext context); + void ProcessModelInitialized( + [NotNull] IConventionModelBuilder modelBuilder, [NotNull] IConventionContext context); } } diff --git a/src/EFCore/Metadata/Conventions/Infrastructure/ProviderConventionSetBuilderDependencies.cs b/src/EFCore/Metadata/Conventions/Infrastructure/ProviderConventionSetBuilderDependencies.cs index a5f04833249..2bc829215bc 100644 --- a/src/EFCore/Metadata/Conventions/Infrastructure/ProviderConventionSetBuilderDependencies.cs +++ b/src/EFCore/Metadata/Conventions/Infrastructure/ProviderConventionSetBuilderDependencies.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -183,7 +183,8 @@ public ProviderConventionSetBuilderDependencies With([NotNull] IDiagnosticsLogge /// /// A replacement for the current dependency of this type. /// A new parameter object with the given service replaced. - public ProviderConventionSetBuilderDependencies With([NotNull] IDiagnosticsLogger validationLogger) + public ProviderConventionSetBuilderDependencies With( + [NotNull] IDiagnosticsLogger validationLogger) => new ProviderConventionSetBuilderDependencies( TypeMappingSource, ConstructorBindingFactory, ParameterBindingFactories, MemberClassifier, Logger, validationLogger, SetFinder, _currentContext, ModelValidator); diff --git a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.cs b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.cs index 79391945cbd..e056c12e570 100644 --- a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.cs +++ b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.cs @@ -9,6 +9,7 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Internal; +using Index = Microsoft.EntityFrameworkCore.Metadata.Internal.Index; namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal { @@ -181,7 +182,6 @@ public virtual IConventionForeignKey OnForeignKeyRemoved( [NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] IConventionForeignKey foreignKey) => _scope.OnForeignKeyRemoved(entityTypeBuilder, foreignKey); - /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in @@ -357,7 +357,7 @@ public virtual IConventionIndexBuilder OnIndexAdded([NotNull] IConventionIndexBu /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual void OnIndexRemoved([NotNull] InternalEntityTypeBuilder entityTypeBuilder, [NotNull] Metadata.Internal.Index index) + public virtual void OnIndexRemoved([NotNull] InternalEntityTypeBuilder entityTypeBuilder, [NotNull] Index index) => _scope.OnIndexRemoved(entityTypeBuilder, index); /// diff --git a/src/EFCore/Metadata/Conventions/Internal/ConventionNode.cs b/src/EFCore/Metadata/Conventions/Internal/ConventionNode.cs index 9c394adabd2..5ca2769bc99 100644 --- a/src/EFCore/Metadata/Conventions/Internal/ConventionNode.cs +++ b/src/EFCore/Metadata/Conventions/Internal/ConventionNode.cs @@ -579,10 +579,10 @@ public override IConventionKey OnEntityTypePrimaryKeyChanged( foreach (var keyConvention in _conventionSet.EntityTypePrimaryKeyChangedConventions) { // Some conventions rely on this running even if the new key has been removed - // This will be fixed by reference counting, see #214 + // This will be fixed by reference counting, see #15898 //if (newPrimaryKey != null && newPrimaryKey.Builder == null) //{ - //return null; + //return null; //} keyConvention.ProcessEntityTypePrimaryKeyChanged( @@ -594,7 +594,8 @@ public override IConventionKey OnEntityTypePrimaryKeyChanged( } } - if (newPrimaryKey != null && newPrimaryKey.Builder == null) + if (newPrimaryKey != null + && newPrimaryKey.Builder == null) { return null; } @@ -618,7 +619,8 @@ public override IConventionAnnotation OnEntityTypeAnnotationChanged( return null; } - entityTypeAnnotationSetConvention.ProcessEntityTypeAnnotationChanged(entityTypeBuilder, name, annotation, oldAnnotation, _annotationConventionContext); + entityTypeAnnotationSetConvention.ProcessEntityTypeAnnotationChanged( + entityTypeBuilder, name, annotation, oldAnnotation, _annotationConventionContext); if (_annotationConventionContext.ShouldStopProcessing()) { return _annotationConventionContext.Result; @@ -1559,7 +1561,7 @@ public OnKeyRemovedNode(IConventionEntityTypeBuilder entityTypeBuilder, IConvent public override ConventionNode Accept(ConventionVisitor visitor) => visitor.VisitOnKeyRemoved(this); } - + private class OnKeyAnnotationChangedNode : ConventionNode { public OnKeyAnnotationChangedNode( diff --git a/src/EFCore/Metadata/Conventions/Internal/ConventionVisitor.cs b/src/EFCore/Metadata/Conventions/Internal/ConventionVisitor.cs index 3f1692fea77..0fed64706f3 100644 --- a/src/EFCore/Metadata/Conventions/Internal/ConventionVisitor.cs +++ b/src/EFCore/Metadata/Conventions/Internal/ConventionVisitor.cs @@ -190,6 +190,7 @@ public override OnForeignKeyRemovedNode VisitOnForeignKeyRemoved(OnForeignKeyRem Dispatcher._immediateConventionScope.OnForeignKeyRemoved(node.EntityTypeBuilder, node.ForeignKey); return null; } + public override OnForeignKeyPropertiesChangedNode VisitOnForeignKeyPropertiesChanged(OnForeignKeyPropertiesChangedNode node) { Dispatcher._immediateConventionScope.OnForeignKeyPropertiesChanged( @@ -216,7 +217,8 @@ public override OnForeignKeyOwnershipChangedNode VisitOnForeignKeyOwnershipChang return null; } - public override OnForeignKeyPrincipalEndChangedNode VisitOnForeignKeyPrincipalEndChanged(OnForeignKeyPrincipalEndChangedNode node) + public override OnForeignKeyPrincipalEndChangedNode VisitOnForeignKeyPrincipalEndChanged( + OnForeignKeyPrincipalEndChangedNode node) { Dispatcher._immediateConventionScope.OnForeignKeyPrincipalEndChanged(node.RelationshipBuilder); return null; diff --git a/src/EFCore/Metadata/Conventions/InversePropertyAttributeConvention.cs b/src/EFCore/Metadata/Conventions/InversePropertyAttributeConvention.cs index 8aa24886f12..b4ec96596f9 100644 --- a/src/EFCore/Metadata/Conventions/InversePropertyAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/InversePropertyAttributeConvention.cs @@ -17,7 +17,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// - /// A convention that configures the inverse navigation property based on the + /// A convention that configures the inverse navigation property based on the /// specified on the other navigation property. /// public class InversePropertyAttributeConvention : @@ -49,7 +49,8 @@ public override void ProcessEntityTypeAdded( => Process(entityTypeBuilder, navigationMemberInfo, targetClrType, attribute); private void Process( - IConventionEntityTypeBuilder entityTypeBuilder, MemberInfo navigationMemberInfo, Type targetClrType, InversePropertyAttribute attribute) + IConventionEntityTypeBuilder entityTypeBuilder, MemberInfo navigationMemberInfo, Type targetClrType, + InversePropertyAttribute attribute) { if (!entityTypeBuilder.CanAddNavigation( navigationMemberInfo.GetSimpleMemberName(), fromDataAnnotation: true)) @@ -383,13 +384,13 @@ public virtual void ProcessModelFinalized(IConventionModelBuilder modelBuilder, /// /// Returns a value indication whether the given navigation has ambiguous inverse navigations with - /// . + /// . /// /// The entity type. /// The navigation. /// Target entity type. /// - /// true if the given navigation has ambiguous inverse navigations with . + /// true if the given navigation has ambiguous inverse navigations with . /// public static bool IsAmbiguous( [NotNull] IConventionEntityType entityType, [NotNull] MemberInfo navigation, [NotNull] IConventionEntityType targetEntityType) @@ -545,7 +546,7 @@ private static void RemoveInverseNavigation( } private static IConventionEntityType FindActualEntityType(IConventionEntityType entityType) - => ((Model)entityType.Model).FindActualEntityType((EntityType) entityType); + => ((Model)entityType.Model).FindActualEntityType((EntityType)entityType); private static Dictionary> GetInverseNavigations( IConventionAnnotatable entityType) diff --git a/src/EFCore/Metadata/Conventions/KeyAttributeConvention.cs b/src/EFCore/Metadata/Conventions/KeyAttributeConvention.cs index 336dc556289..4bbef1d59db 100644 --- a/src/EFCore/Metadata/Conventions/KeyAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/KeyAttributeConvention.cs @@ -15,7 +15,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// - /// A convention that configures the entity type key based on the specified on a property. + /// A convention that configures the entity type key based on the specified on a property. /// public class KeyAttributeConvention : PropertyAttributeConventionBase, IModelFinalizedConvention { @@ -49,10 +49,7 @@ protected override void ProcessPropertyAdded( var entityTypeBuilder = entityType.Builder; var currentKey = entityTypeBuilder.Metadata.FindPrimaryKey(); - var properties = new List - { - propertyBuilder.Metadata.Name - }; + var properties = new List { propertyBuilder.Metadata.Name }; if (currentKey != null && entityType.GetPrimaryKeyConfigurationSource() == ConfigurationSource.DataAnnotation) diff --git a/src/EFCore/Metadata/Conventions/MaxLengthAttributeConvention.cs b/src/EFCore/Metadata/Conventions/MaxLengthAttributeConvention.cs index 68216485898..887d0a01deb 100644 --- a/src/EFCore/Metadata/Conventions/MaxLengthAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/MaxLengthAttributeConvention.cs @@ -10,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// - /// A convention that configures the maximum length based on the applied on the property. + /// A convention that configures the maximum length based on the applied on the property. /// public class MaxLengthAttributeConvention : PropertyAttributeConventionBase { diff --git a/src/EFCore/Metadata/Conventions/NavigationAttributeConventionBase.cs b/src/EFCore/Metadata/Conventions/NavigationAttributeConventionBase.cs index 1dbb21923f2..4e08213cee5 100644 --- a/src/EFCore/Metadata/Conventions/NavigationAttributeConventionBase.cs +++ b/src/EFCore/Metadata/Conventions/NavigationAttributeConventionBase.cs @@ -6,7 +6,6 @@ using System.Linq; using System.Reflection; using JetBrains.Annotations; -using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal; @@ -153,6 +152,7 @@ public virtual void ProcessEntityTypeBaseTypeChanged( } } } + /// /// Called after a navigation is added to the entity type. /// diff --git a/src/EFCore/Metadata/Conventions/NonNullableNavigationConvention.cs b/src/EFCore/Metadata/Conventions/NonNullableNavigationConvention.cs index 7b09844f4a5..89f20370366 100644 --- a/src/EFCore/Metadata/Conventions/NonNullableNavigationConvention.cs +++ b/src/EFCore/Metadata/Conventions/NonNullableNavigationConvention.cs @@ -4,7 +4,6 @@ using System.Reflection; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Diagnostics; -using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; @@ -42,7 +41,8 @@ public virtual void ProcessNavigationAdded( var modelBuilder = relationshipBuilder.ModelBuilder; - if (!IsNonNullable(modelBuilder, navigation) || navigation.IsCollection()) + if (!IsNonNullable(modelBuilder, navigation) + || navigation.IsCollection()) { return; } diff --git a/src/EFCore/Metadata/Conventions/NonNullableReferencePropertyConvention.cs b/src/EFCore/Metadata/Conventions/NonNullableReferencePropertyConvention.cs index fcdafdea798..1187be9b6cb 100644 --- a/src/EFCore/Metadata/Conventions/NonNullableReferencePropertyConvention.cs +++ b/src/EFCore/Metadata/Conventions/NonNullableReferencePropertyConvention.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Reflection; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; diff --git a/src/EFCore/Metadata/Conventions/NotMappedEntityTypeAttributeConvention.cs b/src/EFCore/Metadata/Conventions/NotMappedEntityTypeAttributeConvention.cs index bc7bc8b9dba..2982a2f2f8d 100644 --- a/src/EFCore/Metadata/Conventions/NotMappedEntityTypeAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/NotMappedEntityTypeAttributeConvention.cs @@ -9,7 +9,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// - /// A convention that ignores entity types that have the . + /// A convention that ignores entity types that have the . /// public class NotMappedEntityTypeAttributeConvention : EntityTypeAttributeConventionBase { diff --git a/src/EFCore/Metadata/Conventions/NotMappedMemberAttributeConvention.cs b/src/EFCore/Metadata/Conventions/NotMappedMemberAttributeConvention.cs index d64d0cd8dbd..16e291ecac5 100644 --- a/src/EFCore/Metadata/Conventions/NotMappedMemberAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/NotMappedMemberAttributeConvention.cs @@ -14,7 +14,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// - /// A convention that ignores members on entity types that have the . + /// A convention that ignores members on entity types that have the . /// public class NotMappedMemberAttributeConvention : IEntityTypeAddedConvention { diff --git a/src/EFCore/Metadata/Conventions/OwnedEntityTypeAttributeConvention.cs b/src/EFCore/Metadata/Conventions/OwnedEntityTypeAttributeConvention.cs index 92033ac3227..b93ca18436f 100644 --- a/src/EFCore/Metadata/Conventions/OwnedEntityTypeAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/OwnedEntityTypeAttributeConvention.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; @@ -9,7 +9,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// - /// A convention that configures the entity types that have the as owned. + /// A convention that configures the entity types that have the as owned. /// public class OwnedEntityTypeAttributeConvention : EntityTypeAttributeConventionBase { diff --git a/src/EFCore/Metadata/Conventions/PropertyDiscoveryConvention.cs b/src/EFCore/Metadata/Conventions/PropertyDiscoveryConvention.cs index 0c319f8940e..9737e7bf567 100644 --- a/src/EFCore/Metadata/Conventions/PropertyDiscoveryConvention.cs +++ b/src/EFCore/Metadata/Conventions/PropertyDiscoveryConvention.cs @@ -54,7 +54,7 @@ public virtual void ProcessEntityTypeBaseTypeChanged( IConventionContext context) { if ((newBaseType == null - || oldBaseType != null) + || oldBaseType != null) && entityTypeBuilder.Metadata.BaseType == newBaseType) { Process(entityTypeBuilder); diff --git a/src/EFCore/Metadata/Conventions/QueryFilterDefiningQueryRewritingConvention.cs b/src/EFCore/Metadata/Conventions/QueryFilterDefiningQueryRewritingConvention.cs index fa56f2391af..152b90774b3 100644 --- a/src/EFCore/Metadata/Conventions/QueryFilterDefiningQueryRewritingConvention.cs +++ b/src/EFCore/Metadata/Conventions/QueryFilterDefiningQueryRewritingConvention.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -12,7 +12,8 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// /// Convention that converts accesses of DbSets inside query filters and defining queries into EntityQueryables. - /// This makes them consistent with how DbSet accesses in the actual queries are represented, which allows for easier processing in the query pipeline. + /// This makes them consistent with how DbSet accesses in the actual queries are represented, which allows for easier processing in the + /// query pipeline. /// public class QueryFilterDefiningQueryRewritingConvention : IModelFinalizedConvention { @@ -95,7 +96,8 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp && methodCallExpression.Type.IsGenericType && methodCallExpression.Type.GetGenericTypeDefinition() == typeof(DbSet<>)) { - return NullAsyncQueryProvider.Instance.CreateEntityQueryableExpression(methodCallExpression.Type.GetGenericArguments()[0]); + return NullAsyncQueryProvider.Instance.CreateEntityQueryableExpression( + methodCallExpression.Type.GetGenericArguments()[0]); } return base.VisitMethodCall(methodCallExpression); diff --git a/src/EFCore/Metadata/Conventions/RelationshipDiscoveryConvention.cs b/src/EFCore/Metadata/Conventions/RelationshipDiscoveryConvention.cs index 6deabfee89e..0535c8dc0f8 100644 --- a/src/EFCore/Metadata/Conventions/RelationshipDiscoveryConvention.cs +++ b/src/EFCore/Metadata/Conventions/RelationshipDiscoveryConvention.cs @@ -142,10 +142,7 @@ private IReadOnlyList FindRelationshipCandidates(IConvent continue; } - var navigations = new List - { - navigationPropertyInfo - }; + var navigations = new List { navigationPropertyInfo }; var inverseNavigationCandidates = new List(); if (!entityType.IsKeyless) @@ -223,7 +220,6 @@ private IReadOnlyList FindRelationshipCandidates(IConvent return candidates; } - private static IReadOnlyList RemoveIncompatibleWithExistingRelationships( IReadOnlyList relationshipCandidates, IConventionEntityTypeBuilder entityTypeBuilder) @@ -281,10 +277,7 @@ private static IReadOnlyList RemoveIncompatibleWithExisti filteredRelationshipCandidates.Add( new RelationshipCandidate( targetEntityTypeBuilder, - new List - { - navigationProperty - }, + new List { navigationProperty }, new List())); if (relationshipCandidate.TargetTypeBuilder.Metadata == entityTypeBuilder.Metadata @@ -321,14 +314,8 @@ private static IReadOnlyList RemoveIncompatibleWithExisti filteredRelationshipCandidates.Add( new RelationshipCandidate( targetEntityTypeBuilder, - new List - { - navigationProperty - }, - new List - { - compatibleInverse - }) + new List { navigationProperty }, + new List { compatibleInverse }) ); if (relationshipCandidate.TargetTypeBuilder.Metadata == entityTypeBuilder.Metadata @@ -574,17 +561,11 @@ private void CreateRelationships( { Dependencies.Logger.MultipleNavigationProperties( relationshipCandidate.NavigationProperties.Count == 0 - ? new[] - { - new Tuple(null, targetEntityType.ClrType) - } + ? new[] { new Tuple(null, targetEntityType.ClrType) } : relationshipCandidate.NavigationProperties.Select( n => new Tuple(n, entityType.ClrType)), relationshipCandidate.InverseProperties.Count == 0 - ? new[] - { - new Tuple(null, targetEntityType.ClrType) - } + ? new[] { new Tuple(null, targetEntityType.ClrType) } : relationshipCandidate.InverseProperties.Select( n => new Tuple(n, targetEntityType.ClrType))); } diff --git a/src/EFCore/Metadata/Conventions/RequiredNavigationAttributeConvention.cs b/src/EFCore/Metadata/Conventions/RequiredNavigationAttributeConvention.cs index 44429996c6c..936b4da70a2 100644 --- a/src/EFCore/Metadata/Conventions/RequiredNavigationAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/RequiredNavigationAttributeConvention.cs @@ -13,7 +13,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// /// A convention that configures the principal side of the relationship as required if the - /// is applied on the navigation property to the principal entity type + /// is applied on the navigation property to the principal entity type. /// public class RequiredNavigationAttributeConvention : NavigationAttributeConventionBase { diff --git a/src/EFCore/Metadata/Conventions/RequiredPropertyAttributeConvention.cs b/src/EFCore/Metadata/Conventions/RequiredPropertyAttributeConvention.cs index aa96ca9f3c6..c736093b691 100644 --- a/src/EFCore/Metadata/Conventions/RequiredPropertyAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/RequiredPropertyAttributeConvention.cs @@ -10,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// - /// A convention that configures properties as required if they have the applied. + /// A convention that configures properties as required if they have the applied. /// public class RequiredPropertyAttributeConvention : PropertyAttributeConventionBase { diff --git a/src/EFCore/Metadata/Conventions/StringLengthAttributeConvention.cs b/src/EFCore/Metadata/Conventions/StringLengthAttributeConvention.cs index 208e8f6726d..673c38174ab 100644 --- a/src/EFCore/Metadata/Conventions/StringLengthAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/StringLengthAttributeConvention.cs @@ -10,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// - /// A convention that configures the maximum length based on the applied on the property. + /// A convention that configures the maximum length based on the applied on the property. /// public class StringLengthAttributeConvention : PropertyAttributeConventionBase { diff --git a/src/EFCore/Metadata/Conventions/TimestampAttributeConvention.cs b/src/EFCore/Metadata/Conventions/TimestampAttributeConvention.cs index 507c18520df..5f723a54911 100644 --- a/src/EFCore/Metadata/Conventions/TimestampAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/TimestampAttributeConvention.cs @@ -10,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// - /// A convention that configures the property as a concurrency token if a is applied to it. + /// A convention that configures the property as a concurrency token if a is applied to it. /// public class TimestampAttributeConvention : PropertyAttributeConventionBase { diff --git a/src/EFCore/Metadata/Conventions/TypeMappingConvention.cs b/src/EFCore/Metadata/Conventions/TypeMappingConvention.cs index c5c4aed91b7..5e66528490a 100644 --- a/src/EFCore/Metadata/Conventions/TypeMappingConvention.cs +++ b/src/EFCore/Metadata/Conventions/TypeMappingConvention.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq; diff --git a/src/EFCore/Metadata/Conventions/ValueGenerationConvention.cs b/src/EFCore/Metadata/Conventions/ValueGenerationConvention.cs index b7626c1fdb0..5e9fe430520 100644 --- a/src/EFCore/Metadata/Conventions/ValueGenerationConvention.cs +++ b/src/EFCore/Metadata/Conventions/ValueGenerationConvention.cs @@ -11,7 +11,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// - /// A convention that configures store value generation as on properties that are + /// A convention that configures store value generation as on properties that are /// part of the primary key and not part of any foreign keys. /// public class ValueGenerationConvention : @@ -188,8 +188,8 @@ private static bool ShouldHaveGeneratedProperty(IKey key) { var onOwnedType = key?.DeclaringEntityType.IsOwned(); return key != null - && (onOwnedType.Value && key.Properties.Count(p => !p.IsForeignKey()) == 1 - || !onOwnedType.Value && key.Properties.Count == 1); + && (onOwnedType.Value && key.Properties.Count(p => !p.IsForeignKey()) == 1 + || !onOwnedType.Value && key.Properties.Count == 1); } /// diff --git a/src/EFCore/Metadata/DependencyInjectionMethodParameterBinding.cs b/src/EFCore/Metadata/DependencyInjectionMethodParameterBinding.cs index 0aeb45e563d..ce2748db33f 100644 --- a/src/EFCore/Metadata/DependencyInjectionMethodParameterBinding.cs +++ b/src/EFCore/Metadata/DependencyInjectionMethodParameterBinding.cs @@ -64,10 +64,7 @@ public override Expression BindToParameter( var delegateVariable = Expression.Variable(ParameterType, "delegate"); return Expression.Block( - new[] - { - serviceVariable, delegateVariable - }, + new[] { serviceVariable, delegateVariable }, new List { Expression.Assign( diff --git a/src/EFCore/Metadata/IConventionEntityType.cs b/src/EFCore/Metadata/IConventionEntityType.cs index 0f6eef043ec..7c8f0e4ac34 100644 --- a/src/EFCore/Metadata/IConventionEntityType.cs +++ b/src/EFCore/Metadata/IConventionEntityType.cs @@ -202,7 +202,7 @@ IConventionForeignKey AddForeignKey( /// /// /// The corresponding CLR type member or null for a shadow property. - /// + /// /// /// An indexer with a string parameter and object return type can be used. /// diff --git a/src/EFCore/Metadata/IMutableEntityType.cs b/src/EFCore/Metadata/IMutableEntityType.cs index 589372a0684..93e667589bd 100644 --- a/src/EFCore/Metadata/IMutableEntityType.cs +++ b/src/EFCore/Metadata/IMutableEntityType.cs @@ -159,7 +159,7 @@ IMutableForeignKey AddForeignKey( /// /// /// The corresponding CLR type member or null for a shadow property. - /// + /// /// /// An indexer with a string parameter and object return type can be used. /// diff --git a/src/EFCore/Metadata/Internal/ClrAccessorFactory.cs b/src/EFCore/Metadata/Internal/ClrAccessorFactory.cs index 34260a94078..99ce5e9aadb 100644 --- a/src/EFCore/Metadata/Internal/ClrAccessorFactory.cs +++ b/src/EFCore/Metadata/Internal/ClrAccessorFactory.cs @@ -58,10 +58,7 @@ protected virtual TAccessor Create(MemberInfo memberInfo, IPropertyBase property try { return (TAccessor)boundMethod.Invoke( - this, new object[] - { - memberInfo, propertyBase - }); + this, new object[] { memberInfo, propertyBase }); } catch (TargetInvocationException e) when (e.InnerException != null) { diff --git a/src/EFCore/Metadata/Internal/ClrCollectionAccessor.cs b/src/EFCore/Metadata/Internal/ClrCollectionAccessor.cs index 7adb42ba0cb..8ae71c560e6 100644 --- a/src/EFCore/Metadata/Internal/ClrCollectionAccessor.cs +++ b/src/EFCore/Metadata/Internal/ClrCollectionAccessor.cs @@ -183,6 +183,7 @@ public virtual bool Remove(object entity, object value) return true; } } + return false; case Collection concreteCollection: for (var i = 0; i < concreteCollection.Count; i++) @@ -193,6 +194,7 @@ public virtual bool Remove(object entity, object value) return true; } } + return false; case SortedSet sortedSet: return sortedSet.TryGetValue((TElement)value, out var found) @@ -215,6 +217,7 @@ private static bool Contains(ICollection collection, object value) return true; } } + return false; case Collection concreteCollection: for (var i = 0; i < concreteCollection.Count; i++) @@ -224,6 +227,7 @@ private static bool Contains(ICollection collection, object value) return true; } } + return false; case SortedSet sortedSet: return sortedSet.TryGetValue((TElement)value, out var found) diff --git a/src/EFCore/Metadata/Internal/ClrCollectionAccessorFactory.cs b/src/EFCore/Metadata/Internal/ClrCollectionAccessorFactory.cs index 77ba642fca8..549f1306129 100644 --- a/src/EFCore/Metadata/Internal/ClrCollectionAccessorFactory.cs +++ b/src/EFCore/Metadata/Internal/ClrCollectionAccessorFactory.cs @@ -99,10 +99,7 @@ MemberInfo GetMostDerivedMemberInfo() try { return (IClrCollectionAccessor)boundMethod.Invoke( - null, new object[] - { - navigation - }); + null, new object[] { navigation }); } catch (TargetInvocationException invocationException) { diff --git a/src/EFCore/Metadata/Internal/ClrPropertyGetterFactory.cs b/src/EFCore/Metadata/Internal/ClrPropertyGetterFactory.cs index 8da5fde8d59..21aacb44192 100644 --- a/src/EFCore/Metadata/Internal/ClrPropertyGetterFactory.cs +++ b/src/EFCore/Metadata/Internal/ClrPropertyGetterFactory.cs @@ -6,8 +6,6 @@ using System.Linq.Expressions; using System.Reflection; using Microsoft.EntityFrameworkCore.ChangeTracking; -using Microsoft.EntityFrameworkCore.Diagnostics; -using Microsoft.EntityFrameworkCore.Infrastructure; namespace Microsoft.EntityFrameworkCore.Metadata.Internal { @@ -50,10 +48,7 @@ protected override IClrPropertyGetter CreateGeneric { Expression.Assign( @@ -96,10 +91,7 @@ protected override IClrPropertyGetter CreateGeneric).MakeGenericType(typeof(TValue)), - new object[] - { - false - }); + new object[] { false }); hasDefaultValueExpression = comparer.ExtractEqualsBody( comparer.Type != typeof(TValue) diff --git a/src/EFCore/Metadata/Internal/ClrPropertySetterFactory.cs b/src/EFCore/Metadata/Internal/ClrPropertySetterFactory.cs index 37918417ef1..2e4145ffbfc 100644 --- a/src/EFCore/Metadata/Internal/ClrPropertySetterFactory.cs +++ b/src/EFCore/Metadata/Internal/ClrPropertySetterFactory.cs @@ -54,10 +54,7 @@ protected override IClrPropertySetter CreateGeneric { Expression.Assign( diff --git a/src/EFCore/Metadata/Internal/EntityType.cs b/src/EFCore/Metadata/Internal/EntityType.cs index b7eec3c0abe..14e65d88011 100644 --- a/src/EFCore/Metadata/Internal/EntityType.cs +++ b/src/EFCore/Metadata/Internal/EntityType.cs @@ -420,10 +420,7 @@ public virtual IEnumerable GetDerivedTypes() /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual IEnumerable GetDerivedTypesInclusive() - => new[] - { - this - }.Concat(GetDerivedTypes()); + => new[] { this }.Concat(GetDerivedTypes()); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -501,10 +498,7 @@ public virtual Key SetPrimaryKey([CanBeNull] Property property, ConfigurationSou => SetPrimaryKey( property == null ? null - : new[] - { - property - }, configurationSource); + : new[] { property }, configurationSource); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -663,10 +657,7 @@ private void UpdatePrimaryKeyConfigurationSource(ConfigurationSource configurati /// public virtual Key AddKey([NotNull] Property property, ConfigurationSource configurationSource) => AddKey( - new[] - { - property - }, configurationSource); + new[] { property }, configurationSource); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -735,10 +726,7 @@ public virtual Key AddKey( { if (property.Keys == null) { - property.Keys = new List - { - key - }; + property.Keys = new List { key }; } else { @@ -756,10 +744,7 @@ public virtual Key AddKey( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual Key FindKey([NotNull] IProperty property) => FindKey( - new[] - { - property - }); + new[] { property }); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -887,10 +872,7 @@ public virtual ForeignKey AddForeignKey( ConfigurationSource? componentConfigurationSource, ConfigurationSource configurationSource) => AddForeignKey( - new[] - { - property - }, principalKey, principalEntityType, componentConfigurationSource, configurationSource); + new[] { property }, principalKey, principalEntityType, componentConfigurationSource, configurationSource); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -970,10 +952,7 @@ public virtual void OnForeignKeyUpdated(ForeignKey foreignKey) { if (property.ForeignKeys == null) { - property.ForeignKeys = new List - { - foreignKey - }; + property.ForeignKeys = new List { foreignKey }; } else { @@ -984,10 +963,7 @@ public virtual void OnForeignKeyUpdated(ForeignKey foreignKey) var principalKey = foreignKey.PrincipalKey; if (principalKey.ReferencingForeignKeys == null) { - principalKey.ReferencingForeignKeys = new SortedSet(ForeignKeyComparer.Instance) - { - foreignKey - }; + principalKey.ReferencingForeignKeys = new SortedSet(ForeignKeyComparer.Instance) { foreignKey }; } else { @@ -998,10 +974,7 @@ public virtual void OnForeignKeyUpdated(ForeignKey foreignKey) var principalEntityType = foreignKey.PrincipalEntityType; if (principalEntityType.DeclaredReferencingForeignKeys == null) { - principalEntityType.DeclaredReferencingForeignKeys = new SortedSet(ForeignKeyComparer.Instance) - { - foreignKey - }; + principalEntityType.DeclaredReferencingForeignKeys = new SortedSet(ForeignKeyComparer.Instance) { foreignKey }; } else { @@ -1018,10 +991,7 @@ public virtual void OnForeignKeyUpdated(ForeignKey foreignKey) /// public virtual IEnumerable FindForeignKeys([NotNull] IProperty property) => FindForeignKeys( - new[] - { - property - }); + new[] { property }); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -1049,10 +1019,7 @@ public virtual ForeignKey FindForeignKey( [NotNull] IKey principalKey, [NotNull] IEntityType principalEntityType) => FindForeignKey( - new[] - { - property - }, principalKey, principalEntityType); + new[] { property }, principalKey, principalEntityType); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -1531,10 +1498,7 @@ public virtual Index AddIndex( [NotNull] Property property, ConfigurationSource configurationSource) => AddIndex( - new[] - { - property - }, configurationSource); + new[] { property }, configurationSource); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -1581,10 +1545,7 @@ public virtual Index AddIndex( { if (property.Indexes == null) { - property.Indexes = new List - { - index - }; + property.Indexes = new List { index }; } else { @@ -1603,10 +1564,7 @@ public virtual Index AddIndex( /// public virtual Index FindIndex([NotNull] IProperty property) => FindIndex( - new[] - { - property - }); + new[] { property }); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -1961,6 +1919,7 @@ public virtual IReadOnlyList FindProperties([NotNull] IReadOnlyList IMutableEntityType.GetServiceProperties() => GetServiceProperties(); /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - IMutableServiceProperty IMutableEntityType.RemoveServiceProperty(string name) => RemoveServiceProperty(name); + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// any release. You should only use it directly in your code with extreme caution and knowing that + /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + IMutableServiceProperty IMutableEntityType.RemoveServiceProperty(string name) => RemoveServiceProperty(name); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -3200,10 +3159,7 @@ private static IEnumerable ToEnumerable(T element) where T : class => element == null ? Enumerable.Empty() - : new[] - { - element - }; + : new[] { element }; private class PropertyComparer : IComparer { diff --git a/src/EFCore/Metadata/Internal/EntityTypeExtensions.cs b/src/EFCore/Metadata/Internal/EntityTypeExtensions.cs index f72b7754bca..a67c55cccaa 100644 --- a/src/EFCore/Metadata/Internal/EntityTypeExtensions.cs +++ b/src/EFCore/Metadata/Internal/EntityTypeExtensions.cs @@ -1,9 +1,8 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; diff --git a/src/EFCore/Metadata/Internal/EntityTypePathComparer.cs b/src/EFCore/Metadata/Internal/EntityTypePathComparer.cs index 96d75a1aeea..22a4f234f01 100644 --- a/src/EFCore/Metadata/Internal/EntityTypePathComparer.cs +++ b/src/EFCore/Metadata/Internal/EntityTypePathComparer.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using JetBrains.Annotations; namespace Microsoft.EntityFrameworkCore.Metadata.Internal { diff --git a/src/EFCore/Metadata/Internal/ForeignKey.cs b/src/EFCore/Metadata/Internal/ForeignKey.cs index 9bb53ccb5ae..b440d46221d 100644 --- a/src/EFCore/Metadata/Internal/ForeignKey.cs +++ b/src/EFCore/Metadata/Internal/ForeignKey.cs @@ -918,8 +918,7 @@ IMutableNavigation IMutableForeignKey.HasPrincipalToDependent(MemberInfo propert /// IConventionEntityType IConventionForeignKey.DeclaringEntityType { - [DebuggerStepThrough] - get => DeclaringEntityType; + [DebuggerStepThrough] get => DeclaringEntityType; } /// @@ -930,8 +929,7 @@ IConventionEntityType IConventionForeignKey.DeclaringEntityType /// IConventionEntityType IConventionForeignKey.PrincipalEntityType { - [DebuggerStepThrough] - get => PrincipalEntityType; + [DebuggerStepThrough] get => PrincipalEntityType; } /// @@ -942,8 +940,7 @@ IConventionEntityType IConventionForeignKey.PrincipalEntityType /// IConventionKey IConventionForeignKey.PrincipalKey { - [DebuggerStepThrough] - get => PrincipalKey; + [DebuggerStepThrough] get => PrincipalKey; } /// @@ -954,8 +951,7 @@ IConventionKey IConventionForeignKey.PrincipalKey /// IReadOnlyList IConventionForeignKey.Properties { - [DebuggerStepThrough] - get => Properties; + [DebuggerStepThrough] get => Properties; } /// @@ -966,8 +962,7 @@ IReadOnlyList IConventionForeignKey.Properties /// IConventionNavigation IConventionForeignKey.DependentToPrincipal { - [DebuggerStepThrough] - get => DependentToPrincipal; + [DebuggerStepThrough] get => DependentToPrincipal; } /// @@ -978,8 +973,7 @@ IConventionNavigation IConventionForeignKey.DependentToPrincipal /// IConventionNavigation IConventionForeignKey.PrincipalToDependent { - [DebuggerStepThrough] - get => PrincipalToDependent; + [DebuggerStepThrough] get => PrincipalToDependent; } /// diff --git a/src/EFCore/Metadata/Internal/IMemberClassifier.cs b/src/EFCore/Metadata/Internal/IMemberClassifier.cs index 2e1b9895b50..f15322eb21c 100644 --- a/src/EFCore/Metadata/Internal/IMemberClassifier.cs +++ b/src/EFCore/Metadata/Internal/IMemberClassifier.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Metadata/Internal/InternalEntityTypeBuilder.cs b/src/EFCore/Metadata/Internal/InternalEntityTypeBuilder.cs index c45ca376d36..4a2bdd56a76 100644 --- a/src/EFCore/Metadata/Internal/InternalEntityTypeBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalEntityTypeBuilder.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -456,10 +456,7 @@ private InternalPropertyBuilder Property( { if (configurationSource.Overrides(existingProperty.GetConfigurationSource())) { - propertiesToDetach = new List - { - existingProperty - }; + propertiesToDetach = new List { existingProperty }; } else { @@ -618,10 +615,7 @@ private InternalPropertyBuilder Property( using (Metadata.Model.ConventionDispatcher.DelayConventions()) { var detachedProperties = DetachProperties( - new[] - { - existingProperty - }); + new[] { existingProperty }); property = clrProperty != null ? Metadata.AddProperty(clrProperty, configurationSource.Value) @@ -850,7 +844,7 @@ public virtual InternalEntityTypeBuilder Ignore([NotNull] string name, Configura if (foreignKey.GetConfigurationSource() != navigationConfigurationSource) { var navigationRemoved = foreignKey.Builder.HasNavigation( - (MemberInfo)null, isDependent, configurationSource); + (MemberInfo)null, isDependent, configurationSource); Debug.Assert(navigationRemoved != null); } else @@ -2930,13 +2924,7 @@ private ForeignKey SetOrAddForeignKey( if (principalKey == null) { var principalKeyProperties = principalBaseEntityTypeBuilder.TryCreateUniqueProperties( - 1, null, new[] - { - "TempId" - }, new[] - { - typeof(int) - }, isRequired: true, baseName: "").Item2; + 1, null, new[] { "TempId" }, new[] { typeof(int) }, isRequired: true, baseName: "").Item2; principalKey = principalBaseEntityTypeBuilder.HasKeyInternal( principalKeyProperties, ConfigurationSource.Convention).Metadata; @@ -2967,26 +2955,23 @@ private ForeignKey SetOrAddForeignKey( return Metadata.AddForeignKey( dependentProperties, principalKey, principalType, componentConfigurationSource: null, configurationSource.Value); } - else - { - var oldProperties = foreignKey.Properties; - var oldKey = foreignKey.PrincipalKey; - foreignKey.SetProperties(dependentProperties, principalKey, configurationSource); - if (oldProperties != dependentProperties) - { - foreignKey.DeclaringEntityType.Builder.RemoveUnusedShadowProperties(oldProperties); - } + var oldFKProperties = foreignKey.Properties; + var oldPrincipalKey = foreignKey.PrincipalKey; + foreignKey.SetProperties(dependentProperties, principalKey, configurationSource); - if (oldKey != principalKey) - { - oldKey.DeclaringEntityType.Builder.RemoveKeyIfUnused(oldKey); - } + if (oldFKProperties != dependentProperties) + { + foreignKey.DeclaringEntityType.Builder.RemoveUnusedShadowProperties(oldFKProperties); + } - return foreignKey; + if (oldPrincipalKey != principalKey) + { + oldPrincipalKey.DeclaringEntityType.Builder.RemoveKeyIfUnused(oldPrincipalKey); } - } + return foreignKey; + } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -3016,14 +3001,8 @@ public virtual Property CreateUniqueProperty( Type propertyType, bool isRequired) => CreateUniqueProperties( - new[] - { - propertyName - }, - new[] - { - propertyType - }, + new[] { propertyName }, + new[] { propertyType }, isRequired).First(); /// @@ -3098,7 +3077,8 @@ private IReadOnlyList CreateUniqueProperties( if (currentProperties == null) { var propertyBuilder = Property( - clrType, propertyName, typeConfigurationSource: null, configurationSource: ConfigurationSource.Convention); + clrType, propertyName, typeConfigurationSource: null, + configurationSource: ConfigurationSource.Convention); if (clrType.IsNullableType()) { @@ -3183,7 +3163,7 @@ public virtual IReadOnlyList GetOrCreateProperties( ? type : type?.MakeNullable(), propertyName, - typeConfigurationSource: null, + typeConfigurationSource: null, configurationSource.Value); if (propertyBuilder == null) @@ -3201,9 +3181,9 @@ public virtual IReadOnlyList GetOrCreateProperties( && property.ClrType.IsNullableType()) { property = property.DeclaringEntityType.Builder.Property( - property.ClrType.MakeNullable(false), - property.Name, - configurationSource.Value) + property.ClrType.MakeNullable(false), + property.Name, + configurationSource.Value) .Metadata; } else @@ -3420,10 +3400,7 @@ private void RemoveUnusedDiscriminatorProperty(Property newDiscriminatorProperty && oldDiscriminatorProperty != newDiscriminatorProperty) { oldDiscriminatorProperty.DeclaringEntityType.Builder.RemoveUnusedShadowProperties( - new[] - { - oldDiscriminatorProperty - }); + new[] { oldDiscriminatorProperty }); if (oldDiscriminatorProperty.Builder != null) { @@ -3615,7 +3592,8 @@ IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasNoKey(bool fromData /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasNoKey(IReadOnlyList properties, bool fromDataAnnotation) + IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasNoKey( + IReadOnlyList properties, bool fromDataAnnotation) { Check.NotEmpty(properties, nameof(properties)); @@ -3652,7 +3630,8 @@ IConventionIndexBuilder IConventionEntityTypeBuilder.HasIndex( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasNoIndex(IReadOnlyList properties, bool fromDataAnnotation) + IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasNoIndex( + IReadOnlyList properties, bool fromDataAnnotation) { Check.NotEmpty(properties, nameof(properties)); @@ -3863,8 +3842,10 @@ IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasNoRelationship( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasNoRelationship(IConventionForeignKey foreignKey, bool fromDataAnnotation) - => HasNoRelationship((ForeignKey)foreignKey, + IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasNoRelationship( + IConventionForeignKey foreignKey, bool fromDataAnnotation) + => HasNoRelationship( + (ForeignKey)foreignKey, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -3874,7 +3855,8 @@ IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasNoRelationship(ICon /// doing so can result in application failures when updating to a new Entity Framework Core release. /// bool IConventionEntityTypeBuilder.CanAddNavigation(string navigationName, bool fromDataAnnotation) - => CanAddNavigation(navigationName, + => CanAddNavigation( + navigationName, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -4015,7 +3997,8 @@ IConventionDiscriminatorBuilder IConventionEntityTypeBuilder.HasDiscriminator(st /// doing so can result in application failures when updating to a new Entity Framework Core release. /// IConventionDiscriminatorBuilder IConventionEntityTypeBuilder.HasDiscriminator(MemberInfo memberInfo, bool fromDataAnnotation) - => ((IConventionEntityTypeBuilder)this).CanSetDiscriminator(memberInfo.GetMemberType(), memberInfo.GetSimpleMemberName(), fromDataAnnotation) + => ((IConventionEntityTypeBuilder)this).CanSetDiscriminator( + memberInfo.GetMemberType(), memberInfo.GetSimpleMemberName(), fromDataAnnotation) ? DiscriminatorBuilder( Metadata.RootType().Builder.Property( memberInfo, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention), diff --git a/src/EFCore/Metadata/Internal/InternalModelBuilder.cs b/src/EFCore/Metadata/Internal/InternalModelBuilder.cs index 6432b9d6685..bf4d2723bf6 100644 --- a/src/EFCore/Metadata/Internal/InternalModelBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalModelBuilder.cs @@ -602,7 +602,8 @@ IConventionModelBuilder IConventionModelBuilder.Ignore(string name, bool fromDat /// doing so can result in application failures when updating to a new Entity Framework Core release. /// IConventionModelBuilder IConventionModelBuilder.HasNoEntityType(IConventionEntityType entityType, bool fromDataAnnotation) - => HasNoEntityType((EntityType)entityType, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); + => HasNoEntityType( + (EntityType)entityType, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore/Metadata/Internal/InternalNavigationBuilder.cs b/src/EFCore/Metadata/Internal/InternalNavigationBuilder.cs index 869f5b0419e..9e332369e7d 100644 --- a/src/EFCore/Metadata/Internal/InternalNavigationBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalNavigationBuilder.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore/Metadata/Internal/InternalOwnedEntityTypeBuilder.cs b/src/EFCore/Metadata/Internal/InternalOwnedEntityTypeBuilder.cs index 98a9ef273d1..46a64d748ff 100644 --- a/src/EFCore/Metadata/Internal/InternalOwnedEntityTypeBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalOwnedEntityTypeBuilder.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.Metadata.Builders; diff --git a/src/EFCore/Metadata/Internal/InternalRelationshipBuilder.cs b/src/EFCore/Metadata/Internal/InternalRelationshipBuilder.cs index 90f2542bc7e..3fe8a2d7fbe 100644 --- a/src/EFCore/Metadata/Internal/InternalRelationshipBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalRelationshipBuilder.cs @@ -1346,7 +1346,8 @@ public virtual InternalRelationshipBuilder DependentEntityType( { Metadata.UpdatePrincipalEndConfigurationSource(configurationSource); - builder = (InternalRelationshipBuilder)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(builder); + builder = + (InternalRelationshipBuilder)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(builder); } return builder; @@ -1411,7 +1412,8 @@ public virtual InternalRelationshipBuilder PrincipalEntityType( { Metadata.UpdatePrincipalEndConfigurationSource(configurationSource); - builder = (InternalRelationshipBuilder)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(builder); + builder = + (InternalRelationshipBuilder)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(builder); } return builder; @@ -1735,7 +1737,8 @@ public virtual InternalRelationshipBuilder HasForeignKey( { Metadata.UpdatePrincipalEndConfigurationSource(configurationSource); - builder = (InternalRelationshipBuilder)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(builder); + builder = + (InternalRelationshipBuilder)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(builder); } return builder; @@ -1768,10 +1771,10 @@ public virtual bool CanSetForeignKey([CanBeNull] IReadOnlyList propertyN if (properties != null) { return CanSetForeignKey( - properties, - dependentEntityType: null, - configurationSource, - out _); + properties, + dependentEntityType: null, + configurationSource, + out _); } return configurationSource.Overrides(Metadata.GetPropertiesConfigurationSource()); @@ -1935,7 +1938,8 @@ public virtual InternalRelationshipBuilder HasPrincipalKey( { Metadata.UpdatePrincipalEndConfigurationSource(configurationSource); - builder = (InternalRelationshipBuilder)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(builder); + builder = + (InternalRelationshipBuilder)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(builder); } return builder; @@ -1967,10 +1971,10 @@ public virtual bool CanSetPrincipalKey([CanBeNull] IReadOnlyList propert if (properties != null) { return CanSetPrincipalKey( - properties, - configurationSource, - out _, - out _); + properties, + configurationSource, + out _, + out _); } return configurationSource.Overrides(Metadata.GetPrincipalKeyConfigurationSource()); @@ -2057,11 +2061,11 @@ private InternalRelationshipBuilder ReplaceForeignKey( bool oldRelationshipInverted = false) { principalEntityTypeBuilder ??= (oldRelationshipInverted - ? Metadata.DeclaringEntityType.Builder - : Metadata.PrincipalEntityType.Builder); + ? Metadata.DeclaringEntityType.Builder + : Metadata.PrincipalEntityType.Builder); dependentEntityTypeBuilder ??= (oldRelationshipInverted - ? Metadata.PrincipalEntityType.Builder - : Metadata.DeclaringEntityType.Builder); + ? Metadata.PrincipalEntityType.Builder + : Metadata.DeclaringEntityType.Builder); if (navigationToPrincipal == null) { @@ -2100,39 +2104,39 @@ private InternalRelationshipBuilder ReplaceForeignKey( } dependentProperties ??= ((Metadata.GetPropertiesConfigurationSource()?.Overrides(configurationSource) ?? false) - && !oldRelationshipInverted - ? Metadata.Properties - : null); + && !oldRelationshipInverted + ? Metadata.Properties + : null); principalProperties ??= ((Metadata.GetPrincipalKeyConfigurationSource()?.Overrides(configurationSource) ?? false) - && !oldRelationshipInverted - ? Metadata.PrincipalKey.Properties - : null); + && !oldRelationshipInverted + ? Metadata.PrincipalKey.Properties + : null); isUnique ??= ((Metadata.GetIsUniqueConfigurationSource()?.Overrides(configurationSource) ?? false) - ? Metadata.IsUnique - : (bool?)null); + ? Metadata.IsUnique + : (bool?)null); isRequired ??= ((Metadata.GetIsRequiredConfigurationSource()?.Overrides(configurationSource) ?? false) - ? Metadata.IsRequired - : (bool?)null); + ? Metadata.IsRequired + : (bool?)null); isOwnership ??= ((Metadata.GetIsOwnershipConfigurationSource()?.Overrides(configurationSource) ?? false) - && !oldRelationshipInverted - ? Metadata.IsOwnership - : (bool?)null); + && !oldRelationshipInverted + ? Metadata.IsOwnership + : (bool?)null); deleteBehavior ??= ((Metadata.GetDeleteBehaviorConfigurationSource()?.Overrides(configurationSource) ?? false) - ? Metadata.DeleteBehavior - : (DeleteBehavior?)null); + ? Metadata.DeleteBehavior + : (DeleteBehavior?)null); principalEndConfigurationSource ??= (principalEntityTypeBuilder.Metadata != dependentEntityTypeBuilder.Metadata - && ((principalProperties?.Count > 0) - || (dependentProperties?.Count > 0) - || (navigationToDependent != null && isUnique == false) - || isOwnership == true) - ? configurationSource - : (ConfigurationSource?)null); + && ((principalProperties?.Count > 0) + || (dependentProperties?.Count > 0) + || (navigationToDependent != null && isUnique == false) + || isOwnership == true) + ? configurationSource + : (ConfigurationSource?)null); principalEndConfigurationSource = principalEndConfigurationSource.Max(Metadata.GetPrincipalEndConfigurationSource()); return ReplaceForeignKey( @@ -2546,12 +2550,12 @@ private InternalRelationshipBuilder GetOrCreateRelationshipBuilder( { existingRelationshipInverted = null; var matchingRelationships = FindRelationships( - principalEntityType, - dependentEntityType, - navigationToPrincipal, - navigationToDependent, - dependentProperties, - principalProperties ?? principalEntityType.FindPrimaryKey()?.Properties) + principalEntityType, + dependentEntityType, + navigationToPrincipal, + navigationToDependent, + dependentProperties, + principalProperties ?? principalEntityType.FindPrimaryKey()?.Properties) .Where(r => r.Metadata != Metadata) .Distinct() .ToList(); @@ -2701,7 +2705,8 @@ private InternalRelationshipBuilder GetOrCreateRelationshipBuilder( if (dependentProperties != null && matchingRelationship.Metadata.Properties.SequenceEqual(dependentProperties)) { - if (matchingRelationship.CanSetForeignKey(properties: null, dependentEntityType: null, configurationSource: configurationSource, overrideSameSource: false)) + if (matchingRelationship.CanSetForeignKey( + properties: null, dependentEntityType: null, configurationSource: configurationSource, overrideSameSource: false)) { resolution |= Resolution.ResetDependentProperties; sameConfigurationSource ??= false; @@ -3631,8 +3636,7 @@ private enum Resolution /// IConventionForeignKey IConventionRelationshipBuilder.Metadata { - [DebuggerStepThrough] - get => Metadata; + [DebuggerStepThrough] get => Metadata; } /// @@ -3852,7 +3856,8 @@ IConventionRelationshipBuilder IConventionRelationshipBuilder.HasField( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - IConventionRelationshipBuilder IConventionRelationshipBuilder.HasField(FieldInfo fieldInfo, bool pointsToPrincipal, bool fromDataAnnotation) + IConventionRelationshipBuilder IConventionRelationshipBuilder.HasField( + FieldInfo fieldInfo, bool pointsToPrincipal, bool fromDataAnnotation) => HasField( fieldInfo, pointsToPrincipal, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); diff --git a/src/EFCore/Metadata/Internal/Key.cs b/src/EFCore/Metadata/Internal/Key.cs index 368a25b2f64..a45b7d792c9 100644 --- a/src/EFCore/Metadata/Internal/Key.cs +++ b/src/EFCore/Metadata/Internal/Key.cs @@ -176,8 +176,7 @@ public virtual DebugView DebugView /// IReadOnlyList IKey.Properties { - [DebuggerStepThrough] - get => Properties; + [DebuggerStepThrough] get => Properties; } /// @@ -188,8 +187,7 @@ IReadOnlyList IKey.Properties /// IEntityType IKey.DeclaringEntityType { - [DebuggerStepThrough] - get => DeclaringEntityType; + [DebuggerStepThrough] get => DeclaringEntityType; } /// @@ -200,8 +198,7 @@ IEntityType IKey.DeclaringEntityType /// IReadOnlyList IMutableKey.Properties { - [DebuggerStepThrough] - get => Properties; + [DebuggerStepThrough] get => Properties; } /// @@ -212,8 +209,7 @@ IReadOnlyList IMutableKey.Properties /// IMutableEntityType IMutableKey.DeclaringEntityType { - [DebuggerStepThrough] - get => DeclaringEntityType; + [DebuggerStepThrough] get => DeclaringEntityType; } /// @@ -224,8 +220,7 @@ IMutableEntityType IMutableKey.DeclaringEntityType /// IConventionKeyBuilder IConventionKey.Builder { - [DebuggerStepThrough] - get => Builder; + [DebuggerStepThrough] get => Builder; } /// @@ -236,8 +231,7 @@ IConventionKeyBuilder IConventionKey.Builder /// IReadOnlyList IConventionKey.Properties { - [DebuggerStepThrough] - get => Properties; + [DebuggerStepThrough] get => Properties; } /// @@ -248,8 +242,7 @@ IReadOnlyList IConventionKey.Properties /// IConventionEntityType IConventionKey.DeclaringEntityType { - [DebuggerStepThrough] - get => DeclaringEntityType; + [DebuggerStepThrough] get => DeclaringEntityType; } } } diff --git a/src/EFCore/Metadata/Internal/MemberClassifier.cs b/src/EFCore/Metadata/Internal/MemberClassifier.cs index f0f8a0d4964..5f9ca285d48 100644 --- a/src/EFCore/Metadata/Internal/MemberClassifier.cs +++ b/src/EFCore/Metadata/Internal/MemberClassifier.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Metadata/Internal/Model.cs b/src/EFCore/Metadata/Internal/Model.cs index 209bc1f87be..542a503c09a 100644 --- a/src/EFCore/Metadata/Internal/Model.cs +++ b/src/EFCore/Metadata/Internal/Model.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -529,10 +529,7 @@ public virtual IReadOnlyCollection GetEntityTypes([NotNull] string n var entityType = FindEntityType(name); return entityType == null ? Array.Empty() - : new[] - { - entityType - }; + : new[] { entityType }; } /// @@ -544,10 +541,7 @@ public virtual IReadOnlyCollection GetEntityTypes([NotNull] string n public virtual IReadOnlyList FindLeastDerivedEntityTypes( [NotNull] Type type, [CanBeNull] Func condition = null) { - var derivedLevels = new Dictionary - { - [type.GetTypeInfo()] = 0 - }; + var derivedLevels = new Dictionary { [type.GetTypeInfo()] = 0 }; var leastDerivedTypesGroups = GetEntityTypes() .GroupBy(t => GetDerivedLevel(t.ClrType.GetTypeInfo(), derivedLevels)) @@ -973,8 +967,7 @@ void IMutableModel.AddIgnored(string name) /// IConventionModelBuilder IConventionModel.Builder { - [DebuggerStepThrough] - get => Builder; + [DebuggerStepThrough] get => Builder; } /// diff --git a/src/EFCore/Metadata/Internal/PropertiesSnapshot.cs b/src/EFCore/Metadata/Internal/PropertiesSnapshot.cs index a31370f5eae..c695301fa15 100644 --- a/src/EFCore/Metadata/Internal/PropertiesSnapshot.cs +++ b/src/EFCore/Metadata/Internal/PropertiesSnapshot.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; diff --git a/src/EFCore/Metadata/Internal/PropertyAccessorsFactory.cs b/src/EFCore/Metadata/Internal/PropertyAccessorsFactory.cs index 858d289d844..8fc0c074eff 100644 --- a/src/EFCore/Metadata/Internal/PropertyAccessorsFactory.cs +++ b/src/EFCore/Metadata/Internal/PropertyAccessorsFactory.cs @@ -29,10 +29,7 @@ public virtual PropertyAccessors Create([NotNull] IPropertyBase propertyBase) => (PropertyAccessors)_genericCreate .MakeGenericMethod(propertyBase.ClrType) .Invoke( - null, new object[] - { - propertyBase - }); + null, new object[] { propertyBase }); private static readonly MethodInfo _genericCreate = typeof(PropertyAccessorsFactory).GetTypeInfo().GetDeclaredMethod(nameof(CreateGeneric)); diff --git a/src/EFCore/Metadata/Internal/PropertyExtensions.cs b/src/EFCore/Metadata/Internal/PropertyExtensions.cs index d5ccac007f5..09c8c8ff612 100644 --- a/src/EFCore/Metadata/Internal/PropertyExtensions.cs +++ b/src/EFCore/Metadata/Internal/PropertyExtensions.cs @@ -65,10 +65,7 @@ public static IEnumerable GetReferencingForeignKeys([NotNull] this /// public static IProperty GetGenerationProperty([NotNull] this IProperty property) { - var traversalList = new List - { - property - }; + var traversalList = new List { property }; var index = 0; while (index < traversalList.Count) @@ -164,10 +161,7 @@ public static bool IsKeyOrForeignKey([NotNull] this IProperty property) /// public static IReadOnlyList FindPrincipals([NotNull] this IProperty property) { - var principals = new List - { - property - }; + var principals = new List { property }; AddPrincipals(property, principals); return principals; } diff --git a/src/EFCore/Metadata/Internal/PropertyListComparer.cs b/src/EFCore/Metadata/Internal/PropertyListComparer.cs index 6ea557f64fe..621977370b5 100644 --- a/src/EFCore/Metadata/Internal/PropertyListComparer.cs +++ b/src/EFCore/Metadata/Internal/PropertyListComparer.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Linq; namespace Microsoft.EntityFrameworkCore.Metadata.Internal { @@ -75,6 +74,7 @@ public int GetHashCode(IReadOnlyList obj) { hash.Add(obj[i]); } + return hash.ToHashCode(); } } diff --git a/src/EFCore/Metadata/Internal/TypeBaseExtensions.cs b/src/EFCore/Metadata/Internal/TypeBaseExtensions.cs index d7a3b2fec53..9f39ca39f12 100644 --- a/src/EFCore/Metadata/Internal/TypeBaseExtensions.cs +++ b/src/EFCore/Metadata/Internal/TypeBaseExtensions.cs @@ -1,14 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Collections.Generic; using System.Diagnostics; -using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using JetBrains.Annotations; -using Microsoft.EntityFrameworkCore.Diagnostics; namespace Microsoft.EntityFrameworkCore.Metadata.Internal { diff --git a/src/EFCore/Metadata/MemberIdentity.cs b/src/EFCore/Metadata/MemberIdentity.cs index 73e80970991..0f5ab36fca4 100644 --- a/src/EFCore/Metadata/MemberIdentity.cs +++ b/src/EFCore/Metadata/MemberIdentity.cs @@ -4,7 +4,6 @@ using System.Diagnostics; using System.Reflection; using JetBrains.Annotations; -using Microsoft.EntityFrameworkCore.Metadata.Internal; namespace Microsoft.EntityFrameworkCore.Metadata { diff --git a/src/EFCore/Metadata/ServiceParameterBinding.cs b/src/EFCore/Metadata/ServiceParameterBinding.cs index da34a41e0a0..4a8dea6c6e9 100644 --- a/src/EFCore/Metadata/ServiceParameterBinding.cs +++ b/src/EFCore/Metadata/ServiceParameterBinding.cs @@ -32,10 +32,7 @@ protected ServiceParameterBinding( [CanBeNull] IPropertyBase serviceProperty = null) : base( parameterType, serviceProperty != null - ? new[] - { - serviceProperty - } + ? new[] { serviceProperty } : Array.Empty()) { Check.NotNull(serviceType, nameof(serviceType)); diff --git a/src/EFCore/ModelBuilder.cs b/src/EFCore/ModelBuilder.cs index 0447071ecfd..40713b6f049 100644 --- a/src/EFCore/ModelBuilder.cs +++ b/src/EFCore/ModelBuilder.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -7,7 +7,6 @@ using System.Reflection; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions; @@ -373,14 +372,16 @@ public virtual ModelBuilder ApplyConfiguration([NotNull] IQueryTypeConfi /// /// The same instance so that additional configuration calls can be chained. /// - public virtual ModelBuilder ApplyConfigurationsFromAssembly([NotNull] Assembly assembly, [CanBeNull] Func predicate = null) + public virtual ModelBuilder ApplyConfigurationsFromAssembly( + [NotNull] Assembly assembly, [CanBeNull] Func predicate = null) { var applyEntityConfigurationMethod = typeof(ModelBuilder) .GetMethods() .Single( e => e.Name == nameof(ApplyConfiguration) && e.ContainsGenericParameters - && e.GetParameters().SingleOrDefault()?.ParameterType.GetGenericTypeDefinition() == typeof(IEntityTypeConfiguration<>)); + && e.GetParameters().SingleOrDefault()?.ParameterType.GetGenericTypeDefinition() + == typeof(IEntityTypeConfiguration<>)); var applyQueryConfigurationMethod = typeof(ModelBuilder).GetMethods().Single( e => e.Name == nameof(ApplyConfiguration) && e.ContainsGenericParameters @@ -487,7 +488,7 @@ public virtual ModelBuilder UsePropertyAccessMode(PropertyAccessMode propertyAcc /// /// Forces post-processing on the model such that it is ready for use by the runtime. This post - /// processing happens automatically when using ; this method allows it to be run + /// processing happens automatically when using ; this method allows it to be run /// explicitly in cases where the automatic execution is not possible. /// /// The finalized . diff --git a/src/EFCore/Query/CollectionShaperExpression.cs b/src/EFCore/Query/CollectionShaperExpression.cs index 93248a52650..74a115f423a 100644 --- a/src/EFCore/Query/CollectionShaperExpression.cs +++ b/src/EFCore/Query/CollectionShaperExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Query/CompiledQueryCacheKeyGenerator.cs b/src/EFCore/Query/CompiledQueryCacheKeyGenerator.cs index 62f27ede7e0..db59a0963c7 100644 --- a/src/EFCore/Query/CompiledQueryCacheKeyGenerator.cs +++ b/src/EFCore/Query/CompiledQueryCacheKeyGenerator.cs @@ -21,8 +21,8 @@ namespace Microsoft.EntityFrameworkCore.Query /// not used in application code. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/Query/CompiledQueryCacheKeyGeneratorDependencies.cs b/src/EFCore/Query/CompiledQueryCacheKeyGeneratorDependencies.cs index 820076dfa60..5745be29c35 100644 --- a/src/EFCore/Query/CompiledQueryCacheKeyGeneratorDependencies.cs +++ b/src/EFCore/Query/CompiledQueryCacheKeyGeneratorDependencies.cs @@ -26,8 +26,8 @@ namespace Microsoft.EntityFrameworkCore.Query /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/Query/EntityMaterializerSource.cs b/src/EFCore/Query/EntityMaterializerSource.cs index 76b5b77c263..ad64cfc5a0f 100644 --- a/src/EFCore/Query/EntityMaterializerSource.cs +++ b/src/EFCore/Query/EntityMaterializerSource.cs @@ -143,10 +143,7 @@ var readValueExpression blockExpressions.Add(instanceVariable); return Expression.Block( - new[] - { - instanceVariable - }, blockExpressions); + new[] { instanceVariable }, blockExpressions); } private ConcurrentDictionary> Materializers diff --git a/src/EFCore/Query/EntityShaperExpression.cs b/src/EFCore/Query/EntityShaperExpression.cs index 2ad6c1cd657..4dbace000d7 100644 --- a/src/EFCore/Query/EntityShaperExpression.cs +++ b/src/EFCore/Query/EntityShaperExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Query/EvaluatableExpressionFilter.cs b/src/EFCore/Query/EvaluatableExpressionFilter.cs index b8cc4cd1c50..194cb1452c6 100644 --- a/src/EFCore/Query/EvaluatableExpressionFilter.cs +++ b/src/EFCore/Query/EvaluatableExpressionFilter.cs @@ -16,9 +16,9 @@ namespace Microsoft.EntityFrameworkCore.Query /// Represents a filter for evaluatable expressions. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class EvaluatableExpressionFilter : IEvaluatableExpressionFilter @@ -60,7 +60,7 @@ private static readonly MethodInfo _randomNextTwoArgs /// /// - /// Creates a new instance. + /// Creates a new instance. /// /// /// This type is typically used by database providers (and other extensions). It is generally diff --git a/src/EFCore/Query/EvaluatableExpressionFilterDependencies.cs b/src/EFCore/Query/EvaluatableExpressionFilterDependencies.cs index 8e55867a332..04b7276d95e 100644 --- a/src/EFCore/Query/EvaluatableExpressionFilterDependencies.cs +++ b/src/EFCore/Query/EvaluatableExpressionFilterDependencies.cs @@ -23,9 +23,9 @@ namespace Microsoft.EntityFrameworkCore.Query /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public sealed class EvaluatableExpressionFilterDependencies diff --git a/src/EFCore/Query/ExpressionPrinter.cs b/src/EFCore/Query/ExpressionPrinter.cs index ac0f30717e3..a091fa4db0a 100644 --- a/src/EFCore/Query/ExpressionPrinter.cs +++ b/src/EFCore/Query/ExpressionPrinter.cs @@ -335,8 +335,8 @@ protected override Expression VisitBlock(BlockExpression blockExpression) Visit(blockExpression.Result); AppendLine(";"); } - } + Append("}"); return blockExpression; @@ -411,9 +411,9 @@ protected override Expression VisitGoto(GotoExpression gotoExpression) AppendLine("return (" + gotoExpression.Target.Type.ShortDisplayName() + ")" + gotoExpression.Target + " {"); using (_stringBuilder.Indent()) { - Visit(gotoExpression.Value); } + _stringBuilder.Append("}"); return gotoExpression; @@ -508,17 +508,13 @@ protected override Expression VisitMemberInit(MemberInitExpression memberInitExp } } } + AppendLine("}"); return memberInitExpression; } - private static readonly List _simpleMethods = new List - { - "get_Item", - "TryReadValue", - "ReferenceEquals" - }; + private static readonly List _simpleMethods = new List { "get_Item", "TryReadValue", "ReferenceEquals" }; protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression) { @@ -549,12 +545,14 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp { _stringBuilder.Append(", "); } + _stringBuilder.Append(genericArgument.ShortDisplayName()); first = false; } _stringBuilder.Append(">"); } + _stringBuilder.Append("("); var isSimpleMethodOrProperty = _simpleMethods.Contains(methodCallExpression.Method.Name) @@ -841,7 +839,8 @@ protected override Expression VisitExtension(Expression extensionExpression) return extensionExpression; } - private void VisitArguments(IReadOnlyList arguments, Action appendAction, string lastSeparator = "", bool areConnected = false) + private void VisitArguments( + IReadOnlyList arguments, Action appendAction, string lastSeparator = "", bool areConnected = false) { for (var i = 0; i < arguments.Count; i++) { diff --git a/src/EFCore/Query/GroupByShaperExpression.cs b/src/EFCore/Query/GroupByShaperExpression.cs index 14629ebf5dd..b345dc3311b 100644 --- a/src/EFCore/Query/GroupByShaperExpression.cs +++ b/src/EFCore/Query/GroupByShaperExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Query/ICompiledQueryCacheKeyGenerator.cs b/src/EFCore/Query/ICompiledQueryCacheKeyGenerator.cs index e1dc9ed3d6d..bc4bd2259f8 100644 --- a/src/EFCore/Query/ICompiledQueryCacheKeyGenerator.cs +++ b/src/EFCore/Query/ICompiledQueryCacheKeyGenerator.cs @@ -12,8 +12,8 @@ namespace Microsoft.EntityFrameworkCore.Query /// A cache key generator for the compiled query cache. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/Query/IEvaluatableExpressionFilter.cs b/src/EFCore/Query/IEvaluatableExpressionFilter.cs index 93967804fba..8b8f62f9252 100644 --- a/src/EFCore/Query/IEvaluatableExpressionFilter.cs +++ b/src/EFCore/Query/IEvaluatableExpressionFilter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq.Expressions; @@ -12,9 +12,9 @@ namespace Microsoft.EntityFrameworkCore.Query /// Represents a filter for evaluatable expressions. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IEvaluatableExpressionFilter diff --git a/src/EFCore/Query/IPrintableExpression.cs b/src/EFCore/Query/IPrintableExpression.cs index 8f37ff63c90..c3c3df153c2 100644 --- a/src/EFCore/Query/IPrintableExpression.cs +++ b/src/EFCore/Query/IPrintableExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore/Query/IQueryCompilationContextFactory.cs b/src/EFCore/Query/IQueryCompilationContextFactory.cs index 202e58b3a22..77b9f004a36 100644 --- a/src/EFCore/Query/IQueryCompilationContextFactory.cs +++ b/src/EFCore/Query/IQueryCompilationContextFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.Extensions.DependencyInjection; @@ -7,7 +7,7 @@ namespace Microsoft.EntityFrameworkCore.Query { /// /// - /// A factory for creating instances. + /// A factory for creating instances. /// /// /// The service lifetime is . This means that each diff --git a/src/EFCore/Query/IQueryContextFactory.cs b/src/EFCore/Query/IQueryContextFactory.cs index b93019e8f39..f74b9265832 100644 --- a/src/EFCore/Query/IQueryContextFactory.cs +++ b/src/EFCore/Query/IQueryContextFactory.cs @@ -10,8 +10,8 @@ namespace Microsoft.EntityFrameworkCore.Query /// Factory for instances. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/Query/IQueryTranslationPostprocessorFactory.cs b/src/EFCore/Query/IQueryTranslationPostprocessorFactory.cs index 7df3a774a66..57720185037 100644 --- a/src/EFCore/Query/IQueryTranslationPostprocessorFactory.cs +++ b/src/EFCore/Query/IQueryTranslationPostprocessorFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.Extensions.DependencyInjection; @@ -7,12 +7,12 @@ namespace Microsoft.EntityFrameworkCore.Query { /// /// - /// A factory for creating instances. + /// A factory for creating instances. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IQueryTranslationPostprocessorFactory diff --git a/src/EFCore/Query/IQueryTranslationPreprocessorFactory.cs b/src/EFCore/Query/IQueryTranslationPreprocessorFactory.cs index 0e3801d0041..c6601c07622 100644 --- a/src/EFCore/Query/IQueryTranslationPreprocessorFactory.cs +++ b/src/EFCore/Query/IQueryTranslationPreprocessorFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.Extensions.DependencyInjection; @@ -7,12 +7,12 @@ namespace Microsoft.EntityFrameworkCore.Query { /// /// - /// A factory for creating instances. + /// A factory for creating instances. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IQueryTranslationPreprocessorFactory diff --git a/src/EFCore/Query/IQueryableMethodTranslatingExpressionVisitorFactory.cs b/src/EFCore/Query/IQueryableMethodTranslatingExpressionVisitorFactory.cs index 3c72c4a54e5..f6e3935df57 100644 --- a/src/EFCore/Query/IQueryableMethodTranslatingExpressionVisitorFactory.cs +++ b/src/EFCore/Query/IQueryableMethodTranslatingExpressionVisitorFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.EntityFrameworkCore.Metadata; @@ -8,12 +8,12 @@ namespace Microsoft.EntityFrameworkCore.Query { /// /// - /// A factory for creating instances. + /// A factory for creating instances. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IQueryableMethodTranslatingExpressionVisitorFactory diff --git a/src/EFCore/Query/IShapedQueryCompilingExpressionVisitorFactory.cs b/src/EFCore/Query/IShapedQueryCompilingExpressionVisitorFactory.cs index 86d3925093e..9f873e7b3a0 100644 --- a/src/EFCore/Query/IShapedQueryCompilingExpressionVisitorFactory.cs +++ b/src/EFCore/Query/IShapedQueryCompilingExpressionVisitorFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.Extensions.DependencyInjection; @@ -7,12 +7,12 @@ namespace Microsoft.EntityFrameworkCore.Query { /// /// - /// A factory for creating instances. + /// A factory for creating instances. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IShapedQueryCompilingExpressionVisitorFactory diff --git a/src/EFCore/Query/IncludeExpression.cs b/src/EFCore/Query/IncludeExpression.cs index 93ce199af82..3c7feefd68c 100644 --- a/src/EFCore/Query/IncludeExpression.cs +++ b/src/EFCore/Query/IncludeExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -34,16 +34,16 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) public virtual IncludeExpression Update(Expression entityExpression, Expression navigationExpression) => entityExpression != EntityExpression || navigationExpression != NavigationExpression - ? new IncludeExpression(entityExpression, navigationExpression, Navigation) - : this; + ? new IncludeExpression(entityExpression, navigationExpression, Navigation) + : this; public virtual void Print(ExpressionPrinter expressionPrinter) { - expressionPrinter.AppendLine($"IncludeExpression("); + expressionPrinter.AppendLine("IncludeExpression("); using (expressionPrinter.Indent()) { expressionPrinter.Visit(EntityExpression); - expressionPrinter.AppendLine($", "); + expressionPrinter.AppendLine(", "); expressionPrinter.Visit(NavigationExpression); expressionPrinter.AppendLine($", {Navigation.Name})"); } diff --git a/src/EFCore/Query/Internal/AllAnyToContainsRewritingExpressionVisitor.cs b/src/EFCore/Query/Internal/AllAnyToContainsRewritingExpressionVisitor.cs index 501466510c5..164c580df99 100644 --- a/src/EFCore/Query/Internal/AllAnyToContainsRewritingExpressionVisitor.cs +++ b/src/EFCore/Query/Internal/AllAnyToContainsRewritingExpressionVisitor.cs @@ -12,14 +12,16 @@ public class AllAnyToContainsRewritingExpressionVisitor : ExpressionVisitor { private static bool IsExpressionOfFunc(Type type, int funcGenericArgs = 2) => type.IsGenericType - && type.GetGenericArguments().Length == funcGenericArgs; + && type.GetGenericArguments().Length == funcGenericArgs; private static readonly MethodInfo _allMethodInfo = typeof(Enumerable).GetTypeInfo() .GetDeclaredMethods(nameof(Enumerable.All)) .Single(mi => mi.GetParameters().Length == 2 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); + private static readonly MethodInfo _anyWithPredicateMethodInfo = typeof(Enumerable).GetTypeInfo() .GetDeclaredMethods(nameof(Enumerable.Any)) .Single(mi => mi.GetParameters().Length == 2 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); + private static readonly MethodInfo _containsMethodInfo = typeof(Enumerable).GetTypeInfo() .GetDeclaredMethods(nameof(Enumerable.Contains)) .Single(mi => mi.GetParameters().Length == 2); @@ -37,7 +39,8 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp { var nonParameterExpression = left is ParameterExpression ? right : left; - if (methodInfo.Equals(_anyWithPredicateMethodInfo) && !negated) + if (methodInfo.Equals(_anyWithPredicateMethodInfo) + && !negated) { var containsMethod = _containsMethodInfo.MakeGenericMethod(methodCallExpression.Method.GetGenericArguments()[0]); return Expression.Call(null, containsMethod, methodCallExpression.Arguments[0], nonParameterExpression); @@ -76,13 +79,15 @@ private bool TryExtractEqualityOperands(Expression expression, out Expression le return true; case MethodCallExpression methodCallExpression - when methodCallExpression.Method.Name == nameof(object.Equals): + when methodCallExpression.Method.Name == nameof(object.Equals): negated = false; - if (methodCallExpression.Arguments.Count == 1 && methodCallExpression.Object.Type == methodCallExpression.Arguments[0].Type) + if (methodCallExpression.Arguments.Count == 1 + && methodCallExpression.Object.Type == methodCallExpression.Arguments[0].Type) { (left, right) = (methodCallExpression.Object, methodCallExpression.Arguments[0]); } - else if (methodCallExpression.Arguments.Count == 2 && methodCallExpression.Arguments[0].Type == methodCallExpression.Arguments[1].Type) + else if (methodCallExpression.Arguments.Count == 2 + && methodCallExpression.Arguments[0].Type == methodCallExpression.Arguments[1].Type) { (left, right) = (methodCallExpression.Arguments[0], methodCallExpression.Arguments[1]); } @@ -90,7 +95,7 @@ private bool TryExtractEqualityOperands(Expression expression, out Expression le return true; case UnaryExpression unaryExpression - when unaryExpression.NodeType == ExpressionType.Not: + when unaryExpression.NodeType == ExpressionType.Not: var result = TryExtractEqualityOperands(unaryExpression.Operand, out left, out right, out negated); negated = !negated; return result; diff --git a/src/EFCore/Query/Internal/AnonymousObject.cs b/src/EFCore/Query/Internal/AnonymousObject.cs index 2e279dddb76..59930a7502b 100644 --- a/src/EFCore/Query/Internal/AnonymousObject.cs +++ b/src/EFCore/Query/Internal/AnonymousObject.cs @@ -79,6 +79,7 @@ public override int GetHashCode() { hash.Add(value); } + return hash.ToHashCode(); } } diff --git a/src/EFCore/Query/Internal/AsyncQueryProviderExtensions.cs b/src/EFCore/Query/Internal/AsyncQueryProviderExtensions.cs index 324cbcd7a0c..0c36dbdb149 100644 --- a/src/EFCore/Query/Internal/AsyncQueryProviderExtensions.cs +++ b/src/EFCore/Query/Internal/AsyncQueryProviderExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Query/Internal/CompiledQueryCache.cs b/src/EFCore/Query/Internal/CompiledQueryCache.cs index a167c6688fc..e6c4cc9e727 100644 --- a/src/EFCore/Query/Internal/CompiledQueryCache.cs +++ b/src/EFCore/Query/Internal/CompiledQueryCache.cs @@ -17,9 +17,9 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class CompiledQueryCache : ICompiledQueryCache diff --git a/src/EFCore/Query/Internal/EntityEqualityRewritingExpressionVisitor.cs b/src/EFCore/Query/Internal/EntityEqualityRewritingExpressionVisitor.cs index bd2e15b116e..5f50489fa7b 100644 --- a/src/EFCore/Query/Internal/EntityEqualityRewritingExpressionVisitor.cs +++ b/src/EFCore/Query/Internal/EntityEqualityRewritingExpressionVisitor.cs @@ -92,7 +92,8 @@ protected override Expression VisitMemberInit(MemberInitExpression memberInitExp : new EntityReferenceExpression(visitedMemberInit, entityReferenceInfo); // Visits member bindings, unwrapping expressions and surfacing entity reference information via the dictionary - (IEnumerable, Dictionary) VisitMemberBindings(ReadOnlyCollection bindings) + (IEnumerable, Dictionary) VisitMemberBindings( + ReadOnlyCollection bindings) { var newBindings = new MemberBinding[bindings.Count]; Dictionary bindingEntityReferenceInfo = null; @@ -109,8 +110,10 @@ protected override Expression VisitMemberInit(MemberInitExpression memberInitExp { bindingEntityReferenceInfo = new Dictionary(); } + bindingEntityReferenceInfo[assignment.Member.Name] = EntityOrDtoType.FromEntityReferenceExpression(ere); } + newBindings[i] = assignment.Update(Unwrap(visitedAssignment.Expression)); continue; @@ -136,7 +139,8 @@ protected override Expression VisitMember(MemberExpression memberExpression) protected override Expression VisitBinary(BinaryExpression binaryExpression) { var (newLeft, newRight) = (Visit(binaryExpression.Left), Visit(binaryExpression.Right)); - if (binaryExpression.NodeType == ExpressionType.Equal || binaryExpression.NodeType == ExpressionType.NotEqual) + if (binaryExpression.NodeType == ExpressionType.Equal + || binaryExpression.NodeType == ExpressionType.NotEqual) { if (RewriteEquality(binaryExpression.NodeType == ExpressionType.Equal, newLeft, newRight) is Expression result) { @@ -231,52 +235,52 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp newSource = Visit(arguments[0]); var newMethodCall = methodCallExpression.Update(null, new[] { Unwrap(newSource), arguments[1] }); return newSource is EntityReferenceExpression entityWrapper - ? entityWrapper.TraverseProperty(propertyName, newMethodCall) - : newMethodCall; + ? entityWrapper.TraverseProperty(propertyName, newMethodCall) + : newMethodCall; } switch (method.Name) { // These are methods that require special handling case nameof(Queryable.Contains) - when genericMethod == QueryableMethods.Contains: + when genericMethod == QueryableMethods.Contains: return VisitContainsMethodCall(methodCallExpression); case nameof(Queryable.OrderBy) - when genericMethod == QueryableMethods.OrderBy: + when genericMethod == QueryableMethods.OrderBy: case nameof(Queryable.OrderByDescending) - when genericMethod == QueryableMethods.OrderByDescending: + when genericMethod == QueryableMethods.OrderByDescending: case nameof(Queryable.ThenBy) - when genericMethod == QueryableMethods.ThenBy: + when genericMethod == QueryableMethods.ThenBy: case nameof(Queryable.ThenByDescending) when genericMethod == QueryableMethods.ThenByDescending: return VisitOrderingMethodCall(methodCallExpression); // The following are projecting methods, which flow the entity type from *within* the lambda outside. case nameof(Queryable.Select) - when genericMethod == QueryableMethods.Select: + when genericMethod == QueryableMethods.Select: case nameof(Queryable.SelectMany) - when genericMethod == QueryableMethods.SelectManyWithoutCollectionSelector - || genericMethod == QueryableMethods.SelectManyWithCollectionSelector: + when genericMethod == QueryableMethods.SelectManyWithoutCollectionSelector + || genericMethod == QueryableMethods.SelectManyWithCollectionSelector: return VisitSelectMethodCall(methodCallExpression); case nameof(Queryable.GroupJoin) - when genericMethod == QueryableMethods.GroupJoin: + when genericMethod == QueryableMethods.GroupJoin: case nameof(Queryable.Join) - when genericMethod == QueryableMethods.Join: + when genericMethod == QueryableMethods.Join: case nameof(QueryableExtensions.LeftJoin) - when genericMethod == QueryableExtensions.LeftJoinMethodInfo: + when genericMethod == QueryableExtensions.LeftJoinMethodInfo: return VisitJoinMethodCall(methodCallExpression); case nameof(Queryable.OfType) - when genericMethod == QueryableMethods.OfType: + when genericMethod == QueryableMethods.OfType: return VisitOfType(methodCallExpression); case nameof(Queryable.GroupBy) - when genericMethod == QueryableMethods.GroupByWithKeySelector - || genericMethod == QueryableMethods.GroupByWithKeyElementSelector - || genericMethod == QueryableMethods.GroupByWithKeyResultSelector - || genericMethod == QueryableMethods.GroupByWithKeyElementResultSelector: - break; // TODO: Implement + when genericMethod == QueryableMethods.GroupByWithKeySelector + || genericMethod == QueryableMethods.GroupByWithKeyElementSelector + || genericMethod == QueryableMethods.GroupByWithKeyResultSelector + || genericMethod == QueryableMethods.GroupByWithKeyElementResultSelector: + break; // TODO: Implement } // We handled the Contains Queryable extension method above, but there's also IList.Contains @@ -364,12 +368,14 @@ protected virtual Expression VisitContainsMethodCall(MethodCallExpression method var sourceEntityType = (newSource as EntityReferenceExpression)?.EntityType; var itemEntityType = (newItem as EntityReferenceExpression)?.EntityType; - if (sourceEntityType == null && itemEntityType == null) + if (sourceEntityType == null + && itemEntityType == null) { return NoTranslation(); } - if (sourceEntityType != null && itemEntityType != null + if (sourceEntityType != null + && itemEntityType != null && sourceEntityType.GetRootType() != itemEntityType.GetRootType()) { return Expression.Constant(false); @@ -383,7 +389,8 @@ protected virtual Expression VisitContainsMethodCall(MethodCallExpression method ? throw new InvalidOperationException(CoreStrings.EntityEqualityOnKeylessEntityNotSupported(entityType.DisplayName())) : keyProperties.Count == 1 ? keyProperties[0] - : throw new InvalidOperationException(CoreStrings.EntityEqualityContainsWithCompositeKeyNotSupported(entityType.DisplayName())); + : throw new InvalidOperationException( + CoreStrings.EntityEqualityContainsWithCompositeKeyNotSupported(entityType.DisplayName())); Expression rewrittenSource, rewrittenItem; @@ -398,6 +405,7 @@ protected virtual Expression VisitContainsMethodCall(MethodCallExpression method { keyList.Add(getter.GetClrValue(listItem)); } + rewrittenSource = Expression.Constant(keyList, keyListType); } else if (newSource is ParameterExpression listParam @@ -413,7 +421,8 @@ protected virtual Expression VisitContainsMethodCall(MethodCallExpression method QueryCompilationContext.QueryContextParameter ); - var newParameterName = $"{RuntimeParameterPrefix}{listParam.Name.Substring(CompiledQueryCache.CompiledQueryParameterPrefix.Length)}_{keyProperty.Name}"; + var newParameterName = + $"{RuntimeParameterPrefix}{listParam.Name.Substring(CompiledQueryCache.CompiledQueryParameterPrefix.Length)}_{keyProperty.Name}"; rewrittenSource = _queryCompilationContext.RegisterRuntimeParameter(newParameterName, lambda); } else @@ -513,6 +522,7 @@ static MethodInfo GetOrderingMethodInfo(bool firstOrdering, bool ascending) ? QueryableMethods.OrderBy : QueryableMethods.OrderByDescending; } + return ascending ? QueryableMethods.ThenBy : QueryableMethods.ThenByDescending; @@ -556,7 +566,8 @@ protected virtual Expression VisitSelectMethodCall(MethodCallExpression methodCa ? RewriteAndVisitLambda(resultSelector, sourceWrapper, newCollectionSelectorWrapper) : (LambdaExpression)Visit(resultSelector); - newMethodCall = methodCallExpression.Update(null, new[] { Unwrap(newSource), Unwrap(newCollectionSelector), Unwrap(newResultSelector) }); + newMethodCall = methodCallExpression.Update( + null, new[] { Unwrap(newSource), Unwrap(newCollectionSelector), Unwrap(newResultSelector) }); return newResultSelector.Body is EntityReferenceExpression entityWrapper ? entityWrapper.Update(newMethodCall) : (Expression)newMethodCall; @@ -582,10 +593,16 @@ protected virtual Expression VisitJoinMethodCall(MethodCallExpression methodCall if (!(newOuter is EntityReferenceExpression outerWrapper && newInner is EntityReferenceExpression innerWrapper)) { - return methodCallExpression.Update(null, new[] - { - Unwrap(newOuter), Unwrap(newInner), Unwrap(Visit(outerKeySelector)), Unwrap(Visit(innerKeySelector)), Unwrap(Visit(resultSelector)) - }); + return methodCallExpression.Update( + null, + new[] + { + Unwrap(newOuter), + Unwrap(newInner), + Unwrap(Visit(outerKeySelector)), + Unwrap(Visit(innerKeySelector)), + Unwrap(Visit(resultSelector)) + }); } var newOuterKeySelector = RewriteAndVisitLambda(outerKeySelector, outerWrapper); @@ -598,7 +615,8 @@ protected virtual Expression VisitJoinMethodCall(MethodCallExpression methodCall // we need to rewrite. if (newOuterKeySelector.Body is EntityReferenceExpression outerKeySelectorWrapper && newInnerKeySelector.Body is EntityReferenceExpression innerKeySelectorWrapper - && outerKeySelectorWrapper.IsEntityType && innerKeySelectorWrapper.IsEntityType + && outerKeySelectorWrapper.IsEntityType + && innerKeySelectorWrapper.IsEntityType && outerKeySelectorWrapper.EntityType.GetRootType() == innerKeySelectorWrapper.EntityType.GetRootType()) { var entityType = outerKeySelectorWrapper.EntityType; @@ -607,12 +625,14 @@ protected virtual Expression VisitJoinMethodCall(MethodCallExpression methodCall { throw new InvalidOperationException(CoreStrings.EntityEqualityOnKeylessEntityNotSupported(entityType.DisplayName())); } + if (keyProperties.Count > 1 && (outerKeySelectorWrapper.SubqueryTraversed || innerKeySelectorWrapper.SubqueryTraversed)) { // One side of the comparison is the result of a subquery, and we have a composite key. // Rewriting this would mean evaluating the subquery more than once, so we don't do it. - throw new InvalidOperationException(CoreStrings.EntityEqualitySubqueryWithCompositeKeyNotSupported(entityType.DisplayName())); + throw new InvalidOperationException( + CoreStrings.EntityEqualitySubqueryWithCompositeKeyNotSupported(entityType.DisplayName())); } // Rewrite the lambda bodies, adding the key access on top of whatever is there, and then @@ -646,12 +666,16 @@ protected virtual Expression VisitJoinMethodCall(MethodCallExpression methodCall } else { - newMethodCall = methodCallExpression.Update(null, new[] - { - Unwrap(newOuter), Unwrap(newInner), - Expression.Quote(Unwrap(newOuterKeySelector)), Expression.Quote(Unwrap(newInnerKeySelector)), - Expression.Quote(Unwrap(newResultSelector)) - }); + newMethodCall = methodCallExpression.Update( + null, + new[] + { + Unwrap(newOuter), + Unwrap(newInner), + Expression.Quote(Unwrap(newOuterKeySelector)), + Expression.Quote(Unwrap(newInnerKeySelector)), + Expression.Quote(Unwrap(newResultSelector)) + }); } return newResultSelector.Body is EntityReferenceExpression wrapper @@ -687,10 +711,11 @@ protected virtual Expression VisitOfType(MethodCallExpression methodCallExpressi protected virtual LambdaExpression RewriteAndVisitLambda(LambdaExpression lambda, EntityReferenceExpression source) => Expression.Lambda( lambda.Type, - Visit(ReplacingExpressionVisitor.Replace( - lambda.Parameters.Single(), - source.Update(lambda.Parameters.Single()), - lambda.Body)), + Visit( + ReplacingExpressionVisitor.Replace( + lambda.Parameters.Single(), + source.Update(lambda.Parameters.Single()), + lambda.Body)), lambda.TailCall, lambda.Parameters); @@ -698,7 +723,8 @@ protected virtual LambdaExpression RewriteAndVisitLambda(LambdaExpression lambda /// Replaces the lambda's two parameters with type wrappers based on the given sources, and then visits /// the lambda's body. /// - protected virtual LambdaExpression RewriteAndVisitLambda(LambdaExpression lambda, + protected virtual LambdaExpression RewriteAndVisitLambda( + LambdaExpression lambda, EntityReferenceExpression source1, EntityReferenceExpression source2) { @@ -710,10 +736,8 @@ protected virtual LambdaExpression RewriteAndVisitLambda(LambdaExpression lambda lambda.Type, Visit( new ReplacingExpressionVisitor( - new Dictionary { - { original1, replacement1 }, - { original2, replacement2 } - }).Visit(lambda.Body)), + new Dictionary { { original1, replacement1 }, { original2, replacement2 } }) + .Visit(lambda.Body)), lambda.TailCall, lambda.Parameters); } @@ -748,7 +772,8 @@ protected virtual Expression RewriteEquality(bool equality, Expression left, Exp } return rightTypeWrapper?.IsEntityType == true - ? RewriteNullEquality(equality, rightTypeWrapper.EntityType, rightTypeWrapper.Underlying, rightTypeWrapper.LastNavigation) + ? RewriteNullEquality( + equality, rightTypeWrapper.EntityType, rightTypeWrapper.Underlying, rightTypeWrapper.LastNavigation) : null; } @@ -814,7 +839,8 @@ private Expression RewriteEntityEquality( [NotNull] Expression right, [CanBeNull] INavigation rightNavigation, bool subqueryTraversed) { - if (leftNavigation?.IsCollection() == true || rightNavigation?.IsCollection() == true) + if (leftNavigation?.IsCollection() == true + || rightNavigation?.IsCollection() == true) { if (leftNavigation?.Equals(rightNavigation) == true) { @@ -835,11 +861,13 @@ private Expression RewriteEntityEquality( { throw new InvalidOperationException(CoreStrings.EntityEqualityOnKeylessEntityNotSupported(entityType.DisplayName())); } + if (subqueryTraversed && keyProperties.Count > 1) { // One side of the comparison is the result of a subquery, and we have a composite key. // Rewriting this would mean evaluating the subquery more than once, so we don't do it. - throw new InvalidOperationException(CoreStrings.EntityEqualitySubqueryWithCompositeKeyNotSupported(entityType.DisplayName())); + throw new InvalidOperationException( + CoreStrings.EntityEqualitySubqueryWithCompositeKeyNotSupported(entityType.DisplayName())); } return Expression.MakeBinary( @@ -922,11 +950,12 @@ private Expression CreatePropertyAccessExpression(Expression target, IProperty p Expression.Constant(property, typeof(IProperty))), QueryCompilationContext.QueryContextParameter); - var newParameterName = $"{RuntimeParameterPrefix}{baseParameterExpression.Name.Substring(CompiledQueryCache.CompiledQueryParameterPrefix.Length)}_{property.Name}"; + var newParameterName = + $"{RuntimeParameterPrefix}{baseParameterExpression.Name.Substring(CompiledQueryCache.CompiledQueryParameterPrefix.Length)}_{property.Name}"; return _queryCompilationContext.RegisterRuntimeParameter(newParameterName, lambda); } - return target.CreateEFPropertyExpression(property, true); + return target.CreateEFPropertyExpression(property); } private static bool CanEvaluate(Expression expression) @@ -941,8 +970,8 @@ private static bool CanEvaluate(Expression expression) case MemberInitExpression memberInitExpression: return CanEvaluate(memberInitExpression.NewExpression) - && memberInitExpression.Bindings.All( - mb => mb is MemberAssignment memberAssignment && CanEvaluate(memberAssignment.Expression)); + && memberInitExpression.Bindings.All( + mb => mb is MemberAssignment memberAssignment && CanEvaluate(memberAssignment.Expression)); default: return false; @@ -956,15 +985,16 @@ private static T ParameterValueExtractor(QueryContext context, string basePar } private static readonly MethodInfo _parameterValueExtractor - = typeof(EntityEqualityRewritingExpressionVisitor) - .GetTypeInfo() - .GetDeclaredMethod(nameof(ParameterValueExtractor)); + = typeof(EntityEqualityRewritingExpressionVisitor) + .GetTypeInfo() + .GetDeclaredMethod(nameof(ParameterValueExtractor)); /// - /// Extracts the list parameter with name from and returns a - /// projection to its elements' values. + /// Extracts the list parameter with name from and returns a + /// projection to its elements' values. /// - private static List ParameterListValueExtractor(QueryContext context, string baseParameterName, IProperty property) + private static List ParameterListValueExtractor( + QueryContext context, string baseParameterName, IProperty property) { var baseListParameter = context.ParameterValues[baseParameterName] as IEnumerable; if (baseListParameter == null) @@ -993,11 +1023,11 @@ protected static Expression Unwrap(Expression expression) { EntityReferenceExpression wrapper => wrapper.Underlying, LambdaExpression lambda when lambda.Body is EntityReferenceExpression wrapper => - Expression.Lambda( - lambda.Type, - wrapper.Underlying, - lambda.TailCall, - lambda.Parameters), + Expression.Lambda( + lambda.Type, + wrapper.Underlying, + lambda.TailCall, + lambda.Parameters), _ => expression }; @@ -1006,8 +1036,7 @@ protected struct EntityOrDtoType public static EntityOrDtoType FromEntityReferenceExpression(EntityReferenceExpression ere) => new EntityOrDtoType { - EntityType = ere.IsEntityType ? ere.EntityType : null, - DtoType = ere.IsDtoType ? ere.DtoType : null + EntityType = ere.IsEntityType ? ere.EntityType : null, DtoType = ere.IsDtoType ? ere.DtoType : null }; public static EntityOrDtoType FromDtoType(Dictionary dtoType) @@ -1060,7 +1089,8 @@ public EntityReferenceExpression(Expression underlying, IEntityType entityType) { } - private EntityReferenceExpression(Expression underlying, IEntityType entityType, INavigation lastNavigation, bool subqueryTraversed) + private EntityReferenceExpression( + Expression underlying, IEntityType entityType, INavigation lastNavigation, bool subqueryTraversed) { Underlying = underlying; EntityType = entityType; @@ -1083,8 +1113,8 @@ public EntityReferenceExpression( } /// - /// Attempts to find as a navigation from the current node, - /// and if successful, returns a new wrapping the + /// Attempts to find as a navigation from the current node, + /// and if successful, returns a new wrapping the /// given expression. Otherwise returns the given expression without wrapping it. /// public virtual Expression TraverseProperty(string propertyName, Expression destinationExpression) @@ -1140,7 +1170,8 @@ public virtual void Print(ExpressionPrinter expressionPrinter) } } - public override string ToString() => $"{Underlying}[{(IsEntityType ? EntityType.ShortName() : "DTO")}{(SubqueryTraversed ? ", Subquery" : "")}]"; + public override string ToString() => + $"{Underlying}[{(IsEntityType ? EntityType.ShortName() : "DTO")}{(SubqueryTraversed ? ", Subquery" : "")}]"; } } } diff --git a/src/EFCore/Query/Internal/EntityQueryProvider.cs b/src/EFCore/Query/Internal/EntityQueryProvider.cs index 8614c7d9a9a..8169f96721d 100644 --- a/src/EFCore/Query/Internal/EntityQueryProvider.cs +++ b/src/EFCore/Query/Internal/EntityQueryProvider.cs @@ -19,8 +19,8 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/Query/Internal/EnumerableToQueryableMethodConvertingExpressionVisitor.cs b/src/EFCore/Query/Internal/EnumerableToQueryableMethodConvertingExpressionVisitor.cs index bada82ae75a..da043e7cfd6 100644 --- a/src/EFCore/Query/Internal/EnumerableToQueryableMethodConvertingExpressionVisitor.cs +++ b/src/EFCore/Query/Internal/EnumerableToQueryableMethodConvertingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -132,7 +132,8 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp return methodCallExpression.Update(Visit(methodCallExpression.Object), arguments); } - else if (methodCallExpression.Method.DeclaringType.IsGenericType + + if (methodCallExpression.Method.DeclaringType.IsGenericType && methodCallExpression.Method.DeclaringType.GetGenericTypeDefinition() == typeof(List<>) && string.Equals(nameof(List.Contains), methodCallExpression.Method.Name)) { @@ -157,9 +158,9 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp private static bool ClientSource(Expression expression) => expression is ConstantExpression - || expression is MemberInitExpression - || expression is NewExpression - || expression is ParameterExpression; + || expression is MemberInitExpression + || expression is NewExpression + || expression is ParameterExpression; private static bool CanConvertEnumerableToQueryable(Type enumerableType, Type queryableType) { diff --git a/src/EFCore/Query/Internal/FunctionPreprocessingExpressionVisitor.cs b/src/EFCore/Query/Internal/FunctionPreprocessingExpressionVisitor.cs index 0a5c494db1b..dabf281fcb7 100644 --- a/src/EFCore/Query/Internal/FunctionPreprocessingExpressionVisitor.cs +++ b/src/EFCore/Query/Internal/FunctionPreprocessingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq.Expressions; @@ -54,7 +54,7 @@ protected override Expression VisitUnary(UnaryExpression unaryExpression) if (unaryExpression.NodeType == ExpressionType.Not && unaryExpression.Operand is MethodCallExpression innerMethodCall && (_startsWithMethodInfo.Equals(innerMethodCall.Method) - || _endsWithMethodInfo.Equals(innerMethodCall.Method))) + || _endsWithMethodInfo.Equals(innerMethodCall.Method))) { if (innerMethodCall.Arguments[0] is ConstantExpression constantArgument && (string)constantArgument.Value == string.Empty) diff --git a/src/EFCore/Query/Internal/GroupJoinFlatteningExpressionVisitor.cs b/src/EFCore/Query/Internal/GroupJoinFlatteningExpressionVisitor.cs index 23fd05a7efd..fd41ffb003b 100644 --- a/src/EFCore/Query/Internal/GroupJoinFlatteningExpressionVisitor.cs +++ b/src/EFCore/Query/Internal/GroupJoinFlatteningExpressionVisitor.cs @@ -1,12 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; -using Microsoft.EntityFrameworkCore.Diagnostics; -using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Internal; namespace Microsoft.EntityFrameworkCore.Query.Internal @@ -15,6 +13,7 @@ public class GroupJoinFlatteningExpressionVisitor : ExpressionVisitor { private static readonly EnumerableToQueryableMethodConvertingExpressionVisitor _enumerableToQueryableReMappingExpressionVisitor = new EnumerableToQueryableMethodConvertingExpressionVisitor(); + private readonly SelectManyVerifyingExpressionVisitor _selectManyVerifyingExpressionVisitor = new SelectManyVerifyingExpressionVisitor(); @@ -76,9 +75,9 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp Expression.Quote(Expression.Lambda(correlationPredicate, innerParameter))); inner = ReplacingExpressionVisitor.Replace( - groupJoinResultSelector.Parameters[1], - inner, - collectionSelectorBody); + groupJoinResultSelector.Parameters[1], + inner, + collectionSelectorBody); inner = Expression.Quote(Expression.Lambda(inner, outerParameter)); } @@ -133,21 +132,19 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp innerKeySelector, resultSelector); } - else - { - // inner join - return Expression.Call( - QueryableMethods.Join.MakeGenericMethod( - outer.Type.TryGetSequenceType(), - inner.Type.TryGetSequenceType(), - outerKeySelector.ReturnType, - resultSelector.ReturnType), - outer, - inner, - outerKeySelector, - innerKeySelector, - resultSelector); - } + + // inner join + return Expression.Call( + QueryableMethods.Join.MakeGenericMethod( + outer.Type.TryGetSequenceType(), + inner.Type.TryGetSequenceType(), + outerKeySelector.ReturnType, + resultSelector.ReturnType), + outer, + inner, + outerKeySelector, + innerKeySelector, + resultSelector); } } } @@ -218,21 +215,19 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp innerKeySelector, resultSelector); } - else - { - // inner join - return Expression.Call( - QueryableMethods.Join.MakeGenericMethod( - outer.Type.TryGetSequenceType(), - inner.Type.TryGetSequenceType(), - outerKeySelector.ReturnType, - resultSelector.ReturnType), - outer, - inner, - outerKeySelector, - innerKeySelector, - resultSelector); - } + + // inner join + return Expression.Call( + QueryableMethods.Join.MakeGenericMethod( + outer.Type.TryGetSequenceType(), + inner.Type.TryGetSequenceType(), + outerKeySelector.ReturnType, + resultSelector.ReturnType), + outer, + inner, + outerKeySelector, + innerKeySelector, + resultSelector); } } } @@ -244,11 +239,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp private class SelectManyVerifyingExpressionVisitor : ExpressionVisitor { private readonly List _allowedParameters = new List(); - private readonly ISet _allowedMethods = new HashSet - { - nameof(Queryable.Where), - nameof(Queryable.AsQueryable) - }; + private readonly ISet _allowedMethods = new HashSet { nameof(Queryable.Where), nameof(Queryable.AsQueryable) }; private ParameterExpression _rootParameter; private int _rootParameterCount; @@ -272,7 +263,7 @@ public bool VerifyCollectionSelector(Expression body, ParameterExpression rootPa expression = memberExpression.Expression; } else if (expression is MethodCallExpression methodCallExpression - && methodCallExpression.Method.DeclaringType == typeof(Queryable)) + && methodCallExpression.Method.DeclaringType == typeof(Queryable)) { expression = methodCallExpression.Arguments[0]; } diff --git a/src/EFCore/Query/Internal/IAsyncQueryProvider.cs b/src/EFCore/Query/Internal/IAsyncQueryProvider.cs index c8a68a7f258..044382a71b7 100644 --- a/src/EFCore/Query/Internal/IAsyncQueryProvider.cs +++ b/src/EFCore/Query/Internal/IAsyncQueryProvider.cs @@ -17,8 +17,8 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/Query/Internal/ICompiledQueryCache.cs b/src/EFCore/Query/Internal/ICompiledQueryCache.cs index 53a53d3f58f..73bf2559d4c 100644 --- a/src/EFCore/Query/Internal/ICompiledQueryCache.cs +++ b/src/EFCore/Query/Internal/ICompiledQueryCache.cs @@ -15,9 +15,9 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface ICompiledQueryCache diff --git a/src/EFCore/Query/Internal/IQueryCompiler.cs b/src/EFCore/Query/Internal/IQueryCompiler.cs index b0371a3e3cb..f3edcba39e4 100644 --- a/src/EFCore/Query/Internal/IQueryCompiler.cs +++ b/src/EFCore/Query/Internal/IQueryCompiler.cs @@ -17,8 +17,8 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs index e58dec253d8..94de607cfdf 100644 --- a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs +++ b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -70,7 +70,7 @@ protected override Expression VisitMember(MemberExpression memberExpression) { var innerExpression = Visit(memberExpression.Expression); return TryExpandNavigation(innerExpression, MemberIdentity.Create(memberExpression.Member)) - ?? memberExpression.Update(innerExpression); + ?? memberExpression.Update(innerExpression); } protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression) @@ -79,7 +79,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp { source = Visit(source); return TryExpandNavigation(source, MemberIdentity.Create(navigationName)) - ?? methodCallExpression.Update(null, new[] { source, methodCallExpression.Arguments[1] }); + ?? methodCallExpression.Update(null, new[] { source, methodCallExpression.Arguments[1] }); } return base.VisitMethodCall(methodCallExpression); @@ -153,11 +153,9 @@ protected Expression ExpandNavigation( return new MaterializeCollectionNavigationExpression(subquery, navigation); } - else - { - entityReference.NavigationMap[navigation] = ownedExpansion; - return ownedExpansion; - } + + entityReference.NavigationMap[navigation] = ownedExpansion; + return ownedExpansion; } var innerQueryableType = targetType.ClrType; @@ -178,7 +176,8 @@ protected Expression ExpandNavigation( { // This is FirstOrDefault ending so we need to push down properties. var temporaryParameter = Expression.Parameter(root.Type); - var temporaryKey = CreateKeyAccessExpression(temporaryParameter, + var temporaryKey = CreateKeyAccessExpression( + temporaryParameter, navigation.IsDependentToPrincipal() ? navigation.ForeignKey.Properties : navigation.ForeignKey.PrincipalKey.Properties); @@ -191,13 +190,15 @@ protected Expression ExpandNavigation( } else { - outerKey = CreateKeyAccessExpression(root, + outerKey = CreateKeyAccessExpression( + root, navigation.IsDependentToPrincipal() ? navigation.ForeignKey.Properties : navigation.ForeignKey.PrincipalKey.Properties); } - var innerKey = CreateKeyAccessExpression(innerParameter, + var innerKey = CreateKeyAccessExpression( + innerParameter, navigation.IsDependentToPrincipal() ? navigation.ForeignKey.PrincipalKey.Properties : navigation.ForeignKey.Properties); @@ -228,60 +229,59 @@ protected Expression ExpandNavigation( return new MaterializeCollectionNavigationExpression(subquery, navigation); } - else + + var outerKeySelector = _navigationExpandingExpressionVisitor.GenerateLambda( + outerKey, _source.CurrentParameter); + var innerKeySelector = _navigationExpandingExpressionVisitor.GenerateLambda( + _navigationExpandingExpressionVisitor.ExpandNavigationsInLambdaExpression( + innerSource, + Expression.Lambda(innerKey, innerParameter)), + innerSource.CurrentParameter); + + var resultSelectorOuterParameter = Expression.Parameter(_source.SourceElementType, "o"); + var resultSelectorInnerParameter = Expression.Parameter(innerSource.SourceElementType, "i"); + var resultType = TransparentIdentifierFactory.Create(_source.SourceElementType, innerSource.SourceElementType); + + var transparentIdentifierOuterMemberInfo = resultType.GetTypeInfo().GetDeclaredField("Outer"); + var transparentIdentifierInnerMemberInfo = resultType.GetTypeInfo().GetDeclaredField("Inner"); + + var resultSelector = Expression.Lambda( + Expression.New( + resultType.GetTypeInfo().GetConstructors().Single(), + new[] { resultSelectorOuterParameter, resultSelectorInnerParameter }, transparentIdentifierOuterMemberInfo, + transparentIdentifierInnerMemberInfo), + resultSelectorOuterParameter, + resultSelectorInnerParameter); + + var innerJoin = !entityReference.IsOptional && !derivedTypeConversion + && navigation.IsDependentToPrincipal() && navigation.ForeignKey.IsRequired; + + if (!innerJoin) { - var outerKeySelector = _navigationExpandingExpressionVisitor.GenerateLambda( - outerKey, _source.CurrentParameter); - var innerKeySelector = _navigationExpandingExpressionVisitor.GenerateLambda( - _navigationExpandingExpressionVisitor.ExpandNavigationsInLambdaExpression( - innerSource, - Expression.Lambda(innerKey, innerParameter)), - innerSource.CurrentParameter); - - var resultSelectorOuterParameter = Expression.Parameter(_source.SourceElementType, "o"); - var resultSelectorInnerParameter = Expression.Parameter(innerSource.SourceElementType, "i"); - var resultType = TransparentIdentifierFactory.Create(_source.SourceElementType, innerSource.SourceElementType); - - var transparentIdentifierOuterMemberInfo = resultType.GetTypeInfo().GetDeclaredField("Outer"); - var transparentIdentifierInnerMemberInfo = resultType.GetTypeInfo().GetDeclaredField("Inner"); - - var resultSelector = Expression.Lambda( - Expression.New( - resultType.GetTypeInfo().GetConstructors().Single(), - new[] { resultSelectorOuterParameter, resultSelectorInnerParameter }, - new[] { transparentIdentifierOuterMemberInfo, transparentIdentifierInnerMemberInfo }), - resultSelectorOuterParameter, - resultSelectorInnerParameter); - - var innerJoin = !entityReference.IsOptional && !derivedTypeConversion - && navigation.IsDependentToPrincipal() && navigation.ForeignKey.IsRequired; - - if (!innerJoin) - { - var innerEntityReference = (EntityReference)((NavigationTreeExpression)innerSource.PendingSelector).Value; - innerEntityReference.MarkAsOptional(); - } + var innerEntityReference = (EntityReference)((NavigationTreeExpression)innerSource.PendingSelector).Value; + innerEntityReference.MarkAsOptional(); + } - _source.UpdateSource(Expression.Call( + _source.UpdateSource( + Expression.Call( (innerJoin ? QueryableMethods.Join : QueryableExtensions.LeftJoinMethodInfo).MakeGenericMethod( - _source.SourceElementType, - innerSource.SourceElementType, - outerKeySelector.ReturnType, - resultSelector.ReturnType), + _source.SourceElementType, + innerSource.SourceElementType, + outerKeySelector.ReturnType, + resultSelector.ReturnType), _source.Source, innerSource.Source, outerKeySelector, innerKeySelector, resultSelector)); - entityReference.NavigationMap[navigation] = innerSource.PendingSelector; + entityReference.NavigationMap[navigation] = innerSource.PendingSelector; - _source.UpdateCurrentTree(new NavigationTreeNode(_source.CurrentTree, innerSource.CurrentTree)); + _source.UpdateCurrentTree(new NavigationTreeNode(_source.CurrentTree, innerSource.CurrentTree)); - return innerSource.PendingSelector; - } + return innerSource.PendingSelector; } private static Expression CreateKeyAccessExpression(Expression target, IReadOnlyList properties) @@ -326,6 +326,7 @@ public override Expression Visit(Expression expression) return replacement; } } + break; case OwnedNavigationReference ownedNavigationReference: @@ -439,8 +440,8 @@ private void VerifyNoCycles(IncludeTreeNode includeTreeNode) { throw new InvalidOperationException( $"The Include path '{navigation.Name}->{inverseNavigation.Name}' results in a cycle. " + - $"Cycles are not allowed in no-tracking queries. " + - $"Either use a tracking query or remove the cycle."); + "Cycles are not allowed in no-tracking queries. " + + "Either use a tracking query or remove the cycle."); } VerifyNoCycles(referenceIncludeTreeNode); @@ -467,7 +468,7 @@ private Expression ExpandIncludesHelper(Expression root, EntityReference entityR if (!navigation.IsCollection()) { var innerEntityReference = navigation.GetTargetType().HasDefiningNavigation() - || navigation.GetTargetType().IsOwned() + || navigation.GetTargetType().IsOwned() ? ((OwnedNavigationReference)included).EntityReference : (EntityReference)((NavigationTreeExpression)included).Value; @@ -633,7 +634,9 @@ protected override Expression VisitConstant(ConstantExpression constantExpressio { if (constantExpression.IsEntityQueryable()) { - var entityType = _navigationExpandingExpressionVisitor._queryCompilationContext.Model.FindEntityType(((IQueryable)constantExpression.Value).ElementType); + var entityType = + _navigationExpandingExpressionVisitor._queryCompilationContext.Model.FindEntityType( + ((IQueryable)constantExpression.Value).ElementType); if (entityType == _entityType) { return _navigationExpandingExpressionVisitor.CreateNavigationExpansionExpression(constantExpression, entityType); diff --git a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.Expressions.cs b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.Expressions.cs index b93e752fb1a..c894ba347e6 100644 --- a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.Expressions.cs +++ b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.Expressions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -18,6 +18,7 @@ protected class NavigationExpansionExpression : Expression, IPrintableExpression { private readonly List<(MethodInfo OrderingMethod, Expression KeySelector)> _pendingOrderings = new List<(MethodInfo OrderingMethod, Expression KeySelector)>(); + private readonly string _parameterName; private NavigationTreeNode _currentTree; @@ -32,6 +33,7 @@ public NavigationExpansionExpression( public virtual Expression Source { get; private set; } public virtual ParameterExpression CurrentParameter => CurrentTree.CurrentParameter; + public virtual NavigationTreeNode CurrentTree { get => _currentTree; @@ -41,6 +43,7 @@ private set _currentTree.SetParameter(_parameterName); } } + public virtual Expression PendingSelector { get; private set; } public virtual MethodInfo CardinalityReducingGenericMethodInfo { get; private set; } public virtual Type SourceElementType => CurrentParameter.Type; @@ -66,6 +69,7 @@ public virtual void AddPendingOrdering(MethodInfo orderingMethod, Expression key _pendingOrderings.Clear(); _pendingOrderings.Add((orderingMethod, keySelector)); } + public virtual void AppendPendingOrdering(MethodInfo orderingMethod, Expression keySelector) { _pendingOrderings.Add((orderingMethod, keySelector)); @@ -102,6 +106,7 @@ public virtual void Print(ExpressionPrinter expressionPrinter) } public override ExpressionType NodeType => ExpressionType.Extension; + public override Type Type => CardinalityReducingGenericMethodInfo == null ? typeof(IQueryable<>).MakeGenericType(PendingSelector.Type) : PendingSelector.Type; @@ -114,13 +119,16 @@ public NavigationTreeExpression(Expression value) { Value = value; } + public virtual Expression Value { get; private set; } + protected override Expression VisitChildren(ExpressionVisitor visitor) { Value = visitor.Visit(Value); return this; } + public override Type Type => Value.Type; public virtual void Print(ExpressionPrinter expressionPrinter) @@ -146,6 +154,7 @@ public EntityReference(IEntityType entityType) } public virtual IEntityType EntityType { get; } + public virtual IDictionary NavigationMap { get; } = new Dictionary(); @@ -162,10 +171,7 @@ public virtual void SetIncludePaths(IncludeTreeNode includePaths) public virtual EntityReference Clone() { - var result = new EntityReference(EntityType) - { - IsOptional = IsOptional - }; + var result = new EntityReference(EntityType) { IsOptional = IsOptional }; result.IncludePaths = IncludePaths.Clone(result); return result; @@ -193,7 +199,9 @@ public virtual void Print(ExpressionPrinter expressionPrinter) if (IncludePaths.Count > 0) { // TODO: fully render nested structure of include tree - expressionPrinter.Append(" | IncludePaths: " + string.Join(" ", IncludePaths.Select(ip => ip.Value.Count() > 0 ? ip.Key.Name + "->..." : ip.Key.Name))); + expressionPrinter.Append( + " | IncludePaths: " + string.Join( + " ", IncludePaths.Select(ip => ip.Value.Count() > 0 ? ip.Key.Name + "->..." : ip.Key.Name))); } } @@ -227,6 +235,7 @@ private set CurrentParameter = null; } } + public virtual NavigationTreeNode Left { get; } public virtual NavigationTreeNode Right { get; } public virtual ParameterExpression CurrentParameter { get; private set; } @@ -241,6 +250,7 @@ public virtual void SetParameter(string parameterName) public override ExpressionType NodeType => ExpressionType.Extension; public override Type Type => TransparentIdentifierFactory.Create(Left.Type, Right.Type); + public virtual Expression GetExpression() { if (Parent == null) @@ -330,9 +340,9 @@ public virtual IncludeTreeNode Clone(EntityReference entityReference) public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is IncludeTreeNode includeTreeNode - && Equals(includeTreeNode)); + && (ReferenceEquals(this, obj) + || obj is IncludeTreeNode includeTreeNode + && Equals(includeTreeNode)); private bool Equals(IncludeTreeNode includeTreeNode) { diff --git a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs index 69830318d8e..6310b7be608 100644 --- a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs +++ b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -24,8 +24,10 @@ public partial class NavigationExpandingExpressionVisitor : ExpressionVisitor private readonly ISet _parameterNames = new HashSet(); private readonly EnumerableToQueryableMethodConvertingExpressionVisitor _enumerableToQueryableMethodConvertingExpressionVisitor; private readonly ParameterExtractingExpressionVisitor _parameterExtractingExpressionVisitor; + private readonly Dictionary _parameterizedQueryFilterPredicateCache = new Dictionary(); + private readonly Parameters _parameters = new Parameters(); private static readonly MethodInfo _enumerableToListMethodInfo = typeof(Enumerable).GetTypeInfo() @@ -111,9 +113,9 @@ private Expression ExpandAndReduce(Expression query, bool applyInclude) } private static readonly PropertyInfo _queryContextContextPropertyInfo - = typeof(QueryContext) - .GetTypeInfo() - .GetDeclaredProperty(nameof(QueryContext.Context)); + = typeof(QueryContext) + .GetTypeInfo() + .GetDeclaredProperty(nameof(QueryContext.Context)); protected override Expression VisitConstant(ConstantExpression constantExpression) { @@ -126,7 +128,8 @@ protected override Expression VisitConstant(ConstantExpression constantExpressio { var processedDefiningQueryBody = _parameterExtractingExpressionVisitor.ExtractParameters(definingQuery.Body); processedDefiningQueryBody = _enumerableToQueryableMethodConvertingExpressionVisitor.Visit(processedDefiningQueryBody); - processedDefiningQueryBody = new SelfReferenceEntityQueryableRewritingExpressionVisitor(this, entityType).Visit(processedDefiningQueryBody); + processedDefiningQueryBody = + new SelfReferenceEntityQueryableRewritingExpressionVisitor(this, entityType).Visit(processedDefiningQueryBody); navigationExpansionExpression = (NavigationExpansionExpression)Visit(processedDefiningQueryBody); @@ -172,7 +175,9 @@ private Expression ApplyQueryFilter(NavigationExpansionExpression navigationExpa _parameterizedQueryFilterPredicateCache[rootEntityType] = filterPredicate; } - filterPredicate = (LambdaExpression)new SelfReferenceEntityQueryableRewritingExpressionVisitor(this, entityType).Visit(filterPredicate); + filterPredicate = + (LambdaExpression)new SelfReferenceEntityQueryableRewritingExpressionVisitor(this, entityType).Visit( + filterPredicate); var sequenceType = navigationExpansionExpression.Type.GetSequenceType(); // if we are constructing EntityQueryable of a derived type, we need to re-map filter predicate to the correct derived type @@ -180,7 +185,8 @@ private Expression ApplyQueryFilter(NavigationExpansionExpression navigationExpa if (filterPredicateParameter.Type != sequenceType) { var newFilterPredicateParameter = Expression.Parameter(sequenceType, filterPredicateParameter.Name); - var newFilterPredicateBody = ReplacingExpressionVisitor.Replace(filterPredicateParameter, newFilterPredicateParameter, filterPredicate.Body); + var newFilterPredicateBody = ReplacingExpressionVisitor.Replace( + filterPredicateParameter, newFilterPredicateParameter, filterPredicate.Body); filterPredicate = Expression.Lambda(newFilterPredicateBody, newFilterPredicateParameter); } @@ -214,7 +220,7 @@ var outboundNavigations protected override Expression VisitExtension(Expression extensionExpression) { return extensionExpression is NavigationExpansionExpression - || extensionExpression is OwnedNavigationReference + || extensionExpression is OwnedNavigationReference ? extensionExpression : base.VisitExtension(extensionExpression); } @@ -237,9 +243,10 @@ protected override Expression VisitMember(MemberExpression memberExpression) subquery); } - return Visit(Expression.Call( - QueryableMethods.CountWithoutPredicate.MakeGenericMethod(elementType), - subquery)); + return Visit( + Expression.Call( + QueryableMethods.CountWithoutPredicate.MakeGenericMethod(elementType), + subquery)); } var updatedExpression = (Expression)memberExpression.Update(innerExpression); @@ -280,92 +287,92 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp switch (method.Name) { case nameof(Queryable.AsQueryable) - when genericMethod == QueryableMethods.AsQueryable: + when genericMethod == QueryableMethods.AsQueryable: return source; case nameof(Queryable.Any) - when genericMethod == QueryableMethods.AnyWithoutPredicate: + when genericMethod == QueryableMethods.AnyWithoutPredicate: case nameof(Queryable.Count) - when genericMethod == QueryableMethods.CountWithoutPredicate: + when genericMethod == QueryableMethods.CountWithoutPredicate: case nameof(Queryable.LongCount) - when genericMethod == QueryableMethods.LongCountWithoutPredicate: + when genericMethod == QueryableMethods.LongCountWithoutPredicate: return ProcessAllAnyCountLongCount( source, genericMethod, predicate: null); case nameof(Queryable.All) - when genericMethod == QueryableMethods.All: + when genericMethod == QueryableMethods.All: case nameof(Queryable.Any) - when genericMethod == QueryableMethods.AnyWithPredicate: + when genericMethod == QueryableMethods.AnyWithPredicate: case nameof(Queryable.Count) - when genericMethod == QueryableMethods.CountWithPredicate: + when genericMethod == QueryableMethods.CountWithPredicate: case nameof(Queryable.LongCount) - when genericMethod == QueryableMethods.LongCountWithPredicate: + when genericMethod == QueryableMethods.LongCountWithPredicate: return ProcessAllAnyCountLongCount( source, genericMethod, methodCallExpression.Arguments[1].UnwrapLambdaFromQuote()); case nameof(Queryable.Average) - when QueryableMethods.IsAverageWithoutSelector(method): + when QueryableMethods.IsAverageWithoutSelector(method): case nameof(Queryable.Sum) - when QueryableMethods.IsSumWithoutSelector(method): + when QueryableMethods.IsSumWithoutSelector(method): case nameof(Queryable.Max) - when genericMethod == QueryableMethods.MaxWithoutSelector: + when genericMethod == QueryableMethods.MaxWithoutSelector: case nameof(Queryable.Min) - when genericMethod == QueryableMethods.MinWithoutSelector: + when genericMethod == QueryableMethods.MinWithoutSelector: return ProcessAverageMaxMinSum( source, genericMethod ?? method, null); case nameof(Queryable.Average) - when QueryableMethods.IsAverageWithSelector(method): + when QueryableMethods.IsAverageWithSelector(method): case nameof(Queryable.Sum) - when QueryableMethods.IsSumWithSelector(method): + when QueryableMethods.IsSumWithSelector(method): case nameof(Queryable.Max) - when genericMethod == QueryableMethods.MaxWithSelector: + when genericMethod == QueryableMethods.MaxWithSelector: case nameof(Queryable.Min) - when genericMethod == QueryableMethods.MinWithSelector: + when genericMethod == QueryableMethods.MinWithSelector: return ProcessAverageMaxMinSum( source, genericMethod ?? method, methodCallExpression.Arguments[1].UnwrapLambdaFromQuote()); case nameof(Queryable.Distinct) - when genericMethod == QueryableMethods.Distinct: + when genericMethod == QueryableMethods.Distinct: return ProcessDistinctSkipTake(source, genericMethod, null); case nameof(Queryable.Skip) - when genericMethod == QueryableMethods.Skip: + when genericMethod == QueryableMethods.Skip: case nameof(Queryable.Take) - when genericMethod == QueryableMethods.Take: + when genericMethod == QueryableMethods.Take: return ProcessDistinctSkipTake( source, genericMethod, methodCallExpression.Arguments[1]); case nameof(Queryable.Contains) - when genericMethod == QueryableMethods.Contains: + when genericMethod == QueryableMethods.Contains: return ProcessContains( source, methodCallExpression.Arguments[1]); case nameof(Queryable.First) - when genericMethod == QueryableMethods.FirstWithoutPredicate: + when genericMethod == QueryableMethods.FirstWithoutPredicate: case nameof(Queryable.FirstOrDefault) - when genericMethod == QueryableMethods.FirstOrDefaultWithoutPredicate: + when genericMethod == QueryableMethods.FirstOrDefaultWithoutPredicate: case nameof(Queryable.Single) - when genericMethod == QueryableMethods.SingleWithoutPredicate: + when genericMethod == QueryableMethods.SingleWithoutPredicate: case nameof(Queryable.SingleOrDefault) - when genericMethod == QueryableMethods.SingleOrDefaultWithoutPredicate: + when genericMethod == QueryableMethods.SingleOrDefaultWithoutPredicate: case nameof(Queryable.Last) - when genericMethod == QueryableMethods.LastWithoutPredicate: + when genericMethod == QueryableMethods.LastWithoutPredicate: case nameof(Queryable.LastOrDefault) - when genericMethod == QueryableMethods.LastOrDefaultWithoutPredicate: + when genericMethod == QueryableMethods.LastOrDefaultWithoutPredicate: return ProcessFirstSingleLastOrDefault( source, genericMethod, @@ -373,17 +380,17 @@ when QueryableMethods.IsSumWithSelector(method): methodCallExpression.Type); case nameof(Queryable.First) - when genericMethod == QueryableMethods.FirstWithPredicate: + when genericMethod == QueryableMethods.FirstWithPredicate: case nameof(Queryable.FirstOrDefault) - when genericMethod == QueryableMethods.FirstOrDefaultWithPredicate: + when genericMethod == QueryableMethods.FirstOrDefaultWithPredicate: case nameof(Queryable.Single) - when genericMethod == QueryableMethods.SingleWithPredicate: + when genericMethod == QueryableMethods.SingleWithPredicate: case nameof(Queryable.SingleOrDefault) - when genericMethod == QueryableMethods.SingleOrDefaultWithPredicate: + when genericMethod == QueryableMethods.SingleOrDefaultWithPredicate: case nameof(Queryable.Last) - when genericMethod == QueryableMethods.LastWithPredicate: + when genericMethod == QueryableMethods.LastWithPredicate: case nameof(Queryable.LastOrDefault) - when genericMethod == QueryableMethods.LastOrDefaultWithPredicate: + when genericMethod == QueryableMethods.LastOrDefaultWithPredicate: return ProcessFirstSingleLastOrDefault( source, genericMethod, @@ -391,7 +398,7 @@ when QueryableMethods.IsSumWithSelector(method): methodCallExpression.Type); case nameof(Queryable.Join) - when genericMethod == QueryableMethods.Join: + when genericMethod == QueryableMethods.Join: { var secondArgument = Visit(methodCallExpression.Arguments[1]); if (secondArgument is NavigationExpansionExpression innerSource) @@ -403,11 +410,12 @@ when QueryableMethods.IsSumWithSelector(method): methodCallExpression.Arguments[3].UnwrapLambdaFromQuote(), methodCallExpression.Arguments[4].UnwrapLambdaFromQuote()); } + break; } case nameof(QueryableExtensions.LeftJoin) - when genericMethod == QueryableExtensions.LeftJoinMethodInfo: + when genericMethod == QueryableExtensions.LeftJoinMethodInfo: { var secondArgument = Visit(methodCallExpression.Arguments[1]); if (secondArgument is NavigationExpansionExpression innerSource) @@ -419,31 +427,32 @@ when QueryableMethods.IsSumWithSelector(method): methodCallExpression.Arguments[3].UnwrapLambdaFromQuote(), methodCallExpression.Arguments[4].UnwrapLambdaFromQuote()); } + break; } case nameof(Queryable.SelectMany) - when genericMethod == QueryableMethods.SelectManyWithoutCollectionSelector: + when genericMethod == QueryableMethods.SelectManyWithoutCollectionSelector: return ProcessSelectMany( source, methodCallExpression.Arguments[1].UnwrapLambdaFromQuote(), null); case nameof(Queryable.SelectMany) - when genericMethod == QueryableMethods.SelectManyWithCollectionSelector: + when genericMethod == QueryableMethods.SelectManyWithCollectionSelector: return ProcessSelectMany( source, methodCallExpression.Arguments[1].UnwrapLambdaFromQuote(), methodCallExpression.Arguments[2].UnwrapLambdaFromQuote()); case nameof(Queryable.Concat) - when genericMethod == QueryableMethods.Concat: + when genericMethod == QueryableMethods.Concat: case nameof(Queryable.Except) - when genericMethod == QueryableMethods.Except: + when genericMethod == QueryableMethods.Except: case nameof(Queryable.Intersect) - when genericMethod == QueryableMethods.Intersect: + when genericMethod == QueryableMethods.Intersect: case nameof(Queryable.Union) - when genericMethod == QueryableMethods.Union: + when genericMethod == QueryableMethods.Union: { var secondArgument = Visit(methodCallExpression.Arguments[1]); if (secondArgument is NavigationExpansionExpression innerSource) @@ -453,13 +462,14 @@ when QueryableMethods.IsSumWithSelector(method): genericMethod, innerSource); } + break; } case nameof(Queryable.Cast) - when genericMethod == QueryableMethods.Cast: + when genericMethod == QueryableMethods.Cast: case nameof(Queryable.OfType) - when genericMethod == QueryableMethods.OfType: + when genericMethod == QueryableMethods.OfType: return ProcessCastOfType( source, genericMethod, @@ -470,11 +480,12 @@ when QueryableMethods.IsSumWithSelector(method): return ProcessInclude( source, methodCallExpression.Arguments[1], - string.Equals(method.Name, - nameof(EntityFrameworkQueryableExtensions.ThenInclude))); + string.Equals( + method.Name, + nameof(EntityFrameworkQueryableExtensions.ThenInclude))); case nameof(Queryable.GroupBy) - when genericMethod == QueryableMethods.GroupByWithKeySelector: + when genericMethod == QueryableMethods.GroupByWithKeySelector: return ProcessGroupBy( source, methodCallExpression.Arguments[1].UnwrapLambdaFromQuote(), @@ -482,7 +493,7 @@ when QueryableMethods.IsSumWithSelector(method): null); case nameof(Queryable.GroupBy) - when genericMethod == QueryableMethods.GroupByWithKeyElementSelector: + when genericMethod == QueryableMethods.GroupByWithKeyElementSelector: return ProcessGroupBy( source, methodCallExpression.Arguments[1].UnwrapLambdaFromQuote(), @@ -490,7 +501,7 @@ when QueryableMethods.IsSumWithSelector(method): null); case nameof(Queryable.GroupBy) - when genericMethod == QueryableMethods.GroupByWithKeyElementResultSelector: + when genericMethod == QueryableMethods.GroupByWithKeyElementResultSelector: return ProcessGroupBy( source, methodCallExpression.Arguments[1].UnwrapLambdaFromQuote(), @@ -498,7 +509,7 @@ when QueryableMethods.IsSumWithSelector(method): methodCallExpression.Arguments[3].UnwrapLambdaFromQuote()); case nameof(Queryable.GroupBy) - when genericMethod == QueryableMethods.GroupByWithKeyResultSelector: + when genericMethod == QueryableMethods.GroupByWithKeyResultSelector: return ProcessGroupBy( source, methodCallExpression.Arguments[1].UnwrapLambdaFromQuote(), @@ -506,9 +517,9 @@ when QueryableMethods.IsSumWithSelector(method): methodCallExpression.Arguments[2].UnwrapLambdaFromQuote()); case nameof(Queryable.OrderBy) - when genericMethod == QueryableMethods.OrderBy: + when genericMethod == QueryableMethods.OrderBy: case nameof(Queryable.OrderByDescending) - when genericMethod == QueryableMethods.OrderByDescending: + when genericMethod == QueryableMethods.OrderByDescending: return ProcessOrderByThenBy( source, genericMethod, @@ -516,9 +527,9 @@ when QueryableMethods.IsSumWithSelector(method): thenBy: false); case nameof(Queryable.ThenBy) - when genericMethod == QueryableMethods.ThenBy: + when genericMethod == QueryableMethods.ThenBy: case nameof(Queryable.ThenByDescending) - when genericMethod == QueryableMethods.ThenByDescending: + when genericMethod == QueryableMethods.ThenByDescending: return ProcessOrderByThenBy( source, genericMethod, @@ -526,19 +537,19 @@ when QueryableMethods.IsSumWithSelector(method): thenBy: true); case nameof(Queryable.Select) - when genericMethod == QueryableMethods.Select: + when genericMethod == QueryableMethods.Select: return ProcessSelect( source, methodCallExpression.Arguments[1].UnwrapLambdaFromQuote()); case nameof(Queryable.Where) - when genericMethod == QueryableMethods.Where: + when genericMethod == QueryableMethods.Where: return ProcessWhere( source, methodCallExpression.Arguments[1].UnwrapLambdaFromQuote()); case nameof(Queryable.DefaultIfEmpty) - when genericMethod == QueryableMethods.DefaultIfEmptyWithoutArgument: + when genericMethod == QueryableMethods.DefaultIfEmptyWithoutArgument: return ProcessDefaultIfEmpty(source); default: @@ -546,19 +557,20 @@ when QueryableMethods.IsSumWithSelector(method): } } else if (firstArgument is MaterializeCollectionNavigationExpression materializeCollectionNavigationExpression - && method.Name == nameof(Queryable.AsQueryable)) + && method.Name == nameof(Queryable.AsQueryable)) { var subquery = materializeCollectionNavigationExpression.Subquery; return subquery is OwnedNavigationReference ownedNavigationReference - && ownedNavigationReference.Navigation.IsCollection() - ? Visit(Expression.Call( - QueryableMethods.AsQueryable.MakeGenericMethod(subquery.Type.TryGetSequenceType()), - subquery)) + && ownedNavigationReference.Navigation.IsCollection() + ? Visit( + Expression.Call( + QueryableMethods.AsQueryable.MakeGenericMethod(subquery.Type.TryGetSequenceType()), + subquery)) : subquery; } else if (firstArgument is OwnedNavigationReference ownedNavigationReference - && ownedNavigationReference.Navigation.IsCollection() - && method.Name == nameof(Queryable.AsQueryable)) + && ownedNavigationReference.Navigation.IsCollection() + && method.Name == nameof(Queryable.AsQueryable)) { var parameterName = GetParameterName("o"); var entityReference = ownedNavigationReference.EntityReference; @@ -636,8 +648,8 @@ private Expression ProcessUnknownMethod(MethodCallExpression methodCallExpressio var queryable = Reduce(source); var result = Expression.Call( - methodCallExpression.Method.GetGenericMethodDefinition().MakeGenericMethod(queryableElementType), - new[] { queryable }.Concat(methodCallExpression.Arguments.Skip(1).Select(e => Visit(e)))); + methodCallExpression.Method.GetGenericMethodDefinition().MakeGenericMethod(queryableElementType), + new[] { queryable }.Concat(methodCallExpression.Arguments.Skip(1).Select(e => Visit(e)))); var navigationTree = new NavigationTreeExpression(newStructure); var parameterName = GetParameterName("e"); @@ -657,7 +669,8 @@ private Expression ProcessInclude( { if (entityReferece.EntityType.GetDefiningQuery() != null) { - throw new InvalidOperationException(CoreStrings.IncludeOnEntityWithDefiningQueryNotSupported(entityReferece.EntityType.DisplayName())); + throw new InvalidOperationException( + CoreStrings.IncludeOnEntityWithDefiningQueryNotSupported(entityReferece.EntityType.DisplayName())); } if (expression is ConstantExpression includeConstant @@ -683,7 +696,8 @@ private Expression ProcessInclude( if (includeTreeNodes.Count == 0) { - throw new InvalidOperationException("Invalid include path: '" + navigationChain + + throw new InvalidOperationException( + "Invalid include path: '" + navigationChain + "' - couldn't find navigation for: '" + navigationName + "'"); } } @@ -699,6 +713,7 @@ private Expression ProcessInclude( { throw new InvalidOperationException("Lambda expression used inside Include is not valid."); } + entityReferece.SetLastInclude(lastIncludeTree); } @@ -747,6 +762,7 @@ private IncludeTreeNode PopulateIncludeTree(IncludeTreeNode includeTreeNode, Exp PopulateEagerLoadedNavigations(addedNode); return addedNode; } + break; } @@ -808,8 +824,8 @@ private Expression ProcessSelectMany( var newResultSelector = Expression.Lambda( Expression.New( transparentIdentifierType.GetTypeInfo().GetConstructors().Single(), - new[] { source.CurrentParameter, collectionElementParameter }, - new[] { transparentIdentifierOuterMemberInfo, transparentIdentifierInnerMemberInfo }), + new[] { source.CurrentParameter, collectionElementParameter }, transparentIdentifierOuterMemberInfo, + transparentIdentifierInnerMemberInfo), source.CurrentParameter, collectionElementParameter); @@ -826,8 +842,7 @@ private Expression ProcessSelectMany( : new ReplacingExpressionVisitor( new Dictionary { - { resultSelector.Parameters[0], source.PendingSelector }, - { resultSelector.Parameters[1], innerTree } + { resultSelector.Parameters[0], source.PendingSelector }, { resultSelector.Parameters[1], innerTree } }).Visit(resultSelector.Body); var parameterName = GetParameterName("ti"); @@ -845,10 +860,11 @@ private void ApplyPendingOrderings(NavigationExpansionExpression source) { var keySelectorLambda = GenerateLambda(keySelector, source.CurrentParameter); - source.UpdateSource(Expression.Call( - orderingMethod.MakeGenericMethod(source.SourceElementType, keySelectorLambda.ReturnType), - source.Source, - keySelectorLambda)); + source.UpdateSource( + Expression.Call( + orderingMethod.MakeGenericMethod(source.SourceElementType, keySelectorLambda.ReturnType), + source.Source, + keySelectorLambda)); } source.ClearPendingOrderings(); @@ -883,8 +899,8 @@ private bool CompareIncludes(Expression outer, Expression inner) } return outer is DefaultExpression outerDefaultExpression - && inner is DefaultExpression innerDefaultExpression - && outerDefaultExpression.Type == innerDefaultExpression.Type; + && inner is DefaultExpression innerDefaultExpression + && outerDefaultExpression.Type == innerDefaultExpression.Type; } private Expression ProcessGroupBy( @@ -1018,14 +1034,15 @@ private Expression ProcessJoin( var newResultSelector = Expression.Lambda( Expression.New( transparentIdentifierType.GetTypeInfo().GetConstructors().Single(), - new[] { outerSource.CurrentParameter, innerSource.CurrentParameter }, - new[] { transparentIdentifierOuterMemberInfo, transparentIdentifierInnerMemberInfo }), + new[] { outerSource.CurrentParameter, innerSource.CurrentParameter }, transparentIdentifierOuterMemberInfo, + transparentIdentifierInnerMemberInfo), outerSource.CurrentParameter, innerSource.CurrentParameter); var source = Expression.Call( QueryableMethods.Join.MakeGenericMethod( - outerSource.SourceElementType, innerSource.SourceElementType, outerKeySelector.ReturnType, newResultSelector.ReturnType), + outerSource.SourceElementType, innerSource.SourceElementType, outerKeySelector.ReturnType, + newResultSelector.ReturnType), outerSource.Source, innerSource.Source, Expression.Quote(outerKeySelector), @@ -1071,14 +1088,15 @@ private Expression ProcessLeftJoin( var newResultSelector = Expression.Lambda( Expression.New( transparentIdentifierType.GetTypeInfo().GetConstructors().Single(), - new[] { outerSource.CurrentParameter, innerSource.CurrentParameter }, - new[] { transparentIdentifierOuterMemberInfo, transparentIdentifierInnerMemberInfo }), + new[] { outerSource.CurrentParameter, innerSource.CurrentParameter }, transparentIdentifierOuterMemberInfo, + transparentIdentifierInnerMemberInfo), outerSource.CurrentParameter, innerSource.CurrentParameter); var source = Expression.Call( QueryableExtensions.LeftJoinMethodInfo.MakeGenericMethod( - outerSource.SourceElementType, innerSource.SourceElementType, outerKeySelector.ReturnType, newResultSelector.ReturnType), + outerSource.SourceElementType, innerSource.SourceElementType, outerKeySelector.ReturnType, + newResultSelector.ReturnType), outerSource.Source, innerSource.Source, Expression.Quote(outerKeySelector), @@ -1121,12 +1139,14 @@ private Expression ProcessCastOfType( { newEntityReference.MarkAsOptional(); } + newEntityReference.SetIncludePaths(entityReference.IncludePaths); // Prune includes for sibling types var siblingNavigations = newEntityReference.IncludePaths.Keys - .Where(n => !castEntityType.IsAssignableFrom(n.DeclaringEntityType) - && !n.DeclaringEntityType.IsAssignableFrom(castEntityType)).ToList(); + .Where( + n => !castEntityType.IsAssignableFrom(n.DeclaringEntityType) + && !n.DeclaringEntityType.IsAssignableFrom(castEntityType)).ToList(); foreach (var navigation in siblingNavigations) { @@ -1219,7 +1239,7 @@ private Expression SnapshotExpression(Expression selector) for (var i = 0; i < newExpression.Arguments.Count; i++) { arguments[i] = newExpression.Arguments[i] is NewExpression - || newExpression.Arguments[i] is NavigationTreeExpression + || newExpression.Arguments[i] is NavigationTreeExpression ? SnapshotExpression(newExpression.Arguments[i]) : Expression.Default(newExpression.Arguments[i].Type); } @@ -1242,7 +1262,7 @@ private Expression SnapshotExpression(Expression selector) { QueryableMethods.SingleWithPredicate, QueryableMethods.SingleWithoutPredicate }, { QueryableMethods.SingleOrDefaultWithPredicate, QueryableMethods.SingleOrDefaultWithoutPredicate }, { QueryableMethods.LastWithPredicate, QueryableMethods.LastWithoutPredicate }, - { QueryableMethods.LastOrDefaultWithPredicate, QueryableMethods.LastOrDefaultWithoutPredicate }, + { QueryableMethods.LastOrDefaultWithPredicate, QueryableMethods.LastOrDefaultWithoutPredicate } }; private Expression ProcessFirstSingleLastOrDefault( @@ -1255,10 +1275,11 @@ private Expression ProcessFirstSingleLastOrDefault( { var predicateBody = ExpandNavigationsInLambdaExpression(source, predicate); - source.UpdateSource(Expression.Call( - QueryableMethods.Where.MakeGenericMethod(source.SourceElementType), - source.Source, - Expression.Quote(GenerateLambda(predicateBody, source.CurrentParameter)))); + source.UpdateSource( + Expression.Call( + QueryableMethods.Where.MakeGenericMethod(source.SourceElementType), + source.Source, + Expression.Quote(GenerateLambda(predicateBody, source.CurrentParameter)))); genericMethod = _predicateLessMethodInfo[genericMethod]; } @@ -1302,7 +1323,7 @@ private Expression ProcessSelect( if (source.SourceElementType.IsGenericType && source.SourceElementType.GetGenericTypeDefinition() == typeof(IGrouping<,>) && !(selector.ReturnType.IsGenericType - && selector.ReturnType.GetGenericTypeDefinition() == typeof(IGrouping<,>))) + && selector.ReturnType.GetGenericTypeDefinition() == typeof(IGrouping<,>))) { var selectorLambda = GenerateLambda(ExpandNavigationsInLambdaExpression(source, selector), source.CurrentParameter); @@ -1370,10 +1391,11 @@ private Expression ProcessWhere( { var predicateBody = ExpandNavigationsInLambdaExpression(source, predicate); - source.UpdateSource(Expression.Call( - QueryableMethods.Where.MakeGenericMethod(source.SourceElementType), - source.Source, - Expression.Quote(GenerateLambda(predicateBody, source.CurrentParameter)))); + source.UpdateSource( + Expression.Call( + QueryableMethods.Where.MakeGenericMethod(source.SourceElementType), + source.Source, + Expression.Quote(GenerateLambda(predicateBody, source.CurrentParameter)))); return source; } diff --git a/src/EFCore/Query/Internal/NegationOptimizingExpressionVisitor.cs b/src/EFCore/Query/Internal/NegationOptimizingExpressionVisitor.cs index 5cf94408fb2..efae0d840d7 100644 --- a/src/EFCore/Query/Internal/NegationOptimizingExpressionVisitor.cs +++ b/src/EFCore/Query/Internal/NegationOptimizingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; @@ -10,17 +10,18 @@ public class NegationOptimizingExpressionVisitor : ExpressionVisitor { private static bool TryNegate(ExpressionType expressionType, out ExpressionType result) { - var negated = expressionType switch { - ExpressionType.AndAlso => ExpressionType.OrElse, - ExpressionType.OrElse => ExpressionType.AndAlso, - ExpressionType.Equal => ExpressionType.NotEqual, - ExpressionType.NotEqual => ExpressionType.Equal, - ExpressionType.GreaterThan => ExpressionType.LessThanOrEqual, + var negated = expressionType switch + { + ExpressionType.AndAlso => ExpressionType.OrElse, + ExpressionType.OrElse => ExpressionType.AndAlso, + ExpressionType.Equal => ExpressionType.NotEqual, + ExpressionType.NotEqual => ExpressionType.Equal, + ExpressionType.GreaterThan => ExpressionType.LessThanOrEqual, ExpressionType.GreaterThanOrEqual => ExpressionType.LessThan, - ExpressionType.LessThan => ExpressionType.GreaterThanOrEqual, - ExpressionType.LessThanOrEqual => ExpressionType.GreaterThan, + ExpressionType.LessThan => ExpressionType.GreaterThanOrEqual, + ExpressionType.LessThanOrEqual => ExpressionType.GreaterThan, _ => (ExpressionType?)null - }; + }; result = negated ?? default; return negated.HasValue; diff --git a/src/EFCore/Query/Internal/NullAsyncQueryProvider.cs b/src/EFCore/Query/Internal/NullAsyncQueryProvider.cs index 2637fcd7233..5669a08ed23 100644 --- a/src/EFCore/Query/Internal/NullAsyncQueryProvider.cs +++ b/src/EFCore/Query/Internal/NullAsyncQueryProvider.cs @@ -17,8 +17,8 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/Query/Internal/NullCheckRemovingExpressionVisitor.cs b/src/EFCore/Query/Internal/NullCheckRemovingExpressionVisitor.cs index 899c921a145..57fe75004de 100644 --- a/src/EFCore/Query/Internal/NullCheckRemovingExpressionVisitor.cs +++ b/src/EFCore/Query/Internal/NullCheckRemovingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; @@ -10,6 +10,7 @@ public class NullCheckRemovingExpressionVisitor : ExpressionVisitor { private readonly NullSafeAccessVerifyingExpressionVisitor _nullSafeAccessVerifyingExpressionVisitor = new NullSafeAccessVerifyingExpressionVisitor(); + private readonly NullConditionalRemovingExpressionVisitor _nullConditionalRemovingExpressionVisitor = new NullConditionalRemovingExpressionVisitor(); @@ -114,6 +115,6 @@ protected override Expression VisitUnary(UnaryExpression unaryExpression) private bool IsNullConstant(Expression expression) => expression is ConstantExpression constantExpression - && constantExpression.Value == null; + && constantExpression.Value == null; } } diff --git a/src/EFCore/Query/Internal/ParameterExtractingExpressionVisitor.cs b/src/EFCore/Query/Internal/ParameterExtractingExpressionVisitor.cs index c6e813c53e6..50003e72b4f 100644 --- a/src/EFCore/Query/Internal/ParameterExtractingExpressionVisitor.cs +++ b/src/EFCore/Query/Internal/ParameterExtractingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -30,6 +30,7 @@ public class ParameterExtractingExpressionVisitor : ExpressionVisitor private readonly bool _generateContextAccessors; private readonly EvaluatableExpressionFindingExpressionVisitor _evaluatableExpressionFindingExpressionVisitor; private readonly ContextParameterReplacingExpressionVisitor _contextParameterReplacingExpressionVisitor; + private readonly Dictionary _evaluatedValues = new Dictionary(ExpressionEqualityComparer.Instance); @@ -535,7 +536,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp protected override Expression VisitMember(MemberExpression memberExpression) { _containsClosure = memberExpression.Expression != null - || !(memberExpression.Member is FieldInfo fieldInfo && fieldInfo.IsInitOnly); + || !(memberExpression.Member is FieldInfo fieldInfo && fieldInfo.IsInitOnly); return base.VisitMember(memberExpression); } diff --git a/src/EFCore/Query/Internal/QueryCompilationContextFactory.cs b/src/EFCore/Query/Internal/QueryCompilationContextFactory.cs index f4131e58677..7bb4fd837c3 100644 --- a/src/EFCore/Query/Internal/QueryCompilationContextFactory.cs +++ b/src/EFCore/Query/Internal/QueryCompilationContextFactory.cs @@ -7,7 +7,7 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal { /// /// - /// A factory for creating instances. + /// A factory for creating instances. /// /// /// The service lifetime is . This means that each diff --git a/src/EFCore/Query/Internal/QueryCompiler.cs b/src/EFCore/Query/Internal/QueryCompiler.cs index 5b952f42bbe..ba65196cfbe 100644 --- a/src/EFCore/Query/Internal/QueryCompiler.cs +++ b/src/EFCore/Query/Internal/QueryCompiler.cs @@ -22,8 +22,8 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/Query/Internal/QueryMetadataExtractingExpressionVisitor.cs b/src/EFCore/Query/Internal/QueryMetadataExtractingExpressionVisitor.cs index 626241c4d00..f2927a32975 100644 --- a/src/EFCore/Query/Internal/QueryMetadataExtractingExpressionVisitor.cs +++ b/src/EFCore/Query/Internal/QueryMetadataExtractingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq.Expressions; diff --git a/src/EFCore/Query/Internal/QueryTranslationPostprocessorFactory.cs b/src/EFCore/Query/Internal/QueryTranslationPostprocessorFactory.cs index 8140c291687..2f8d23fadf9 100644 --- a/src/EFCore/Query/Internal/QueryTranslationPostprocessorFactory.cs +++ b/src/EFCore/Query/Internal/QueryTranslationPostprocessorFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.Extensions.DependencyInjection; diff --git a/src/EFCore/Query/Internal/QueryTranslationPreprocessorFactory.cs b/src/EFCore/Query/Internal/QueryTranslationPreprocessorFactory.cs index 9b67e8aa29e..d496b5f557b 100644 --- a/src/EFCore/Query/Internal/QueryTranslationPreprocessorFactory.cs +++ b/src/EFCore/Query/Internal/QueryTranslationPreprocessorFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.Extensions.DependencyInjection; @@ -7,12 +7,12 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal { /// /// - /// A factory for creating instances. + /// A factory for creating instances. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class QueryTranslationPreprocessorFactory : IQueryTranslationPreprocessorFactory diff --git a/src/EFCore/Query/Internal/SubqueryMemberPushdownExpressionVisitor.cs b/src/EFCore/Query/Internal/SubqueryMemberPushdownExpressionVisitor.cs index 06a73286b76..b04eb9a0026 100644 --- a/src/EFCore/Query/Internal/SubqueryMemberPushdownExpressionVisitor.cs +++ b/src/EFCore/Query/Internal/SubqueryMemberPushdownExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -13,32 +13,32 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal public class SubqueryMemberPushdownExpressionVisitor : ExpressionVisitor { private static readonly List _supportedMethods = new List - { - QueryableMethods.FirstWithPredicate, - QueryableMethods.FirstWithoutPredicate, - QueryableMethods.FirstOrDefaultWithPredicate, - QueryableMethods.FirstOrDefaultWithoutPredicate, - QueryableMethods.SingleWithPredicate, - QueryableMethods.SingleWithoutPredicate, - QueryableMethods.SingleOrDefaultWithPredicate, - QueryableMethods.SingleOrDefaultWithoutPredicate, - QueryableMethods.LastWithPredicate, - QueryableMethods.LastWithoutPredicate, - QueryableMethods.LastOrDefaultWithPredicate, - QueryableMethods.LastOrDefaultWithoutPredicate, - //QueryableMethodProvider.ElementAtMethodInfo, - //QueryableMethodProvider.ElementAtOrDefaultMethodInfo - }; + { + QueryableMethods.FirstWithPredicate, + QueryableMethods.FirstWithoutPredicate, + QueryableMethods.FirstOrDefaultWithPredicate, + QueryableMethods.FirstOrDefaultWithoutPredicate, + QueryableMethods.SingleWithPredicate, + QueryableMethods.SingleWithoutPredicate, + QueryableMethods.SingleOrDefaultWithPredicate, + QueryableMethods.SingleOrDefaultWithoutPredicate, + QueryableMethods.LastWithPredicate, + QueryableMethods.LastWithoutPredicate, + QueryableMethods.LastOrDefaultWithPredicate, + QueryableMethods.LastOrDefaultWithoutPredicate + //QueryableMethodProvider.ElementAtMethodInfo, + //QueryableMethodProvider.ElementAtOrDefaultMethodInfo + }; private static readonly IDictionary _predicateLessMethodInfo = new Dictionary - { - { QueryableMethods.FirstWithPredicate, QueryableMethods.FirstWithoutPredicate }, - { QueryableMethods.FirstOrDefaultWithPredicate, QueryableMethods.FirstOrDefaultWithoutPredicate }, - { QueryableMethods.SingleWithPredicate, QueryableMethods.SingleWithoutPredicate }, - { QueryableMethods.SingleOrDefaultWithPredicate, QueryableMethods.SingleOrDefaultWithoutPredicate }, - { QueryableMethods.LastWithPredicate, QueryableMethods.LastWithoutPredicate }, - { QueryableMethods.LastOrDefaultWithPredicate, QueryableMethods.LastOrDefaultWithoutPredicate }, - }; + { + { QueryableMethods.FirstWithPredicate, QueryableMethods.FirstWithoutPredicate }, + { QueryableMethods.FirstOrDefaultWithPredicate, QueryableMethods.FirstOrDefaultWithoutPredicate }, + { QueryableMethods.SingleWithPredicate, QueryableMethods.SingleWithoutPredicate }, + { QueryableMethods.SingleOrDefaultWithPredicate, QueryableMethods.SingleOrDefaultWithoutPredicate }, + { QueryableMethods.LastWithPredicate, QueryableMethods.LastWithoutPredicate }, + { QueryableMethods.LastOrDefaultWithPredicate, QueryableMethods.LastOrDefaultWithoutPredicate } + }; protected override Expression VisitMember(MemberExpression memberExpression) { @@ -53,8 +53,8 @@ protected override Expression VisitMember(MemberExpression memberExpression) { var memberAccessExpression = Expression.MakeMemberAccess(target, memberExpression.Member); return nullable && !memberAccessExpression.Type.IsNullableType() - ? Expression.Convert(memberAccessExpression, memberAccessExpression.Type.MakeNullable()) - : (Expression)memberAccessExpression; + ? Expression.Convert(memberAccessExpression, memberAccessExpression.Type.MakeNullable()) + : (Expression)memberAccessExpression; }, memberExpression.Type); } diff --git a/src/EFCore/Query/MaterializeCollectionNavigationExpression.cs b/src/EFCore/Query/MaterializeCollectionNavigationExpression.cs index 403d4a10026..01f4f3ae36b 100644 --- a/src/EFCore/Query/MaterializeCollectionNavigationExpression.cs +++ b/src/EFCore/Query/MaterializeCollectionNavigationExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Query/NullConditionalExpression.cs b/src/EFCore/Query/NullConditionalExpression.cs index 17ef312989b..4c8097ee479 100644 --- a/src/EFCore/Query/NullConditionalExpression.cs +++ b/src/EFCore/Query/NullConditionalExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Query/ProjectionBindingExpression.cs b/src/EFCore/Query/ProjectionBindingExpression.cs index 7a85d721b3b..8d6d5e27f29 100644 --- a/src/EFCore/Query/ProjectionBindingExpression.cs +++ b/src/EFCore/Query/ProjectionBindingExpression.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -66,9 +66,9 @@ public virtual void Print(ExpressionPrinter expressionPrinter) public override bool Equals(object obj) => obj != null - && (ReferenceEquals(this, obj) - || obj is ProjectionBindingExpression projectionBindingExpression - && Equals(projectionBindingExpression)); + && (ReferenceEquals(this, obj) + || obj is ProjectionBindingExpression projectionBindingExpression + && Equals(projectionBindingExpression)); private bool Equals(ProjectionBindingExpression projectionBindingExpression) => QueryExpression.Equals(projectionBindingExpression.QueryExpression) diff --git a/src/EFCore/Query/ProjectionMember.cs b/src/EFCore/Query/ProjectionMember.cs index 142e48fd49c..0a50df1366a 100644 --- a/src/EFCore/Query/ProjectionMember.cs +++ b/src/EFCore/Query/ProjectionMember.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Query/QueryCompilationContext.cs b/src/EFCore/Query/QueryCompilationContext.cs index d175ead9f36..689c0c07004 100644 --- a/src/EFCore/Query/QueryCompilationContext.cs +++ b/src/EFCore/Query/QueryCompilationContext.cs @@ -97,9 +97,11 @@ public virtual Func CreateQueryExecutor(Expressi /// public virtual ParameterExpression RegisterRuntimeParameter(string name, LambdaExpression valueExtractor) { - if (valueExtractor.Parameters.Count != 1 || valueExtractor.Parameters[0] != QueryContextParameter) + if (valueExtractor.Parameters.Count != 1 + || valueExtractor.Parameters[0] != QueryContextParameter) { - throw new ArgumentException("Runtime parameter extraction lambda must have one QueryContext parameter", + throw new ArgumentException( + "Runtime parameter extraction lambda must have one QueryContext parameter", nameof(valueExtractor)); } @@ -115,14 +117,16 @@ public virtual ParameterExpression RegisterRuntimeParameter(string name, LambdaE private Expression InsertRuntimeParameters(Expression query) => _runtimeParameters == null ? query - : Expression.Block(_runtimeParameters - .Select(kv => - Expression.Call( - QueryContextParameter, - _queryContextAddParameterMethodInfo, - Expression.Constant(kv.Key), - Expression.Convert(Expression.Invoke(kv.Value, QueryContextParameter), typeof(object)))) - .Append(query)); + : Expression.Block( + _runtimeParameters + .Select( + kv => + Expression.Call( + QueryContextParameter, + _queryContextAddParameterMethodInfo, + Expression.Constant(kv.Key), + Expression.Convert(Expression.Invoke(kv.Value, QueryContextParameter), typeof(object)))) + .Append(query)); private static readonly MethodInfo _queryContextAddParameterMethodInfo = typeof(QueryContext) diff --git a/src/EFCore/Query/QueryCompilationContextDependencies.cs b/src/EFCore/Query/QueryCompilationContextDependencies.cs index 7e8c6a19d39..943b21787a7 100644 --- a/src/EFCore/Query/QueryCompilationContextDependencies.cs +++ b/src/EFCore/Query/QueryCompilationContextDependencies.cs @@ -178,7 +178,8 @@ public QueryCompilationContextDependencies With( /// /// A replacement for the current dependency of this type. /// A new parameter object with the given service replaced. - public QueryCompilationContextDependencies With([NotNull] IQueryTranslationPostprocessorFactory queryTranslationPostprocessorFactory) + public QueryCompilationContextDependencies With( + [NotNull] IQueryTranslationPostprocessorFactory queryTranslationPostprocessorFactory) => new QueryCompilationContextDependencies( Model, QueryTranslationPreprocessorFactory, diff --git a/src/EFCore/Query/QueryContext.cs b/src/EFCore/Query/QueryContext.cs index 28cacaedbfd..b5b048f8532 100644 --- a/src/EFCore/Query/QueryContext.cs +++ b/src/EFCore/Query/QueryContext.cs @@ -8,7 +8,6 @@ using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Utilities; @@ -24,7 +23,7 @@ public abstract class QueryContext : IParameterValues /// /// - /// Creates a new instance. + /// Creates a new instance. /// /// /// This type is typically used by database providers (and other extensions). It is generally diff --git a/src/EFCore/Query/QueryContextDependencies.cs b/src/EFCore/Query/QueryContextDependencies.cs index 9aa77e8d5a3..8fb976b5ce7 100644 --- a/src/EFCore/Query/QueryContextDependencies.cs +++ b/src/EFCore/Query/QueryContextDependencies.cs @@ -29,8 +29,8 @@ namespace Microsoft.EntityFrameworkCore.Query /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/Query/QueryTranslationPostprocessor.cs b/src/EFCore/Query/QueryTranslationPostprocessor.cs index 28dfd7e88fd..bbf3b3d5bf3 100644 --- a/src/EFCore/Query/QueryTranslationPostprocessor.cs +++ b/src/EFCore/Query/QueryTranslationPostprocessor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq.Expressions; diff --git a/src/EFCore/Query/QueryTranslationPostprocessorDependencies.cs b/src/EFCore/Query/QueryTranslationPostprocessorDependencies.cs index 313dd9d4287..639307af0e2 100644 --- a/src/EFCore/Query/QueryTranslationPostprocessorDependencies.cs +++ b/src/EFCore/Query/QueryTranslationPostprocessorDependencies.cs @@ -23,9 +23,9 @@ namespace Microsoft.EntityFrameworkCore.Query /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public sealed class QueryTranslationPostprocessorDependencies diff --git a/src/EFCore/Query/QueryTranslationPreprocessor.cs b/src/EFCore/Query/QueryTranslationPreprocessor.cs index 6490296c7cf..be10f8531a9 100644 --- a/src/EFCore/Query/QueryTranslationPreprocessor.cs +++ b/src/EFCore/Query/QueryTranslationPreprocessor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq; @@ -31,7 +31,8 @@ public virtual Expression Process(Expression query) query = new NullCheckRemovingExpressionVisitor().Visit(query); query = new EntityEqualityRewritingExpressionVisitor(_queryCompilationContext).Rewrite(query); query = new SubqueryMemberPushdownExpressionVisitor().Visit(query); - query = new NavigationExpandingExpressionVisitor(_queryCompilationContext, Dependencies.EvaluatableExpressionFilter).Expand(query); + query = new NavigationExpandingExpressionVisitor(_queryCompilationContext, Dependencies.EvaluatableExpressionFilter).Expand( + query); query = new FunctionPreprocessingExpressionVisitor().Visit(query); new EnumerableVerifyingExpressionVisitor().Visit(query); diff --git a/src/EFCore/Query/QueryTranslationPreprocessorDependencies.cs b/src/EFCore/Query/QueryTranslationPreprocessorDependencies.cs index 20de5f247b5..e5b7932ddc9 100644 --- a/src/EFCore/Query/QueryTranslationPreprocessorDependencies.cs +++ b/src/EFCore/Query/QueryTranslationPreprocessorDependencies.cs @@ -25,9 +25,9 @@ namespace Microsoft.EntityFrameworkCore.Query /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public sealed class QueryTranslationPreprocessorDependencies diff --git a/src/EFCore/Query/QueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore/Query/QueryableMethodTranslatingExpressionVisitor.cs index 8cb80eedc0b..bc90d1589e8 100644 --- a/src/EFCore/Query/QueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore/Query/QueryableMethodTranslatingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -47,7 +47,8 @@ ShapedQueryExpression CheckTranslated(ShapedQueryExpression translated) } var method = methodCallExpression.Method; - if (method.DeclaringType == typeof(Queryable) || method.DeclaringType == typeof(QueryableExtensions)) + if (method.DeclaringType == typeof(Queryable) + || method.DeclaringType == typeof(QueryableExtensions)) { var source = Visit(methodCallExpression.Arguments[0]); if (source is ShapedQueryExpression shapedQueryExpression) @@ -56,40 +57,41 @@ ShapedQueryExpression CheckTranslated(ShapedQueryExpression translated) switch (method.Name) { case nameof(Queryable.All) - when genericMethod == QueryableMethods.All: + when genericMethod == QueryableMethods.All: shapedQueryExpression.ResultCardinality = ResultCardinality.Single; return CheckTranslated(TranslateAll(shapedQueryExpression, GetLambdaExpressionFromArgument(1))); case nameof(Queryable.Any) - when genericMethod == QueryableMethods.AnyWithoutPredicate: + when genericMethod == QueryableMethods.AnyWithoutPredicate: shapedQueryExpression.ResultCardinality = ResultCardinality.Single; return CheckTranslated(TranslateAny(shapedQueryExpression, null)); case nameof(Queryable.Any) - when genericMethod == QueryableMethods.AnyWithPredicate: + when genericMethod == QueryableMethods.AnyWithPredicate: shapedQueryExpression.ResultCardinality = ResultCardinality.Single; return CheckTranslated(TranslateAny(shapedQueryExpression, GetLambdaExpressionFromArgument(1))); case nameof(Queryable.AsQueryable) - when genericMethod == QueryableMethods.AsQueryable: + when genericMethod == QueryableMethods.AsQueryable: return source; case nameof(Queryable.Average) - when QueryableMethods.IsAverageWithoutSelector(method): + when QueryableMethods.IsAverageWithoutSelector(method): shapedQueryExpression.ResultCardinality = ResultCardinality.Single; return CheckTranslated(TranslateAverage(shapedQueryExpression, null, methodCallExpression.Type)); case nameof(Queryable.Average) - when QueryableMethods.IsAverageWithSelector(method): + when QueryableMethods.IsAverageWithSelector(method): shapedQueryExpression.ResultCardinality = ResultCardinality.Single; - return CheckTranslated(TranslateAverage(shapedQueryExpression, GetLambdaExpressionFromArgument(1), methodCallExpression.Type)); + return CheckTranslated( + TranslateAverage(shapedQueryExpression, GetLambdaExpressionFromArgument(1), methodCallExpression.Type)); case nameof(Queryable.Cast) - when genericMethod == QueryableMethods.Cast: + when genericMethod == QueryableMethods.Cast: return CheckTranslated(TranslateCast(shapedQueryExpression, method.GetGenericArguments()[0])); case nameof(Queryable.Concat) - when genericMethod == QueryableMethods.Concat: + when genericMethod == QueryableMethods.Concat: { var source2 = Visit(methodCallExpression.Arguments[1]); if (source2 is ShapedQueryExpression innerShapedQueryExpression) @@ -98,78 +100,87 @@ when QueryableMethods.IsAverageWithSelector(method): shapedQueryExpression, innerShapedQueryExpression); } + break; } case nameof(Queryable.Contains) - when genericMethod == QueryableMethods.Contains: + when genericMethod == QueryableMethods.Contains: shapedQueryExpression.ResultCardinality = ResultCardinality.Single; return CheckTranslated(TranslateContains(shapedQueryExpression, methodCallExpression.Arguments[1])); case nameof(Queryable.Count) - when genericMethod == QueryableMethods.CountWithoutPredicate: + when genericMethod == QueryableMethods.CountWithoutPredicate: shapedQueryExpression.ResultCardinality = ResultCardinality.Single; return CheckTranslated(TranslateCount(shapedQueryExpression, null)); case nameof(Queryable.Count) - when genericMethod == QueryableMethods.CountWithPredicate: + when genericMethod == QueryableMethods.CountWithPredicate: shapedQueryExpression.ResultCardinality = ResultCardinality.Single; return CheckTranslated(TranslateCount(shapedQueryExpression, GetLambdaExpressionFromArgument(1))); case nameof(Queryable.DefaultIfEmpty) - when genericMethod == QueryableMethods.DefaultIfEmptyWithoutArgument: + when genericMethod == QueryableMethods.DefaultIfEmptyWithoutArgument: return CheckTranslated(TranslateDefaultIfEmpty(shapedQueryExpression, null)); case nameof(Queryable.DefaultIfEmpty) - when genericMethod == QueryableMethods.DefaultIfEmptyWithArgument: + when genericMethod == QueryableMethods.DefaultIfEmptyWithArgument: return CheckTranslated(TranslateDefaultIfEmpty(shapedQueryExpression, methodCallExpression.Arguments[1])); case nameof(Queryable.Distinct) - when genericMethod == QueryableMethods.Distinct: + when genericMethod == QueryableMethods.Distinct: return CheckTranslated(TranslateDistinct(shapedQueryExpression)); case nameof(Queryable.ElementAt) - when genericMethod == QueryableMethods.ElementAt: + when genericMethod == QueryableMethods.ElementAt: shapedQueryExpression.ResultCardinality = ResultCardinality.Single; - return CheckTranslated(TranslateElementAtOrDefault(shapedQueryExpression, methodCallExpression.Arguments[1], false)); + return CheckTranslated( + TranslateElementAtOrDefault(shapedQueryExpression, methodCallExpression.Arguments[1], false)); case nameof(Queryable.ElementAtOrDefault) - when genericMethod == QueryableMethods.ElementAtOrDefault: + when genericMethod == QueryableMethods.ElementAtOrDefault: shapedQueryExpression.ResultCardinality = ResultCardinality.SingleOrDefault; - return CheckTranslated(TranslateElementAtOrDefault(shapedQueryExpression, methodCallExpression.Arguments[1], true)); + return CheckTranslated( + TranslateElementAtOrDefault(shapedQueryExpression, methodCallExpression.Arguments[1], true)); case nameof(Queryable.Except) - when genericMethod == QueryableMethods.Except: + when genericMethod == QueryableMethods.Except: { var source2 = Visit(methodCallExpression.Arguments[1]); if (source2 is ShapedQueryExpression innerShapedQueryExpression) { - return CheckTranslated(TranslateExcept( - shapedQueryExpression, - innerShapedQueryExpression)); + return CheckTranslated( + TranslateExcept( + shapedQueryExpression, + innerShapedQueryExpression)); } + break; } case nameof(Queryable.First) - when genericMethod == QueryableMethods.FirstWithoutPredicate: + when genericMethod == QueryableMethods.FirstWithoutPredicate: shapedQueryExpression.ResultCardinality = ResultCardinality.Single; return CheckTranslated(TranslateFirstOrDefault(shapedQueryExpression, null, methodCallExpression.Type, false)); case nameof(Queryable.First) - when genericMethod == QueryableMethods.FirstWithPredicate: + when genericMethod == QueryableMethods.FirstWithPredicate: shapedQueryExpression.ResultCardinality = ResultCardinality.Single; - return CheckTranslated(TranslateFirstOrDefault(shapedQueryExpression, GetLambdaExpressionFromArgument(1), methodCallExpression.Type, false)); + return CheckTranslated( + TranslateFirstOrDefault( + shapedQueryExpression, GetLambdaExpressionFromArgument(1), methodCallExpression.Type, false)); case nameof(Queryable.FirstOrDefault) - when genericMethod == QueryableMethods.FirstOrDefaultWithoutPredicate: + when genericMethod == QueryableMethods.FirstOrDefaultWithoutPredicate: shapedQueryExpression.ResultCardinality = ResultCardinality.SingleOrDefault; return CheckTranslated(TranslateFirstOrDefault(shapedQueryExpression, null, methodCallExpression.Type, true)); case nameof(Queryable.FirstOrDefault) - when genericMethod == QueryableMethods.FirstOrDefaultWithPredicate: + when genericMethod == QueryableMethods.FirstOrDefaultWithPredicate: shapedQueryExpression.ResultCardinality = ResultCardinality.SingleOrDefault; - return CheckTranslated(TranslateFirstOrDefault(shapedQueryExpression, GetLambdaExpressionFromArgument(1), methodCallExpression.Type, true)); + return CheckTranslated( + TranslateFirstOrDefault( + shapedQueryExpression, GetLambdaExpressionFromArgument(1), methodCallExpression.Type, true)); case nameof(Queryable.GroupBy) when genericMethod == QueryableMethods.GroupByWithKeySelector: @@ -177,18 +188,25 @@ when QueryableMethods.IsAverageWithSelector(method): case nameof(Queryable.GroupBy) when genericMethod == QueryableMethods.GroupByWithKeyElementSelector: - return CheckTranslated(TranslateGroupBy(shapedQueryExpression, GetLambdaExpressionFromArgument(1), GetLambdaExpressionFromArgument(2), null)); + return CheckTranslated( + TranslateGroupBy( + shapedQueryExpression, GetLambdaExpressionFromArgument(1), GetLambdaExpressionFromArgument(2), null)); case nameof(Queryable.GroupBy) - when genericMethod == QueryableMethods.GroupByWithKeyElementResultSelector: - return CheckTranslated(TranslateGroupBy(shapedQueryExpression, GetLambdaExpressionFromArgument(1), GetLambdaExpressionFromArgument(2), GetLambdaExpressionFromArgument(3))); + when genericMethod == QueryableMethods.GroupByWithKeyElementResultSelector: + return CheckTranslated( + TranslateGroupBy( + shapedQueryExpression, GetLambdaExpressionFromArgument(1), GetLambdaExpressionFromArgument(2), + GetLambdaExpressionFromArgument(3))); case nameof(Queryable.GroupBy) - when genericMethod == QueryableMethods.GroupByWithKeyResultSelector: - return CheckTranslated(TranslateGroupBy(shapedQueryExpression, GetLambdaExpressionFromArgument(1), null, GetLambdaExpressionFromArgument(2))); + when genericMethod == QueryableMethods.GroupByWithKeyResultSelector: + return CheckTranslated( + TranslateGroupBy( + shapedQueryExpression, GetLambdaExpressionFromArgument(1), null, GetLambdaExpressionFromArgument(2))); case nameof(Queryable.GroupJoin) - when genericMethod == QueryableMethods.GroupJoin: + when genericMethod == QueryableMethods.GroupJoin: { if (Visit(methodCallExpression.Arguments[1]) is ShapedQueryExpression innerShapedQueryExpression) { @@ -200,186 +218,211 @@ when QueryableMethods.IsAverageWithSelector(method): GetLambdaExpressionFromArgument(3), GetLambdaExpressionFromArgument(4))); } + break; } case nameof(Queryable.Intersect) - when genericMethod == QueryableMethods.Intersect: + when genericMethod == QueryableMethods.Intersect: { if (Visit(methodCallExpression.Arguments[1]) is ShapedQueryExpression innerShapedQueryExpression) { return CheckTranslated(TranslateIntersect(shapedQueryExpression, innerShapedQueryExpression)); } + break; } case nameof(Queryable.Join) - when genericMethod == QueryableMethods.Join: + when genericMethod == QueryableMethods.Join: { if (Visit(methodCallExpression.Arguments[1]) is ShapedQueryExpression innerShapedQueryExpression) { - return CheckTranslated(TranslateJoin(shapedQueryExpression, innerShapedQueryExpression, GetLambdaExpressionFromArgument(2), GetLambdaExpressionFromArgument(3), GetLambdaExpressionFromArgument(4))); + return CheckTranslated( + TranslateJoin( + shapedQueryExpression, innerShapedQueryExpression, GetLambdaExpressionFromArgument(2), + GetLambdaExpressionFromArgument(3), GetLambdaExpressionFromArgument(4))); } + break; } case nameof(QueryableExtensions.LeftJoin) - when genericMethod == QueryableExtensions.LeftJoinMethodInfo: + when genericMethod == QueryableExtensions.LeftJoinMethodInfo: { if (Visit(methodCallExpression.Arguments[1]) is ShapedQueryExpression innerShapedQueryExpression) { - return CheckTranslated(TranslateLeftJoin(shapedQueryExpression, innerShapedQueryExpression, GetLambdaExpressionFromArgument(2), GetLambdaExpressionFromArgument(3), GetLambdaExpressionFromArgument(4))); + return CheckTranslated( + TranslateLeftJoin( + shapedQueryExpression, innerShapedQueryExpression, GetLambdaExpressionFromArgument(2), + GetLambdaExpressionFromArgument(3), GetLambdaExpressionFromArgument(4))); } + break; } case nameof(Queryable.Last) - when genericMethod == QueryableMethods.LastWithoutPredicate: + when genericMethod == QueryableMethods.LastWithoutPredicate: shapedQueryExpression.ResultCardinality = ResultCardinality.Single; return CheckTranslated(TranslateLastOrDefault(shapedQueryExpression, null, methodCallExpression.Type, false)); case nameof(Queryable.Last) - when genericMethod == QueryableMethods.LastWithPredicate: + when genericMethod == QueryableMethods.LastWithPredicate: shapedQueryExpression.ResultCardinality = ResultCardinality.Single; - return CheckTranslated(TranslateLastOrDefault(shapedQueryExpression, GetLambdaExpressionFromArgument(1), methodCallExpression.Type, false)); + return CheckTranslated( + TranslateLastOrDefault( + shapedQueryExpression, GetLambdaExpressionFromArgument(1), methodCallExpression.Type, false)); case nameof(Queryable.LastOrDefault) - when genericMethod == QueryableMethods.LastOrDefaultWithoutPredicate: + when genericMethod == QueryableMethods.LastOrDefaultWithoutPredicate: shapedQueryExpression.ResultCardinality = ResultCardinality.SingleOrDefault; return CheckTranslated(TranslateLastOrDefault(shapedQueryExpression, null, methodCallExpression.Type, true)); case nameof(Queryable.LastOrDefault) - when genericMethod == QueryableMethods.LastOrDefaultWithPredicate: + when genericMethod == QueryableMethods.LastOrDefaultWithPredicate: shapedQueryExpression.ResultCardinality = ResultCardinality.SingleOrDefault; - return CheckTranslated(TranslateLastOrDefault(shapedQueryExpression, GetLambdaExpressionFromArgument(1), methodCallExpression.Type, true)); + return CheckTranslated( + TranslateLastOrDefault( + shapedQueryExpression, GetLambdaExpressionFromArgument(1), methodCallExpression.Type, true)); case nameof(Queryable.LongCount) - when genericMethod == QueryableMethods.LongCountWithoutPredicate: + when genericMethod == QueryableMethods.LongCountWithoutPredicate: shapedQueryExpression.ResultCardinality = ResultCardinality.Single; return CheckTranslated(TranslateLongCount(shapedQueryExpression, null)); case nameof(Queryable.LongCount) - when genericMethod == QueryableMethods.LongCountWithPredicate: + when genericMethod == QueryableMethods.LongCountWithPredicate: shapedQueryExpression.ResultCardinality = ResultCardinality.Single; return CheckTranslated(TranslateLongCount(shapedQueryExpression, GetLambdaExpressionFromArgument(1))); case nameof(Queryable.Max) - when genericMethod == QueryableMethods.MaxWithoutSelector: + when genericMethod == QueryableMethods.MaxWithoutSelector: shapedQueryExpression.ResultCardinality = ResultCardinality.Single; return CheckTranslated(TranslateMax(shapedQueryExpression, null, methodCallExpression.Type)); case nameof(Queryable.Max) - when genericMethod == QueryableMethods.MaxWithSelector: + when genericMethod == QueryableMethods.MaxWithSelector: shapedQueryExpression.ResultCardinality = ResultCardinality.Single; - return CheckTranslated(TranslateMax(shapedQueryExpression, GetLambdaExpressionFromArgument(1), methodCallExpression.Type)); + return CheckTranslated( + TranslateMax(shapedQueryExpression, GetLambdaExpressionFromArgument(1), methodCallExpression.Type)); case nameof(Queryable.Min) - when genericMethod == QueryableMethods.MinWithoutSelector: + when genericMethod == QueryableMethods.MinWithoutSelector: shapedQueryExpression.ResultCardinality = ResultCardinality.Single; return CheckTranslated(TranslateMin(shapedQueryExpression, null, methodCallExpression.Type)); case nameof(Queryable.Min) - when genericMethod == QueryableMethods.MinWithSelector: + when genericMethod == QueryableMethods.MinWithSelector: shapedQueryExpression.ResultCardinality = ResultCardinality.Single; - return CheckTranslated(TranslateMin(shapedQueryExpression, GetLambdaExpressionFromArgument(1), methodCallExpression.Type)); + return CheckTranslated( + TranslateMin(shapedQueryExpression, GetLambdaExpressionFromArgument(1), methodCallExpression.Type)); case nameof(Queryable.OfType) - when genericMethod == QueryableMethods.OfType: + when genericMethod == QueryableMethods.OfType: return CheckTranslated(TranslateOfType(shapedQueryExpression, method.GetGenericArguments()[0])); case nameof(Queryable.OrderBy) - when genericMethod == QueryableMethods.OrderBy: + when genericMethod == QueryableMethods.OrderBy: return CheckTranslated(TranslateOrderBy(shapedQueryExpression, GetLambdaExpressionFromArgument(1), true)); case nameof(Queryable.OrderByDescending) - when genericMethod == QueryableMethods.OrderByDescending: + when genericMethod == QueryableMethods.OrderByDescending: return CheckTranslated(TranslateOrderBy(shapedQueryExpression, GetLambdaExpressionFromArgument(1), false)); case nameof(Queryable.Reverse) - when genericMethod == QueryableMethods.Reverse: + when genericMethod == QueryableMethods.Reverse: return CheckTranslated(TranslateReverse(shapedQueryExpression)); case nameof(Queryable.Select) - when genericMethod == QueryableMethods.Select: + when genericMethod == QueryableMethods.Select: return CheckTranslated(TranslateSelect(shapedQueryExpression, GetLambdaExpressionFromArgument(1))); case nameof(Queryable.SelectMany) - when genericMethod == QueryableMethods.SelectManyWithoutCollectionSelector: + when genericMethod == QueryableMethods.SelectManyWithoutCollectionSelector: return CheckTranslated(TranslateSelectMany(shapedQueryExpression, GetLambdaExpressionFromArgument(1))); case nameof(Queryable.SelectMany) - when genericMethod == QueryableMethods.SelectManyWithCollectionSelector: - return CheckTranslated(TranslateSelectMany(shapedQueryExpression, GetLambdaExpressionFromArgument(1), GetLambdaExpressionFromArgument(2))); + when genericMethod == QueryableMethods.SelectManyWithCollectionSelector: + return CheckTranslated( + TranslateSelectMany( + shapedQueryExpression, GetLambdaExpressionFromArgument(1), GetLambdaExpressionFromArgument(2))); case nameof(Queryable.Single) - when genericMethod == QueryableMethods.SingleWithoutPredicate: + when genericMethod == QueryableMethods.SingleWithoutPredicate: shapedQueryExpression.ResultCardinality = ResultCardinality.Single; return CheckTranslated(TranslateSingleOrDefault(shapedQueryExpression, null, methodCallExpression.Type, false)); case nameof(Queryable.Single) - when genericMethod == QueryableMethods.SingleWithPredicate: + when genericMethod == QueryableMethods.SingleWithPredicate: shapedQueryExpression.ResultCardinality = ResultCardinality.Single; - return CheckTranslated(TranslateSingleOrDefault(shapedQueryExpression, GetLambdaExpressionFromArgument(1), methodCallExpression.Type, false)); + return CheckTranslated( + TranslateSingleOrDefault( + shapedQueryExpression, GetLambdaExpressionFromArgument(1), methodCallExpression.Type, false)); case nameof(Queryable.SingleOrDefault) - when genericMethod == QueryableMethods.SingleOrDefaultWithoutPredicate: + when genericMethod == QueryableMethods.SingleOrDefaultWithoutPredicate: shapedQueryExpression.ResultCardinality = ResultCardinality.SingleOrDefault; return CheckTranslated(TranslateSingleOrDefault(shapedQueryExpression, null, methodCallExpression.Type, true)); case nameof(Queryable.SingleOrDefault) - when genericMethod == QueryableMethods.SingleOrDefaultWithPredicate: + when genericMethod == QueryableMethods.SingleOrDefaultWithPredicate: shapedQueryExpression.ResultCardinality = ResultCardinality.SingleOrDefault; - return CheckTranslated(TranslateSingleOrDefault(shapedQueryExpression, GetLambdaExpressionFromArgument(1), methodCallExpression.Type, true)); + return CheckTranslated( + TranslateSingleOrDefault( + shapedQueryExpression, GetLambdaExpressionFromArgument(1), methodCallExpression.Type, true)); case nameof(Queryable.Skip) - when genericMethod == QueryableMethods.Skip: + when genericMethod == QueryableMethods.Skip: return CheckTranslated(TranslateSkip(shapedQueryExpression, methodCallExpression.Arguments[1])); case nameof(Queryable.SkipWhile) - when genericMethod == QueryableMethods.SkipWhile: + when genericMethod == QueryableMethods.SkipWhile: return CheckTranslated(TranslateSkipWhile(shapedQueryExpression, GetLambdaExpressionFromArgument(1))); case nameof(Queryable.Sum) - when QueryableMethods.IsSumWithoutSelector(method): + when QueryableMethods.IsSumWithoutSelector(method): shapedQueryExpression.ResultCardinality = ResultCardinality.Single; return CheckTranslated(TranslateSum(shapedQueryExpression, null, methodCallExpression.Type)); case nameof(Queryable.Sum) - when QueryableMethods.IsSumWithSelector(method): + when QueryableMethods.IsSumWithSelector(method): shapedQueryExpression.ResultCardinality = ResultCardinality.Single; - return CheckTranslated(TranslateSum(shapedQueryExpression, GetLambdaExpressionFromArgument(1), methodCallExpression.Type)); + return CheckTranslated( + TranslateSum(shapedQueryExpression, GetLambdaExpressionFromArgument(1), methodCallExpression.Type)); case nameof(Queryable.Take) - when genericMethod == QueryableMethods.Take: + when genericMethod == QueryableMethods.Take: return CheckTranslated(TranslateTake(shapedQueryExpression, methodCallExpression.Arguments[1])); case nameof(Queryable.TakeWhile) - when genericMethod == QueryableMethods.TakeWhile: + when genericMethod == QueryableMethods.TakeWhile: return CheckTranslated(TranslateTakeWhile(shapedQueryExpression, GetLambdaExpressionFromArgument(1))); case nameof(Queryable.ThenBy) - when genericMethod == QueryableMethods.ThenBy: + when genericMethod == QueryableMethods.ThenBy: return CheckTranslated(TranslateThenBy(shapedQueryExpression, GetLambdaExpressionFromArgument(1), true)); case nameof(Queryable.ThenByDescending) - when genericMethod == QueryableMethods.ThenByDescending: + when genericMethod == QueryableMethods.ThenByDescending: return CheckTranslated(TranslateThenBy(shapedQueryExpression, GetLambdaExpressionFromArgument(1), false)); case nameof(Queryable.Union) - when genericMethod == QueryableMethods.Union: + when genericMethod == QueryableMethods.Union: { if (Visit(methodCallExpression.Arguments[1]) is ShapedQueryExpression innerShapedQueryExpression) { return CheckTranslated(TranslateUnion(shapedQueryExpression, innerShapedQueryExpression)); } + break; } case nameof(Queryable.Where) - when genericMethod == QueryableMethods.Where: + when genericMethod == QueryableMethods.Where: return CheckTranslated(TranslateWhere(shapedQueryExpression, GetLambdaExpressionFromArgument(1))); - LambdaExpression GetLambdaExpressionFromArgument(int argumentIndex) => methodCallExpression.Arguments[argumentIndex].UnwrapLambdaFromQuote(); + LambdaExpression GetLambdaExpressionFromArgument(int argumentIndex) => + methodCallExpression.Arguments[argumentIndex].UnwrapLambdaFromQuote(); } } } @@ -422,10 +465,8 @@ protected virtual ShapedQueryExpression TranslateResultSelectorForJoin( var replacement2 = AccessInnerTransparentField(transparentIdentifierType, transparentIdentifierParameter); var newResultSelector = Expression.Lambda( new ReplacingExpressionVisitor( - new Dictionary { - { original1, replacement1 }, - { original2, replacement2 } - }).Visit(resultSelector.Body), + new Dictionary { { original1, replacement1 }, { original2, replacement2 } }) + .Visit(resultSelector.Body), transparentIdentifierParameter); return TranslateSelect(outer, newResultSelector); @@ -444,8 +485,7 @@ private Expression CombineShapers( return Expression.New( transparentIdentifierType.GetTypeInfo().DeclaredConstructors.Single(), - new[] { outerShaper, innerShaper }, - new[] { outerMemberInfo, innerMemberInfo }); + new[] { outerShaper, innerShaper }, outerMemberInfo, innerMemberInfo); } private class MemberAccessShiftingExpressionVisitor : ExpressionVisitor @@ -506,31 +546,63 @@ public virtual ShapedQueryExpression TranslateSubquery(Expression expression) protected abstract ShapedQueryExpression TranslateCount(ShapedQueryExpression source, LambdaExpression predicate); protected abstract ShapedQueryExpression TranslateDefaultIfEmpty(ShapedQueryExpression source, Expression defaultValue); protected abstract ShapedQueryExpression TranslateDistinct(ShapedQueryExpression source); - protected abstract ShapedQueryExpression TranslateElementAtOrDefault(ShapedQueryExpression source, Expression index, bool returnDefault); + + protected abstract ShapedQueryExpression TranslateElementAtOrDefault( + ShapedQueryExpression source, Expression index, bool returnDefault); + protected abstract ShapedQueryExpression TranslateExcept(ShapedQueryExpression source1, ShapedQueryExpression source2); - protected abstract ShapedQueryExpression TranslateFirstOrDefault(ShapedQueryExpression source, LambdaExpression predicate, Type returnType, bool returnDefault); - protected abstract ShapedQueryExpression TranslateGroupBy(ShapedQueryExpression source, LambdaExpression keySelector, LambdaExpression elementSelector, LambdaExpression resultSelector); - protected abstract ShapedQueryExpression TranslateGroupJoin(ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, LambdaExpression resultSelector); + + protected abstract ShapedQueryExpression TranslateFirstOrDefault( + ShapedQueryExpression source, LambdaExpression predicate, Type returnType, bool returnDefault); + + protected abstract ShapedQueryExpression TranslateGroupBy( + ShapedQueryExpression source, LambdaExpression keySelector, LambdaExpression elementSelector, LambdaExpression resultSelector); + + protected abstract ShapedQueryExpression TranslateGroupJoin( + ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, + LambdaExpression resultSelector); + protected abstract ShapedQueryExpression TranslateIntersect(ShapedQueryExpression source1, ShapedQueryExpression source2); - protected abstract ShapedQueryExpression TranslateJoin(ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, LambdaExpression resultSelector); - protected abstract ShapedQueryExpression TranslateLeftJoin(ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, LambdaExpression resultSelector); - protected abstract ShapedQueryExpression TranslateLastOrDefault(ShapedQueryExpression source, LambdaExpression predicate, Type returnType, bool returnDefault); + + protected abstract ShapedQueryExpression TranslateJoin( + ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, + LambdaExpression resultSelector); + + protected abstract ShapedQueryExpression TranslateLeftJoin( + ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, + LambdaExpression resultSelector); + + protected abstract ShapedQueryExpression TranslateLastOrDefault( + ShapedQueryExpression source, LambdaExpression predicate, Type returnType, bool returnDefault); + protected abstract ShapedQueryExpression TranslateLongCount(ShapedQueryExpression source, LambdaExpression predicate); protected abstract ShapedQueryExpression TranslateMax(ShapedQueryExpression source, LambdaExpression selector, Type resultType); protected abstract ShapedQueryExpression TranslateMin(ShapedQueryExpression source, LambdaExpression selector, Type resultType); protected abstract ShapedQueryExpression TranslateOfType(ShapedQueryExpression source, Type resultType); - protected abstract ShapedQueryExpression TranslateOrderBy(ShapedQueryExpression source, LambdaExpression keySelector, bool ascending); + + protected abstract ShapedQueryExpression TranslateOrderBy( + ShapedQueryExpression source, LambdaExpression keySelector, bool ascending); + protected abstract ShapedQueryExpression TranslateReverse(ShapedQueryExpression source); protected abstract ShapedQueryExpression TranslateSelect(ShapedQueryExpression source, LambdaExpression selector); - protected abstract ShapedQueryExpression TranslateSelectMany(ShapedQueryExpression source, LambdaExpression collectionSelector, LambdaExpression resultSelector); + + protected abstract ShapedQueryExpression TranslateSelectMany( + ShapedQueryExpression source, LambdaExpression collectionSelector, LambdaExpression resultSelector); + protected abstract ShapedQueryExpression TranslateSelectMany(ShapedQueryExpression source, LambdaExpression selector); - protected abstract ShapedQueryExpression TranslateSingleOrDefault(ShapedQueryExpression source, LambdaExpression predicate, Type returnType, bool returnDefault); + + protected abstract ShapedQueryExpression TranslateSingleOrDefault( + ShapedQueryExpression source, LambdaExpression predicate, Type returnType, bool returnDefault); + protected abstract ShapedQueryExpression TranslateSkip(ShapedQueryExpression source, Expression count); protected abstract ShapedQueryExpression TranslateSkipWhile(ShapedQueryExpression source, LambdaExpression predicate); protected abstract ShapedQueryExpression TranslateSum(ShapedQueryExpression source, LambdaExpression selector, Type resultType); protected abstract ShapedQueryExpression TranslateTake(ShapedQueryExpression source, Expression count); protected abstract ShapedQueryExpression TranslateTakeWhile(ShapedQueryExpression source, LambdaExpression predicate); - protected abstract ShapedQueryExpression TranslateThenBy(ShapedQueryExpression source, LambdaExpression keySelector, bool ascending); + + protected abstract ShapedQueryExpression TranslateThenBy( + ShapedQueryExpression source, LambdaExpression keySelector, bool ascending); + protected abstract ShapedQueryExpression TranslateUnion(ShapedQueryExpression source1, ShapedQueryExpression source2); protected abstract ShapedQueryExpression TranslateWhere(ShapedQueryExpression source, LambdaExpression predicate); } diff --git a/src/EFCore/Query/QueryableMethodTranslatingExpressionVisitorDependencies.cs b/src/EFCore/Query/QueryableMethodTranslatingExpressionVisitorDependencies.cs index 68a8ef44455..ed92c797b8f 100644 --- a/src/EFCore/Query/QueryableMethodTranslatingExpressionVisitorDependencies.cs +++ b/src/EFCore/Query/QueryableMethodTranslatingExpressionVisitorDependencies.cs @@ -23,9 +23,9 @@ namespace Microsoft.EntityFrameworkCore.Query /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public sealed class QueryableMethodTranslatingExpressionVisitorDependencies diff --git a/src/EFCore/Query/QueryableMethods.cs b/src/EFCore/Query/QueryableMethods.cs index 75e9e2bdefd..799bb6a1006 100644 --- a/src/EFCore/Query/QueryableMethods.cs +++ b/src/EFCore/Query/QueryableMethods.cs @@ -1,9 +1,8 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.Linq; using System.Linq.Expressions; using System.Reflection; @@ -77,11 +76,14 @@ public static class QueryableMethods public static bool IsSumWithoutSelector(MethodInfo methodInfo) => SumWithoutSelectorMethods.Values.Contains(methodInfo); + public static bool IsSumWithSelector(MethodInfo methodInfo) => methodInfo.IsGenericMethod && SumWithSelectorMethods.Values.Contains(methodInfo.GetGenericMethodDefinition()); + public static bool IsAverageWithoutSelector(MethodInfo methodInfo) => AverageWithoutSelectorMethods.Values.Contains(methodInfo); + public static bool IsAverageWithSelector(MethodInfo methodInfo) => methodInfo.IsGenericMethod && AverageWithSelectorMethods.Values.Contains(methodInfo.GetGenericMethodDefinition()); @@ -115,11 +117,13 @@ static QueryableMethods() mi => mi.Name == nameof(Queryable.OfType) && mi.GetParameters().Length == 1); All = queryableMethods.Single( - mi => mi.Name == nameof(Queryable.All) && mi.GetParameters().Length == 2 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); + mi => mi.Name == nameof(Queryable.All) && mi.GetParameters().Length == 2 + && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); AnyWithoutPredicate = queryableMethods.Single( mi => mi.Name == nameof(Queryable.Any) && mi.GetParameters().Length == 1); AnyWithPredicate = queryableMethods.Single( - mi => mi.Name == nameof(Queryable.Any) && mi.GetParameters().Length == 2 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); + mi => mi.Name == nameof(Queryable.Any) && mi.GetParameters().Length == 2 + && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); Contains = queryableMethods.Single( mi => mi.Name == nameof(Queryable.Contains) && mi.GetParameters().Length == 2); @@ -135,17 +139,21 @@ static QueryableMethods() CountWithoutPredicate = queryableMethods.Single( mi => mi.Name == nameof(Queryable.Count) && mi.GetParameters().Length == 1); CountWithPredicate = queryableMethods.Single( - mi => mi.Name == nameof(Queryable.Count) && mi.GetParameters().Length == 2 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); + mi => mi.Name == nameof(Queryable.Count) && mi.GetParameters().Length == 2 + && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); LongCountWithoutPredicate = queryableMethods.Single( mi => mi.Name == nameof(Queryable.LongCount) && mi.GetParameters().Length == 1); LongCountWithPredicate = queryableMethods.Single( - mi => mi.Name == nameof(Queryable.LongCount) && mi.GetParameters().Length == 2 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); + mi => mi.Name == nameof(Queryable.LongCount) && mi.GetParameters().Length == 2 + && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); MinWithSelector = queryableMethods.Single( - mi => mi.Name == nameof(Queryable.Min) && mi.GetParameters().Length == 2 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); + mi => mi.Name == nameof(Queryable.Min) && mi.GetParameters().Length == 2 + && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); MinWithoutSelector = queryableMethods.Single( mi => mi.Name == nameof(Queryable.Min) && mi.GetParameters().Length == 1); MaxWithSelector = queryableMethods.Single( - mi => mi.Name == nameof(Queryable.Max) && mi.GetParameters().Length == 2 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); + mi => mi.Name == nameof(Queryable.Max) && mi.GetParameters().Length == 2 + && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); MaxWithoutSelector = queryableMethods.Single( mi => mi.Name == nameof(Queryable.Max) && mi.GetParameters().Length == 1); @@ -156,52 +164,66 @@ static QueryableMethods() FirstWithoutPredicate = queryableMethods.Single( mi => mi.Name == nameof(Queryable.First) && mi.GetParameters().Length == 1); FirstWithPredicate = queryableMethods.Single( - mi => mi.Name == nameof(Queryable.First) && mi.GetParameters().Length == 2 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); + mi => mi.Name == nameof(Queryable.First) && mi.GetParameters().Length == 2 + && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); FirstOrDefaultWithoutPredicate = queryableMethods.Single( mi => mi.Name == nameof(Queryable.FirstOrDefault) && mi.GetParameters().Length == 1); FirstOrDefaultWithPredicate = queryableMethods.Single( - mi => mi.Name == nameof(Queryable.FirstOrDefault) && mi.GetParameters().Length == 2 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); + mi => mi.Name == nameof(Queryable.FirstOrDefault) && mi.GetParameters().Length == 2 + && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); SingleWithoutPredicate = queryableMethods.Single( mi => mi.Name == nameof(Queryable.Single) && mi.GetParameters().Length == 1); SingleWithPredicate = queryableMethods.Single( - mi => mi.Name == nameof(Queryable.Single) && mi.GetParameters().Length == 2 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); + mi => mi.Name == nameof(Queryable.Single) && mi.GetParameters().Length == 2 + && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); SingleOrDefaultWithoutPredicate = queryableMethods.Single( mi => mi.Name == nameof(Queryable.SingleOrDefault) && mi.GetParameters().Length == 1); SingleOrDefaultWithPredicate = queryableMethods.Single( - mi => mi.Name == nameof(Queryable.SingleOrDefault) && mi.GetParameters().Length == 2 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); + mi => mi.Name == nameof(Queryable.SingleOrDefault) && mi.GetParameters().Length == 2 + && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); LastWithoutPredicate = queryableMethods.Single( mi => mi.Name == nameof(Queryable.Last) && mi.GetParameters().Length == 1); LastWithPredicate = queryableMethods.Single( - mi => mi.Name == nameof(Queryable.Last) && mi.GetParameters().Length == 2 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); + mi => mi.Name == nameof(Queryable.Last) && mi.GetParameters().Length == 2 + && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); LastOrDefaultWithoutPredicate = queryableMethods.Single( mi => mi.Name == nameof(Queryable.LastOrDefault) && mi.GetParameters().Length == 1); LastOrDefaultWithPredicate = queryableMethods.Single( - mi => mi.Name == nameof(Queryable.LastOrDefault) && mi.GetParameters().Length == 2 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); + mi => mi.Name == nameof(Queryable.LastOrDefault) && mi.GetParameters().Length == 2 + && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); Distinct = queryableMethods.Single( mi => mi.Name == nameof(Queryable.Distinct) && mi.GetParameters().Length == 1); Reverse = queryableMethods.Single( mi => mi.Name == nameof(Queryable.Reverse) && mi.GetParameters().Length == 1); Where = queryableMethods.Single( - mi => mi.Name == nameof(Queryable.Where) && mi.GetParameters().Length == 2 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); + mi => mi.Name == nameof(Queryable.Where) && mi.GetParameters().Length == 2 + && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); Select = queryableMethods.Single( - mi => mi.Name == nameof(Queryable.Select) && mi.GetParameters().Length == 2 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); + mi => mi.Name == nameof(Queryable.Select) && mi.GetParameters().Length == 2 + && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); Skip = queryableMethods.Single( mi => mi.Name == nameof(Queryable.Skip) && mi.GetParameters().Length == 2); Take = queryableMethods.Single( mi => mi.Name == nameof(Queryable.Take) && mi.GetParameters().Length == 2); SkipWhile = queryableMethods.Single( - mi => mi.Name == nameof(Queryable.SkipWhile) && mi.GetParameters().Length == 2 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); + mi => mi.Name == nameof(Queryable.SkipWhile) && mi.GetParameters().Length == 2 + && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); TakeWhile = queryableMethods.Single( - mi => mi.Name == nameof(Queryable.TakeWhile) && mi.GetParameters().Length == 2 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); + mi => mi.Name == nameof(Queryable.TakeWhile) && mi.GetParameters().Length == 2 + && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); OrderBy = queryableMethods.Single( - mi => mi.Name == nameof(Queryable.OrderBy) && mi.GetParameters().Length == 2 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); + mi => mi.Name == nameof(Queryable.OrderBy) && mi.GetParameters().Length == 2 + && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); OrderByDescending = queryableMethods.Single( - mi => mi.Name == nameof(Queryable.OrderByDescending) && mi.GetParameters().Length == 2 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); + mi => mi.Name == nameof(Queryable.OrderByDescending) && mi.GetParameters().Length == 2 + && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); ThenBy = queryableMethods.Single( - mi => mi.Name == nameof(Queryable.ThenBy) && mi.GetParameters().Length == 2 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); + mi => mi.Name == nameof(Queryable.ThenBy) && mi.GetParameters().Length == 2 + && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); ThenByDescending = queryableMethods.Single( - mi => mi.Name == nameof(Queryable.ThenByDescending) && mi.GetParameters().Length == 2 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); + mi => mi.Name == nameof(Queryable.ThenByDescending) && mi.GetParameters().Length == 2 + && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); DefaultIfEmptyWithoutArgument = queryableMethods.Single( mi => mi.Name == nameof(Queryable.DefaultIfEmpty) && mi.GetParameters().Length == 1); DefaultIfEmptyWithArgument = queryableMethods.Single( @@ -212,18 +234,28 @@ static QueryableMethods() GroupJoin = queryableMethods.Single( mi => mi.Name == nameof(Queryable.GroupJoin) && mi.GetParameters().Length == 5); SelectManyWithCollectionSelector = queryableMethods.Single( - mi => mi.Name == nameof(Queryable.SelectMany) && mi.GetParameters().Length == 3 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); + mi => mi.Name == nameof(Queryable.SelectMany) && mi.GetParameters().Length == 3 + && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); SelectManyWithoutCollectionSelector = queryableMethods.Single( - mi => mi.Name == nameof(Queryable.SelectMany) && mi.GetParameters().Length == 2 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); + mi => mi.Name == nameof(Queryable.SelectMany) && mi.GetParameters().Length == 2 + && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); GroupByWithKeySelector = queryableMethods.Single( - mi => mi.Name == nameof(Queryable.GroupBy) && mi.GetParameters().Length == 2 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); + mi => mi.Name == nameof(Queryable.GroupBy) && mi.GetParameters().Length == 2 + && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType)); GroupByWithKeyElementSelector = queryableMethods.Single( - mi => mi.Name == nameof(Queryable.GroupBy) && mi.GetParameters().Length == 3 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType) && IsExpressionOfFunc(mi.GetParameters()[2].ParameterType)); + mi => mi.Name == nameof(Queryable.GroupBy) && mi.GetParameters().Length == 3 + && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType) + && IsExpressionOfFunc(mi.GetParameters()[2].ParameterType)); GroupByWithKeyElementResultSelector = queryableMethods.Single( - mi => mi.Name == nameof(Queryable.GroupBy) && mi.GetParameters().Length == 4 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType) && IsExpressionOfFunc(mi.GetParameters()[2].ParameterType) && IsExpressionOfFunc(mi.GetParameters()[3].ParameterType, 3)); + mi => mi.Name == nameof(Queryable.GroupBy) && mi.GetParameters().Length == 4 + && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType) + && IsExpressionOfFunc(mi.GetParameters()[2].ParameterType) && IsExpressionOfFunc( + mi.GetParameters()[3].ParameterType, 3)); GroupByWithKeyResultSelector = queryableMethods.Single( - mi => mi.Name == nameof(Queryable.GroupBy) && mi.GetParameters().Length == 3 && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType) && IsExpressionOfFunc(mi.GetParameters()[2].ParameterType, 3)); + mi => mi.Name == nameof(Queryable.GroupBy) && mi.GetParameters().Length == 3 + && IsExpressionOfFunc(mi.GetParameters()[1].ParameterType) && IsExpressionOfFunc( + mi.GetParameters()[2].ParameterType, 3)); MethodInfo GetSumOrAverageWithoutSelector(string methodName) => queryableMethods.Single( diff --git a/src/EFCore/Query/ReplacingExpressionVisitor.cs b/src/EFCore/Query/ReplacingExpressionVisitor.cs index 4d2c358e305..13cbfc76f76 100644 --- a/src/EFCore/Query/ReplacingExpressionVisitor.cs +++ b/src/EFCore/Query/ReplacingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; diff --git a/src/EFCore/Query/ResultCardinality.cs b/src/EFCore/Query/ResultCardinality.cs index 48e5178c11a..daac39ab443 100644 --- a/src/EFCore/Query/ResultCardinality.cs +++ b/src/EFCore/Query/ResultCardinality.cs @@ -1,5 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + namespace Microsoft.EntityFrameworkCore.Query { public enum ResultCardinality diff --git a/src/EFCore/Query/ShapedQueryCompilingExpressionVisitor.cs b/src/EFCore/Query/ShapedQueryCompilingExpressionVisitor.cs index 7c504e3b764..8904b2a6aba 100644 --- a/src/EFCore/Query/ShapedQueryCompilingExpressionVisitor.cs +++ b/src/EFCore/Query/ShapedQueryCompilingExpressionVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -102,12 +102,12 @@ protected override Expression VisitExtension(Expression extensionExpression) private static readonly MethodInfo _singleAsyncMethodInfo = typeof(ShapedQueryCompilingExpressionVisitor).GetTypeInfo() - .GetDeclaredMethods(nameof(ShapedQueryCompilingExpressionVisitor.SingleAsync)) + .GetDeclaredMethods(nameof(SingleAsync)) .Single(mi => mi.GetParameters().Length == 2); private static readonly MethodInfo _singleOrDefaultAsyncMethodInfo = typeof(ShapedQueryCompilingExpressionVisitor).GetTypeInfo() - .GetDeclaredMethods(nameof(ShapedQueryCompilingExpressionVisitor.SingleOrDefaultAsync)) + .GetDeclaredMethods(nameof(SingleOrDefaultAsync)) .Single(mi => mi.GetParameters().Length == 2); private static async Task SingleAsync( @@ -188,7 +188,7 @@ protected override Expression VisitConstant(ConstantExpression constantExpressio protected override Expression VisitExtension(Expression extensionExpression) { return extensionExpression is EntityShaperExpression - || extensionExpression is ProjectionBindingExpression + || extensionExpression is ProjectionBindingExpression ? extensionExpression : base.VisitExtension(extensionExpression); } @@ -198,23 +198,29 @@ private class EntityMaterializerInjectingExpressionVisitor : ExpressionVisitor { private static readonly ConstructorInfo _materializationContextConstructor = typeof(MaterializationContext).GetConstructors().Single(ci => ci.GetParameters().Length == 2); + private static readonly ConstructorInfo _valueBufferConstructor = typeof(ValueBuffer).GetTypeInfo().DeclaredConstructors.Single(ci => ci.GetParameters().Length == 1); private static readonly PropertyInfo _dbContextMemberInfo = typeof(QueryContext).GetProperty(nameof(QueryContext.Context)); + private static readonly PropertyInfo _stateManagerMemberInfo = typeof(QueryContext).GetProperty(nameof(QueryContext.StateManager)); + private static readonly PropertyInfo _entityMemberInfo = typeof(InternalEntityEntry).GetProperty(nameof(InternalEntityEntry.Entity)); + private static readonly PropertyInfo _entityTypeMemberInfo = typeof(InternalEntityEntry).GetProperty(nameof(InternalEntityEntry.EntityType)); private static readonly MethodInfo _tryGetEntryMethodInfo = typeof(IStateManager).GetTypeInfo().GetDeclaredMethods(nameof(IStateManager.TryGetEntry)) .Single(mi => mi.GetParameters().Length == 4); + private static readonly MethodInfo _startTrackingMethodInfo - = typeof(QueryContext).GetMethod(nameof(QueryContext.StartTracking), new[] { typeof(IEntityType), typeof(object), typeof(ValueBuffer) }); + = typeof(QueryContext).GetMethod( + nameof(QueryContext.StartTracking), new[] { typeof(IEntityType), typeof(object), typeof(ValueBuffer) }); private readonly IEntityMaterializerSource _entityMaterializerSource; private readonly bool _trackQueryResults; @@ -241,7 +247,8 @@ bool containsOwner(IEntityType owner) if (entityType.FindOwnership() is IForeignKey ownership && !containsOwner(ownership.PrincipalEntityType)) { - throw new InvalidOperationException("A tracking query projects owned entity without corresponding owner in result. " + + throw new InvalidOperationException( + "A tracking query projects owned entity without corresponding owner in result. " + "Owned entities cannot be tracked without their owner. " + "Either include the owner entity in the result or make query non-tracking using AsNoTracking()."); } @@ -265,7 +272,8 @@ private Expression ProcessEntityShaper(EntityShaperExpression entityShaperExpres var entityType = entityShaperExpression.EntityType; - var materializationContextVariable = Expression.Variable(typeof(MaterializationContext), + var materializationContextVariable = Expression.Variable( + typeof(MaterializationContext), "materializationContext" + _currentEntityIndex); variables.Add(materializationContextVariable); expressions.Add( @@ -282,15 +290,17 @@ private Expression ProcessEntityShaper(EntityShaperExpression entityShaperExpres var primaryKey = entityType.FindPrimaryKey(); - var concreteEntityTypeVariable = Expression.Variable(typeof(IEntityType), + var concreteEntityTypeVariable = Expression.Variable( + typeof(IEntityType), "entityType" + _currentEntityIndex); variables.Add(concreteEntityTypeVariable); var instanceVariable = Expression.Variable(entityType.ClrType, "instance" + _currentEntityIndex); variables.Add(instanceVariable); - expressions.Add(Expression.Assign( - instanceVariable, - Expression.Constant(null, entityType.ClrType))); + expressions.Add( + Expression.Assign( + instanceVariable, + Expression.Constant(null, entityType.ClrType))); if (_trackQueryResults && primaryKey != null) @@ -312,53 +322,60 @@ private Expression ProcessEntityShaper(EntityShaperExpression entityShaperExpres Expression.NewArrayInit( typeof(object), primaryKey.Properties - .Select(p => _entityMaterializerSource.CreateReadValueExpression( - valueBufferExpression, - typeof(object), - p.GetIndex(), - p))), + .Select( + p => _entityMaterializerSource.CreateReadValueExpression( + valueBufferExpression, + typeof(object), + p.GetIndex(), + p))), Expression.Constant(!entityShaperExpression.IsNullable), hasNullKeyVariable))); - expressions.Add(Expression.IfThen( - Expression.Not(hasNullKeyVariable), - Expression.IfThenElse( - Expression.NotEqual( - entryVariable, - Expression.Constant(default(InternalEntityEntry), typeof(InternalEntityEntry))), - Expression.Block( - Expression.Assign( - concreteEntityTypeVariable, - Expression.MakeMemberAccess(entryVariable, _entityTypeMemberInfo)), - Expression.Assign(instanceVariable, Expression.Convert( - Expression.MakeMemberAccess(entryVariable, _entityMemberInfo), - entityType.ClrType))), - MaterializeEntity( - entityType, materializationContextVariable, concreteEntityTypeVariable, instanceVariable, entryVariable)))); + expressions.Add( + Expression.IfThen( + Expression.Not(hasNullKeyVariable), + Expression.IfThenElse( + Expression.NotEqual( + entryVariable, + Expression.Constant(default(InternalEntityEntry), typeof(InternalEntityEntry))), + Expression.Block( + Expression.Assign( + concreteEntityTypeVariable, + Expression.MakeMemberAccess(entryVariable, _entityTypeMemberInfo)), + Expression.Assign( + instanceVariable, Expression.Convert( + Expression.MakeMemberAccess(entryVariable, _entityMemberInfo), + entityType.ClrType))), + MaterializeEntity( + entityType, materializationContextVariable, concreteEntityTypeVariable, instanceVariable, + entryVariable)))); } else { - expressions.Add(Expression.IfThen( - primaryKey != null - ? primaryKey.Properties.Select(p => - Expression.NotEqual( - _entityMaterializerSource.CreateReadValueExpression( - valueBufferExpression, - typeof(object), - p.GetIndex(), - p), - Expression.Constant(null))) + expressions.Add( + Expression.IfThen( + primaryKey != null + ? primaryKey.Properties.Select( + p => + Expression.NotEqual( + _entityMaterializerSource.CreateReadValueExpression( + valueBufferExpression, + typeof(object), + p.GetIndex(), + p), + Expression.Constant(null))) .Aggregate((a, b) => Expression.AndAlso(a, b)) - : entityType.GetProperties() - .Select(p => - Expression.NotEqual( - _entityMaterializerSource.CreateReadValueExpression( - valueBufferExpression, - typeof(object), - p.GetIndex(), - p), - Expression.Constant(null))) - .Aggregate((a, b) => Expression.OrElse(a, b)), + : entityType.GetProperties() + .Select( + p => + Expression.NotEqual( + _entityMaterializerSource.CreateReadValueExpression( + valueBufferExpression, + typeof(object), + p.GetIndex(), + p), + Expression.Constant(null))) + .Aggregate((a, b) => Expression.OrElse(a, b)), MaterializeEntity( entityType, materializationContextVariable, concreteEntityTypeVariable, instanceVariable, null))); } @@ -377,7 +394,8 @@ private Expression MaterializeEntity( var expressions = new List(); var variables = new List(); - var shadowValuesVariable = Expression.Variable(typeof(ValueBuffer), + var shadowValuesVariable = Expression.Variable( + typeof(ValueBuffer), "shadowValueBuffer" + _currentEntityIndex); variables.Add(shadowValuesVariable); expressions.Add( @@ -398,7 +416,8 @@ private Expression MaterializeEntity( else { var discriminatorProperty = firstEntityType.GetDiscriminatorProperty(); - var discriminatorValueVariable = Expression.Variable(discriminatorProperty.ClrType, "discriminator" + _currentEntityIndex); + var discriminatorValueVariable = Expression.Variable( + discriminatorProperty.ClrType, "discriminator" + _currentEntityIndex); variables.Add(discriminatorValueVariable); expressions.Add( @@ -460,9 +479,9 @@ var discriminatorValue private BlockExpression CreateFullMaterializeExpression( IEntityType concreteEntityType, in (Type ReturnType, - ParameterExpression MaterializationContextVariable, - ParameterExpression ConcreteEntityTypeVariable, - ParameterExpression ShadowValuesVariable) materializeExpressionContext) + ParameterExpression MaterializationContextVariable, + ParameterExpression ConcreteEntityTypeVariable, + ParameterExpression ShadowValuesVariable) materializeExpressionContext) { var (returnType, materializationContextVariable, @@ -470,11 +489,11 @@ private BlockExpression CreateFullMaterializeExpression( shadowValuesVariable) = materializeExpressionContext; var blockExpressions = new List(3) - { - Expression.Assign( - concreteEntityTypeVariable, - Expression.Constant(concreteEntityType)) - }; + { + Expression.Assign( + concreteEntityTypeVariable, + Expression.Constant(concreteEntityType)) + }; var materializer = _entityMaterializerSource .CreateMaterializeExpression(concreteEntityType, "instance", materializationContextVariable); @@ -482,7 +501,8 @@ private BlockExpression CreateFullMaterializeExpression( if (_trackQueryResults && concreteEntityType.ShadowPropertyCount() > 0) { - var valueBufferExpression = Expression.Call(materializationContextVariable, MaterializationContext.GetValueBufferMethod); + var valueBufferExpression = Expression.Call( + materializationContextVariable, MaterializationContext.GetValueBufferMethod); var shadowProperties = concreteEntityType.GetProperties().Where(p => p.IsShadowProperty()); blockExpressions.Add( Expression.Assign( @@ -491,11 +511,12 @@ private BlockExpression CreateFullMaterializeExpression( _valueBufferConstructor, Expression.NewArrayInit( typeof(object), - shadowProperties.Select(p => _entityMaterializerSource.CreateReadValueExpression( - valueBufferExpression, - typeof(object), - p.GetIndex(), - p)))))); + shadowProperties.Select( + p => _entityMaterializerSource.CreateReadValueExpression( + valueBufferExpression, + typeof(object), + p.GetIndex(), + p)))))); } materializer = materializer.Type == returnType diff --git a/src/EFCore/Query/TransparentIdentifierFactory.cs b/src/EFCore/Query/TransparentIdentifierFactory.cs index f8ac3f3da0b..74dc6465a83 100644 --- a/src/EFCore/Query/TransparentIdentifierFactory.cs +++ b/src/EFCore/Query/TransparentIdentifierFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Storage/Database.cs b/src/EFCore/Storage/Database.cs index d2e95de4fa7..90b4ef8eced 100644 --- a/src/EFCore/Storage/Database.cs +++ b/src/EFCore/Storage/Database.cs @@ -23,8 +23,8 @@ namespace Microsoft.EntityFrameworkCore.Storage /// not used in application code. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/Storage/DatabaseDependencies.cs b/src/EFCore/Storage/DatabaseDependencies.cs index d7d21f6a674..28d45a39a00 100644 --- a/src/EFCore/Storage/DatabaseDependencies.cs +++ b/src/EFCore/Storage/DatabaseDependencies.cs @@ -27,8 +27,8 @@ namespace Microsoft.EntityFrameworkCore.Storage /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// @@ -95,7 +95,5 @@ public DatabaseDependencies With([NotNull] IQueryCompilationContextFactory query /// A new parameter object with the given service replaced. public DatabaseDependencies With([NotNull] IUpdateAdapterFactory updateAdapterFactory) => new DatabaseDependencies(QueryCompilationContextFactory, updateAdapterFactory); - - } } diff --git a/src/EFCore/Storage/DatabaseProvider.cs b/src/EFCore/Storage/DatabaseProvider.cs index 5cbad61459e..beb7f879561 100644 --- a/src/EFCore/Storage/DatabaseProvider.cs +++ b/src/EFCore/Storage/DatabaseProvider.cs @@ -19,9 +19,9 @@ namespace Microsoft.EntityFrameworkCore.Storage /// not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// /// diff --git a/src/EFCore/Storage/DatabaseProviderDependencies.cs b/src/EFCore/Storage/DatabaseProviderDependencies.cs index d5180fc3001..d915543a8f5 100644 --- a/src/EFCore/Storage/DatabaseProviderDependencies.cs +++ b/src/EFCore/Storage/DatabaseProviderDependencies.cs @@ -23,10 +23,10 @@ namespace Microsoft.EntityFrameworkCore.Storage /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . - /// This means a single instance of each service is used by many instances. + /// The service lifetime is . + /// This means a single instance of each service is used by many instances. /// The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public sealed class DatabaseProviderDependencies diff --git a/src/EFCore/Storage/ExecutionStrategy.cs b/src/EFCore/Storage/ExecutionStrategy.cs index ff578459740..2ff9ded5f47 100644 --- a/src/EFCore/Storage/ExecutionStrategy.cs +++ b/src/EFCore/Storage/ExecutionStrategy.cs @@ -316,7 +316,8 @@ protected virtual void OnFirstExecution() throw new InvalidOperationException( CoreStrings.ExecutionStrategyExistingTransaction( GetType().Name, - nameof(DbContext) + "." + nameof(DbContext.Database) + "." + nameof(DatabaseFacade.CreateExecutionStrategy) + "()")); + nameof(DbContext) + "." + nameof(DbContext.Database) + "." + nameof(DatabaseFacade.CreateExecutionStrategy) + + "()")); } ExceptionsEncountered.Clear(); diff --git a/src/EFCore/Storage/ExecutionStrategyDependencies.cs b/src/EFCore/Storage/ExecutionStrategyDependencies.cs index b4db0b2c1f8..b9c189e0359 100644 --- a/src/EFCore/Storage/ExecutionStrategyDependencies.cs +++ b/src/EFCore/Storage/ExecutionStrategyDependencies.cs @@ -26,8 +26,8 @@ namespace Microsoft.EntityFrameworkCore.Storage /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/Storage/ExecutionStrategyExtensions.cs b/src/EFCore/Storage/ExecutionStrategyExtensions.cs index 68aa38016c1..9cbcd076c9e 100644 --- a/src/EFCore/Storage/ExecutionStrategyExtensions.cs +++ b/src/EFCore/Storage/ExecutionStrategyExtensions.cs @@ -68,11 +68,7 @@ public static void Execute( Check.NotNull(operation, nameof(operation)); strategy.Execute( - new - { - operation, - state - }, s => + new { operation, state }, s => { s.operation(s.state); return true; @@ -205,11 +201,7 @@ public static Task ExecuteAsync( Check.NotNull(operation, nameof(operation)); return strategy.ExecuteAsync( - new - { - operation, - state - }, async (t, ct) => + new { operation, state }, async (t, ct) => { await t.operation(t.state); return true; @@ -241,11 +233,7 @@ public static Task ExecuteAsync( Check.NotNull(operation, nameof(operation)); return strategy.ExecuteAsync( - new - { - operation, - state - }, async (t, ct) => + new { operation, state }, async (t, ct) => { await t.operation(t.state, ct); return true; @@ -277,11 +265,7 @@ public static Task ExecuteAsync( Check.NotNull(operation, nameof(operation)); return strategy.ExecuteAsync( - new - { - operation, - state - }, (t, ct) => t.operation(t.state), default); + new { operation, state }, (t, ct) => t.operation(t.state), default); } /// diff --git a/src/EFCore/Storage/IDatabase.cs b/src/EFCore/Storage/IDatabase.cs index eb5727c3385..d95f027cec2 100644 --- a/src/EFCore/Storage/IDatabase.cs +++ b/src/EFCore/Storage/IDatabase.cs @@ -22,8 +22,8 @@ namespace Microsoft.EntityFrameworkCore.Storage /// not used in application code. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/Storage/IDatabaseProvider.cs b/src/EFCore/Storage/IDatabaseProvider.cs index 49f0c4b4957..51190d1269e 100644 --- a/src/EFCore/Storage/IDatabaseProvider.cs +++ b/src/EFCore/Storage/IDatabaseProvider.cs @@ -17,9 +17,9 @@ namespace Microsoft.EntityFrameworkCore.Storage /// not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IDatabaseProvider diff --git a/src/EFCore/Storage/IDbContextTransaction.cs b/src/EFCore/Storage/IDbContextTransaction.cs index 8316e2ff9c4..549c30bb471 100644 --- a/src/EFCore/Storage/IDbContextTransaction.cs +++ b/src/EFCore/Storage/IDbContextTransaction.cs @@ -38,14 +38,14 @@ public interface IDbContextTransaction : IDisposable, IAsyncDisposable /// Commits all changes made to the database in the current transaction asynchronously. /// /// The cancellation token. - /// A representing the asynchronous operation. + /// A representing the asynchronous operation. Task CommitAsync(CancellationToken cancellationToken = default); /// /// Discards all changes made to the database in the current transaction asynchronously. /// /// The cancellation token. - /// A representing the asynchronous operation. + /// A representing the asynchronous operation. Task RollbackAsync(CancellationToken cancellationToken = default); } } diff --git a/src/EFCore/Storage/IDbContextTransactionManager.cs b/src/EFCore/Storage/IDbContextTransactionManager.cs index f5fe8f5db64..51759c2a2eb 100644 --- a/src/EFCore/Storage/IDbContextTransactionManager.cs +++ b/src/EFCore/Storage/IDbContextTransactionManager.cs @@ -17,8 +17,8 @@ namespace Microsoft.EntityFrameworkCore.Storage /// not used in application code. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/Storage/IExecutionStrategyFactory.cs b/src/EFCore/Storage/IExecutionStrategyFactory.cs index c50af6a42df..d697fb49187 100644 --- a/src/EFCore/Storage/IExecutionStrategyFactory.cs +++ b/src/EFCore/Storage/IExecutionStrategyFactory.cs @@ -10,8 +10,8 @@ namespace Microsoft.EntityFrameworkCore.Storage /// Factory for instances. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/Storage/ITransactionEnlistmentManager.cs b/src/EFCore/Storage/ITransactionEnlistmentManager.cs index 04122d19199..71517cc5316 100644 --- a/src/EFCore/Storage/ITransactionEnlistmentManager.cs +++ b/src/EFCore/Storage/ITransactionEnlistmentManager.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Transactions; diff --git a/src/EFCore/Storage/ITypeMappingSource.cs b/src/EFCore/Storage/ITypeMappingSource.cs index e1ec12bb50c..f1c8d87ce64 100644 --- a/src/EFCore/Storage/ITypeMappingSource.cs +++ b/src/EFCore/Storage/ITypeMappingSource.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -23,9 +23,9 @@ namespace Microsoft.EntityFrameworkCore.Storage /// not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface ITypeMappingSource diff --git a/src/EFCore/Storage/ITypeMappingSourcePlugin.cs b/src/EFCore/Storage/ITypeMappingSourcePlugin.cs index 164af8e8ca1..7b9c4d7a184 100644 --- a/src/EFCore/Storage/ITypeMappingSourcePlugin.cs +++ b/src/EFCore/Storage/ITypeMappingSourcePlugin.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.Extensions.DependencyInjection; @@ -10,10 +10,10 @@ namespace Microsoft.EntityFrameworkCore.Storage /// Represents a plugin type mapping source. /// /// - /// The service lifetime is and multiple registrations - /// are allowed. This means a single instance of each service is used by many + /// The service lifetime is and multiple registrations + /// are allowed. This means a single instance of each service is used by many /// instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public interface ITypeMappingSourcePlugin diff --git a/src/EFCore/Storage/Internal/ExecutionStrategyFactory.cs b/src/EFCore/Storage/Internal/ExecutionStrategyFactory.cs index ea5f2f72b64..8b291eac179 100644 --- a/src/EFCore/Storage/Internal/ExecutionStrategyFactory.cs +++ b/src/EFCore/Storage/Internal/ExecutionStrategyFactory.cs @@ -15,8 +15,8 @@ namespace Microsoft.EntityFrameworkCore.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/Storage/TypeMappingSource.cs b/src/EFCore/Storage/TypeMappingSource.cs index 01b5c498680..157f8ca4f2b 100644 --- a/src/EFCore/Storage/TypeMappingSource.cs +++ b/src/EFCore/Storage/TypeMappingSource.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -24,9 +24,9 @@ namespace Microsoft.EntityFrameworkCore.Storage /// not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public abstract class TypeMappingSource : TypeMappingSourceBase diff --git a/src/EFCore/Storage/TypeMappingSourceBase.cs b/src/EFCore/Storage/TypeMappingSourceBase.cs index c84b9a8b990..971f6ec17bf 100644 --- a/src/EFCore/Storage/TypeMappingSourceBase.cs +++ b/src/EFCore/Storage/TypeMappingSourceBase.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -21,9 +21,9 @@ namespace Microsoft.EntityFrameworkCore.Storage /// not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public abstract class TypeMappingSourceBase : ITypeMappingSource diff --git a/src/EFCore/Storage/TypeMappingSourceDependencies.cs b/src/EFCore/Storage/TypeMappingSourceDependencies.cs index 7b1431c1f49..24711496590 100644 --- a/src/EFCore/Storage/TypeMappingSourceDependencies.cs +++ b/src/EFCore/Storage/TypeMappingSourceDependencies.cs @@ -27,10 +27,10 @@ namespace Microsoft.EntityFrameworkCore.Storage /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . - /// This means a single instance of each service is used by many instances. + /// The service lifetime is . + /// This means a single instance of each service is used by many instances. /// The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public sealed class TypeMappingSourceDependencies diff --git a/src/EFCore/Storage/ValueBuffer.cs b/src/EFCore/Storage/ValueBuffer.cs index 50c8c2994bb..fa2adabb487 100644 --- a/src/EFCore/Storage/ValueBuffer.cs +++ b/src/EFCore/Storage/ValueBuffer.cs @@ -113,6 +113,7 @@ public override int GetHashCode() { hash.Add(value); } + return hash.ToHashCode(); } } diff --git a/src/EFCore/Storage/ValueConversion/CastingConverter.cs b/src/EFCore/Storage/ValueConversion/CastingConverter.cs index ef84c5550a4..c353991416c 100644 --- a/src/EFCore/Storage/ValueConversion/CastingConverter.cs +++ b/src/EFCore/Storage/ValueConversion/CastingConverter.cs @@ -53,7 +53,8 @@ public CastingConverter([CanBeNull] ConverterMappingHints mappingHints = null) /// A for the default use of this converter. /// public static ValueConverterInfo DefaultInfo { get; } - = new ValueConverterInfo(typeof(TModel), typeof(TProvider), i => new CastingConverter(i.MappingHints), _defaultHints); + = new ValueConverterInfo( + typeof(TModel), typeof(TProvider), i => new CastingConverter(i.MappingHints), _defaultHints); private static Expression> Convert() { diff --git a/src/EFCore/Storage/ValueConversion/DateTimeOffsetToBytesConverter.cs b/src/EFCore/Storage/ValueConversion/DateTimeOffsetToBytesConverter.cs index f32b9afc3b3..2b3d09efa75 100644 --- a/src/EFCore/Storage/ValueConversion/DateTimeOffsetToBytesConverter.cs +++ b/src/EFCore/Storage/ValueConversion/DateTimeOffsetToBytesConverter.cs @@ -40,7 +40,8 @@ public DateTimeOffsetToBytesConverter([CanBeNull] ConverterMappingHints mappingH /// A for the default use of this converter. /// public static ValueConverterInfo DefaultInfo { get; } - = new ValueConverterInfo(typeof(DateTimeOffset), typeof(byte[]), i => new DateTimeOffsetToBytesConverter(i.MappingHints), _defaultHints); + = new ValueConverterInfo( + typeof(DateTimeOffset), typeof(byte[]), i => new DateTimeOffsetToBytesConverter(i.MappingHints), _defaultHints); private static byte[] ToBytes(DateTimeOffset value) { diff --git a/src/EFCore/Storage/ValueConversion/DateTimeOffsetToStringConverter.cs b/src/EFCore/Storage/ValueConversion/DateTimeOffsetToStringConverter.cs index 85d2e774f8c..39070010d26 100644 --- a/src/EFCore/Storage/ValueConversion/DateTimeOffsetToStringConverter.cs +++ b/src/EFCore/Storage/ValueConversion/DateTimeOffsetToStringConverter.cs @@ -31,6 +31,7 @@ public DateTimeOffsetToStringConverter([CanBeNull] ConverterMappingHints mapping /// A for the default use of this converter. /// public static ValueConverterInfo DefaultInfo { get; } - = new ValueConverterInfo(typeof(DateTimeOffset), typeof(string), i => new DateTimeOffsetToStringConverter(i.MappingHints), _defaultHints); + = new ValueConverterInfo( + typeof(DateTimeOffset), typeof(string), i => new DateTimeOffsetToStringConverter(i.MappingHints), _defaultHints); } } diff --git a/src/EFCore/Storage/ValueConversion/DefaultValueConverterRegistryDependencies.cs b/src/EFCore/Storage/ValueConversion/DefaultValueConverterRegistryDependencies.cs index d69183aecbd..e9972f72282 100644 --- a/src/EFCore/Storage/ValueConversion/DefaultValueConverterRegistryDependencies.cs +++ b/src/EFCore/Storage/ValueConversion/DefaultValueConverterRegistryDependencies.cs @@ -23,10 +23,10 @@ namespace Microsoft.EntityFrameworkCore.Storage.ValueConversion /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . - /// This means a single instance of each service is used by many instances. + /// The service lifetime is . + /// This means a single instance of each service is used by many instances. /// The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public sealed class ValueConverterSelectorDependencies diff --git a/src/EFCore/Storage/ValueConversion/EnumToNumberConverter.cs b/src/EFCore/Storage/ValueConversion/EnumToNumberConverter.cs index 312bccb9491..efda04d6d05 100644 --- a/src/EFCore/Storage/ValueConversion/EnumToNumberConverter.cs +++ b/src/EFCore/Storage/ValueConversion/EnumToNumberConverter.cs @@ -48,7 +48,8 @@ public EnumToNumberConverter([CanBeNull] ConverterMappingHints mappingHints = nu /// A for the default use of this converter. /// public static ValueConverterInfo DefaultInfo { get; } - = new ValueConverterInfo(typeof(TEnum), typeof(TNumber), i => new EnumToNumberConverter(i.MappingHints), _defaultHints); + = new ValueConverterInfo( + typeof(TEnum), typeof(TNumber), i => new EnumToNumberConverter(i.MappingHints), _defaultHints); private static Expression> ToNumber() { diff --git a/src/EFCore/Storage/ValueConversion/IValueConverterSelector.cs b/src/EFCore/Storage/ValueConversion/IValueConverterSelector.cs index d34caaa2e87..caf9283edac 100644 --- a/src/EFCore/Storage/ValueConversion/IValueConverterSelector.cs +++ b/src/EFCore/Storage/ValueConversion/IValueConverterSelector.cs @@ -15,9 +15,9 @@ namespace Microsoft.EntityFrameworkCore.Storage.ValueConversion /// to a type that the database provider supports. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IValueConverterSelector diff --git a/src/EFCore/Storage/ValueConversion/Internal/StringCharConverter.cs b/src/EFCore/Storage/ValueConversion/Internal/StringCharConverter.cs index bf622dd9321..01020db4621 100644 --- a/src/EFCore/Storage/ValueConversion/Internal/StringCharConverter.cs +++ b/src/EFCore/Storage/ValueConversion/Internal/StringCharConverter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Storage/ValueConversion/Internal/StringDateTimeConverter.cs b/src/EFCore/Storage/ValueConversion/Internal/StringDateTimeConverter.cs index f0bb9f80fd9..5b6dd3a195b 100644 --- a/src/EFCore/Storage/ValueConversion/Internal/StringDateTimeConverter.cs +++ b/src/EFCore/Storage/ValueConversion/Internal/StringDateTimeConverter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Storage/ValueConversion/Internal/StringDateTimeOffsetConverter.cs b/src/EFCore/Storage/ValueConversion/Internal/StringDateTimeOffsetConverter.cs index 9bff063cde9..c8ad2ab3d63 100644 --- a/src/EFCore/Storage/ValueConversion/Internal/StringDateTimeOffsetConverter.cs +++ b/src/EFCore/Storage/ValueConversion/Internal/StringDateTimeOffsetConverter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Storage/ValueConversion/Internal/StringEnumConverter.cs b/src/EFCore/Storage/ValueConversion/Internal/StringEnumConverter.cs index 0162ddbd714..817af01a142 100644 --- a/src/EFCore/Storage/ValueConversion/Internal/StringEnumConverter.cs +++ b/src/EFCore/Storage/ValueConversion/Internal/StringEnumConverter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Storage/ValueConversion/Internal/StringGuidConverter.cs b/src/EFCore/Storage/ValueConversion/Internal/StringGuidConverter.cs index 60e2393e434..2a4b959e104 100644 --- a/src/EFCore/Storage/ValueConversion/Internal/StringGuidConverter.cs +++ b/src/EFCore/Storage/ValueConversion/Internal/StringGuidConverter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Storage/ValueConversion/Internal/StringNumberConverter.cs b/src/EFCore/Storage/ValueConversion/Internal/StringNumberConverter.cs index 6adab3ec739..23d537fdcd8 100644 --- a/src/EFCore/Storage/ValueConversion/Internal/StringNumberConverter.cs +++ b/src/EFCore/Storage/ValueConversion/Internal/StringNumberConverter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Storage/ValueConversion/Internal/StringTimeSpanConverter.cs b/src/EFCore/Storage/ValueConversion/Internal/StringTimeSpanConverter.cs index 9004c65d2c6..8f488b204ec 100644 --- a/src/EFCore/Storage/ValueConversion/Internal/StringTimeSpanConverter.cs +++ b/src/EFCore/Storage/ValueConversion/Internal/StringTimeSpanConverter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Storage/ValueConversion/Internal/StringUriConverter.cs b/src/EFCore/Storage/ValueConversion/Internal/StringUriConverter.cs index 2f2fdebf2a4..65ec1291d92 100644 --- a/src/EFCore/Storage/ValueConversion/Internal/StringUriConverter.cs +++ b/src/EFCore/Storage/ValueConversion/Internal/StringUriConverter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -49,6 +49,7 @@ protected static Expression> ToUri() private static Uri ConvertToUri(string value) => Uri.TryCreate(value, UriKind.RelativeOrAbsolute, out var result) - ? result : default; + ? result + : default; } } diff --git a/src/EFCore/Storage/ValueConversion/NumberToBytesConverter.cs b/src/EFCore/Storage/ValueConversion/NumberToBytesConverter.cs index ef603e4c361..008ae4e6fa4 100644 --- a/src/EFCore/Storage/ValueConversion/NumberToBytesConverter.cs +++ b/src/EFCore/Storage/ValueConversion/NumberToBytesConverter.cs @@ -41,7 +41,8 @@ public NumberToBytesConverter([CanBeNull] ConverterMappingHints mappingHints = n /// A for the default use of this converter. /// public static ValueConverterInfo DefaultInfo { get; } - = new ValueConverterInfo(typeof(TNumber), typeof(byte[]), i => new NumberToBytesConverter(i.MappingHints), _defaultHints); + = new ValueConverterInfo( + typeof(TNumber), typeof(byte[]), i => new NumberToBytesConverter(i.MappingHints), _defaultHints); private static Expression> ToBytes() { diff --git a/src/EFCore/Storage/ValueConversion/NumberToStringConverter.cs b/src/EFCore/Storage/ValueConversion/NumberToStringConverter.cs index ab0cb24f0a2..2dd5200a464 100644 --- a/src/EFCore/Storage/ValueConversion/NumberToStringConverter.cs +++ b/src/EFCore/Storage/ValueConversion/NumberToStringConverter.cs @@ -31,6 +31,7 @@ public NumberToStringConverter( /// A for the default use of this converter. /// public static ValueConverterInfo DefaultInfo { get; } - = new ValueConverterInfo(typeof(TNumber), typeof(string), i => new NumberToStringConverter(i.MappingHints), _defaultHints); + = new ValueConverterInfo( + typeof(TNumber), typeof(string), i => new NumberToStringConverter(i.MappingHints), _defaultHints); } } diff --git a/src/EFCore/Storage/ValueConversion/StringToBoolConverter.cs b/src/EFCore/Storage/ValueConversion/StringToBoolConverter.cs index 3d935f82ec0..17e5e5c9eab 100644 --- a/src/EFCore/Storage/ValueConversion/StringToBoolConverter.cs +++ b/src/EFCore/Storage/ValueConversion/StringToBoolConverter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Storage/ValueConversion/StringToCharConverter.cs b/src/EFCore/Storage/ValueConversion/StringToCharConverter.cs index a7b2b64c4fc..2b7676ef31e 100644 --- a/src/EFCore/Storage/ValueConversion/StringToCharConverter.cs +++ b/src/EFCore/Storage/ValueConversion/StringToCharConverter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore/Storage/ValueConversion/StringToDateTimeConverter.cs b/src/EFCore/Storage/ValueConversion/StringToDateTimeConverter.cs index e59c6903136..557a8b744de 100644 --- a/src/EFCore/Storage/ValueConversion/StringToDateTimeConverter.cs +++ b/src/EFCore/Storage/ValueConversion/StringToDateTimeConverter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Storage/ValueConversion/StringToDateTimeOffsetConverter.cs b/src/EFCore/Storage/ValueConversion/StringToDateTimeOffsetConverter.cs index 563fec5c951..9e3ced83248 100644 --- a/src/EFCore/Storage/ValueConversion/StringToDateTimeOffsetConverter.cs +++ b/src/EFCore/Storage/ValueConversion/StringToDateTimeOffsetConverter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -32,6 +32,7 @@ public StringToDateTimeOffsetConverter( /// A for the default use of this converter. /// public static ValueConverterInfo DefaultInfo { get; } - = new ValueConverterInfo(typeof(string), typeof(DateTimeOffset), i => new StringToDateTimeOffsetConverter(i.MappingHints), _defaultHints); + = new ValueConverterInfo( + typeof(string), typeof(DateTimeOffset), i => new StringToDateTimeOffsetConverter(i.MappingHints), _defaultHints); } } diff --git a/src/EFCore/Storage/ValueConversion/StringToEnumConverter.cs b/src/EFCore/Storage/ValueConversion/StringToEnumConverter.cs index d612ed241a4..2b57412a8b8 100644 --- a/src/EFCore/Storage/ValueConversion/StringToEnumConverter.cs +++ b/src/EFCore/Storage/ValueConversion/StringToEnumConverter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; diff --git a/src/EFCore/Storage/ValueConversion/StringToGuidConverter.cs b/src/EFCore/Storage/ValueConversion/StringToGuidConverter.cs index a2f017eeb99..4f6a86da6a0 100644 --- a/src/EFCore/Storage/ValueConversion/StringToGuidConverter.cs +++ b/src/EFCore/Storage/ValueConversion/StringToGuidConverter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Storage/ValueConversion/StringToNumberConverter.cs b/src/EFCore/Storage/ValueConversion/StringToNumberConverter.cs index f79d587b2da..25ca9fb5613 100644 --- a/src/EFCore/Storage/ValueConversion/StringToNumberConverter.cs +++ b/src/EFCore/Storage/ValueConversion/StringToNumberConverter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; @@ -31,6 +31,7 @@ public StringToNumberConverter( /// A for the default use of this converter. /// public static ValueConverterInfo DefaultInfo { get; } - = new ValueConverterInfo(typeof(string), typeof(TNumber), i => new StringToNumberConverter(i.MappingHints), _defaultHints); + = new ValueConverterInfo( + typeof(string), typeof(TNumber), i => new StringToNumberConverter(i.MappingHints), _defaultHints); } } diff --git a/src/EFCore/Storage/ValueConversion/StringToTimeSpanConverter.cs b/src/EFCore/Storage/ValueConversion/StringToTimeSpanConverter.cs index ae3a1452f2e..62a0ded7146 100644 --- a/src/EFCore/Storage/ValueConversion/StringToTimeSpanConverter.cs +++ b/src/EFCore/Storage/ValueConversion/StringToTimeSpanConverter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Storage/ValueConversion/StringToUriConverter.cs b/src/EFCore/Storage/ValueConversion/StringToUriConverter.cs index 538f18f4491..6c7ef8dc337 100644 --- a/src/EFCore/Storage/ValueConversion/StringToUriConverter.cs +++ b/src/EFCore/Storage/ValueConversion/StringToUriConverter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/Storage/ValueConversion/ValueConverterSelector.cs b/src/EFCore/Storage/ValueConversion/ValueConverterSelector.cs index b69b3006a24..481d8f026d9 100644 --- a/src/EFCore/Storage/ValueConversion/ValueConverterSelector.cs +++ b/src/EFCore/Storage/ValueConversion/ValueConverterSelector.cs @@ -19,9 +19,9 @@ namespace Microsoft.EntityFrameworkCore.Storage.ValueConversion /// to a type that the database provider supports. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class ValueConverterSelector : IValueConverterSelector @@ -31,13 +31,32 @@ public class ValueConverterSelector : IValueConverterSelector private static readonly Type[] _signedPreferred = { typeof(sbyte), typeof(short), typeof(int), typeof(long), typeof(decimal) }; - private static readonly Type[] _unsignedPreferred = { typeof(byte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(decimal) }; + private static readonly Type[] _unsignedPreferred = + { + typeof(byte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(decimal) + }; private static readonly Type[] _floatingPreferred = { typeof(float), typeof(double), typeof(decimal) }; - private static readonly Type[] _charPreferred = { typeof(char), typeof(int), typeof(ushort), typeof(uint), typeof(long), typeof(ulong), typeof(decimal) }; + private static readonly Type[] _charPreferred = + { + typeof(char), typeof(int), typeof(ushort), typeof(uint), typeof(long), typeof(ulong), typeof(decimal) + }; - private static readonly Type[] _numerics = { typeof(int), typeof(long), typeof(short), typeof(byte), typeof(ulong), typeof(uint), typeof(ushort), typeof(sbyte), typeof(decimal), typeof(double), typeof(float) }; + private static readonly Type[] _numerics = + { + typeof(int), + typeof(long), + typeof(short), + typeof(byte), + typeof(ulong), + typeof(uint), + typeof(ushort), + typeof(sbyte), + typeof(decimal), + typeof(double), + typeof(float) + }; /// /// Initializes a new instance of the class. @@ -397,10 +416,7 @@ private IEnumerable FindNumericConventions( Type converterType, Func> afterPreferred) { - var usedTypes = new List - { - modelType - }; // List not hash because few members + var usedTypes = new List { modelType }; // List not hash because few members var underlyingModelType = modelType.UnwrapEnumType(); if (modelType.IsEnum) diff --git a/src/EFCore/Update/IUpdateAdapter.cs b/src/EFCore/Update/IUpdateAdapter.cs index 8d2f4958bbe..1b2a6f77f09 100644 --- a/src/EFCore/Update/IUpdateAdapter.cs +++ b/src/EFCore/Update/IUpdateAdapter.cs @@ -12,7 +12,7 @@ namespace Microsoft.EntityFrameworkCore.Update /// /// /// Providers tracking capabilities for seed data stored in the model using - /// . + /// . /// /// /// This interface is typically used by database providers (and other extensions). It is generally @@ -75,12 +75,12 @@ public interface IUpdateAdapter IUpdateEntry TryGetEntry([NotNull] IKey key, [NotNull] object[] keyValues); /// - /// All the entries currently being tracked. + /// All the entries currently being tracked. /// IEnumerable Entries { get; } /// - /// Causes the underlying tracker to detect changes made to the tracked entities. + /// Causes the underlying tracker to detect changes made to the tracked entities. /// void DetectChanges(); @@ -96,8 +96,8 @@ public interface IUpdateAdapter /// to manually force the deletes to have at a time controlled by the application. /// /// - /// If is true then this method - /// will call . + /// If is true then this method + /// will call . /// /// void CascadeChanges(); diff --git a/src/EFCore/Update/IUpdateAdapterFactory.cs b/src/EFCore/Update/IUpdateAdapterFactory.cs index 9a5c3e5eff2..313a5a1286e 100644 --- a/src/EFCore/Update/IUpdateAdapterFactory.cs +++ b/src/EFCore/Update/IUpdateAdapterFactory.cs @@ -26,7 +26,7 @@ public interface IUpdateAdapterFactory /// /// - /// Creates a standalone tracker that works with its own and hence will not + /// Creates a standalone tracker that works with its own and hence will not /// impact tracking on the state manager currently in use. /// /// diff --git a/src/EFCore/Update/UpdateEntryExtensions.cs b/src/EFCore/Update/UpdateEntryExtensions.cs index 303aebf69a4..49d82e2c3a3 100644 --- a/src/EFCore/Update/UpdateEntryExtensions.cs +++ b/src/EFCore/Update/UpdateEntryExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/EFCore/ValueGeneration/IValueGeneratorCache.cs b/src/EFCore/ValueGeneration/IValueGeneratorCache.cs index aa1915a29d8..55a6b9ea48d 100644 --- a/src/EFCore/ValueGeneration/IValueGeneratorCache.cs +++ b/src/EFCore/ValueGeneration/IValueGeneratorCache.cs @@ -17,9 +17,9 @@ namespace Microsoft.EntityFrameworkCore.ValueGeneration /// not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public interface IValueGeneratorCache diff --git a/src/EFCore/ValueGeneration/IValueGeneratorSelector.cs b/src/EFCore/ValueGeneration/IValueGeneratorSelector.cs index f4c7a77c4eb..eac5e097d4e 100644 --- a/src/EFCore/ValueGeneration/IValueGeneratorSelector.cs +++ b/src/EFCore/ValueGeneration/IValueGeneratorSelector.cs @@ -16,8 +16,8 @@ namespace Microsoft.EntityFrameworkCore.ValueGeneration /// not used in application code. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/ValueGeneration/ValueGeneratorCache.cs b/src/EFCore/ValueGeneration/ValueGeneratorCache.cs index 7263cc650ec..a67274f2bae 100644 --- a/src/EFCore/ValueGeneration/ValueGeneratorCache.cs +++ b/src/EFCore/ValueGeneration/ValueGeneratorCache.cs @@ -19,9 +19,9 @@ namespace Microsoft.EntityFrameworkCore.ValueGeneration /// not used in application code. /// /// - /// The service lifetime is . This means a single instance - /// is used by many instances. The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// The service lifetime is . This means a single instance + /// is used by many instances. The implementation must be thread-safe. + /// This service cannot depend on services registered as . /// /// public class ValueGeneratorCache : IValueGeneratorCache diff --git a/src/EFCore/ValueGeneration/ValueGeneratorCacheDependencies.cs b/src/EFCore/ValueGeneration/ValueGeneratorCacheDependencies.cs index 0cfdf7ca900..0455b81c24d 100644 --- a/src/EFCore/ValueGeneration/ValueGeneratorCacheDependencies.cs +++ b/src/EFCore/ValueGeneration/ValueGeneratorCacheDependencies.cs @@ -23,10 +23,10 @@ namespace Microsoft.EntityFrameworkCore.ValueGeneration /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . - /// This means a single instance of each service is used by many instances. + /// The service lifetime is . + /// This means a single instance of each service is used by many instances. /// The implementation must be thread-safe. - /// This service cannot depend on services registered as . + /// This service cannot depend on services registered as . /// /// public sealed class ValueGeneratorCacheDependencies diff --git a/src/EFCore/ValueGeneration/ValueGeneratorSelector.cs b/src/EFCore/ValueGeneration/ValueGeneratorSelector.cs index f8cd33eb321..4d3f28ff4e2 100644 --- a/src/EFCore/ValueGeneration/ValueGeneratorSelector.cs +++ b/src/EFCore/ValueGeneration/ValueGeneratorSelector.cs @@ -21,8 +21,8 @@ namespace Microsoft.EntityFrameworkCore.ValueGeneration /// not used in application code. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/EFCore/ValueGeneration/ValueGeneratorSelectorDependencies.cs b/src/EFCore/ValueGeneration/ValueGeneratorSelectorDependencies.cs index 1405c70e881..ec852a9d612 100644 --- a/src/EFCore/ValueGeneration/ValueGeneratorSelectorDependencies.cs +++ b/src/EFCore/ValueGeneration/ValueGeneratorSelectorDependencies.cs @@ -25,8 +25,8 @@ namespace Microsoft.EntityFrameworkCore.ValueGeneration /// services using the 'With...' methods. Do not call the constructor at any point in this process. /// /// - /// The service lifetime is . This means that each - /// instance will use its own instance of this service. + /// The service lifetime is . This means that each + /// instance will use its own instance of this service. /// The implementation may depend on other services registered with any lifetime. /// The implementation does not need to be thread-safe. /// diff --git a/src/Microsoft.Data.Sqlite.Core/Extensions/SQLitePCLExtensions.cs b/src/Microsoft.Data.Sqlite.Core/Extensions/SQLitePCLExtensions.cs index 66233984250..a554689e0ac 100644 --- a/src/Microsoft.Data.Sqlite.Core/Extensions/SQLitePCLExtensions.cs +++ b/src/Microsoft.Data.Sqlite.Core/Extensions/SQLitePCLExtensions.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Reflection; + // ReSharper disable once CheckNamespace namespace SQLitePCL @@ -9,6 +9,6 @@ namespace SQLitePCL internal static class SQLitePCLExtensions { public static bool EncryptionNotSupported() - => SQLitePCL.raw.GetNativeLibraryName() == "e_sqlite3"; + => raw.GetNativeLibraryName() == "e_sqlite3"; } } diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteBlob.cs b/src/Microsoft.Data.Sqlite.Core/SqliteBlob.cs index e8d58b93a8c..8ba905fd21e 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteBlob.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteBlob.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -6,7 +6,6 @@ using System.IO; using Microsoft.Data.Sqlite.Properties; using SQLitePCL; - using static SQLitePCL.raw; namespace Microsoft.Data.Sqlite diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteCacheMode.cs b/src/Microsoft.Data.Sqlite.Core/SqliteCacheMode.cs index f0d18a31c6f..64cc8577593 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteCacheMode.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteCacheMode.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. namespace Microsoft.Data.Sqlite diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteCommand.cs b/src/Microsoft.Data.Sqlite.Core/SqliteCommand.cs index 335a191c8d9..0bc69474f1f 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteCommand.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteCommand.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -11,7 +11,6 @@ using System.Threading.Tasks; using Microsoft.Data.Sqlite.Properties; using SQLitePCL; - using static SQLitePCL.raw; namespace Microsoft.Data.Sqlite diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteConnection.CreateAggregate.cs b/src/Microsoft.Data.Sqlite.Core/SqliteConnection.CreateAggregate.cs index 08f56cca828..f75d0c93ab4 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteConnection.CreateAggregate.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteConnection.CreateAggregate.cs @@ -1,5 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// using System; diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteConnection.CreateAggregate.tt b/src/Microsoft.Data.Sqlite.Core/SqliteConnection.CreateAggregate.tt index 35c670929eb..cc5d6bc87b4 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteConnection.CreateAggregate.tt +++ b/src/Microsoft.Data.Sqlite.Core/SqliteConnection.CreateAggregate.tt @@ -1,8 +1,9 @@ -<#@ assembly name="System.Core" #> +<#@ assembly name="System.Core" #> <#@ import namespace="System.Collections.Generic" #> <#@ import namespace="System.Linq" #> // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// using System; diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteConnection.CreateFunction.cs b/src/Microsoft.Data.Sqlite.Core/SqliteConnection.CreateFunction.cs index 6b39b3c247a..71744bc0b19 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteConnection.CreateFunction.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteConnection.CreateFunction.cs @@ -1,5 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// using System; diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteConnection.CreateFunction.tt b/src/Microsoft.Data.Sqlite.Core/SqliteConnection.CreateFunction.tt index 763b9495ff3..e6a003efa5b 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteConnection.CreateFunction.tt +++ b/src/Microsoft.Data.Sqlite.Core/SqliteConnection.CreateFunction.tt @@ -1,8 +1,9 @@ -<#@ assembly name="System.Core" #> +<#@ assembly name="System.Core" #> <#@ import namespace="System.Collections.Generic" #> <#@ import namespace="System.Linq" #> // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// using System; diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs b/src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs index c6c116ae36b..c476a98f1c7 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -10,7 +10,6 @@ using Microsoft.Data.Sqlite.Properties; using Microsoft.Data.Sqlite.Utilities; using SQLitePCL; - using static SQLitePCL.raw; namespace Microsoft.Data.Sqlite @@ -32,8 +31,10 @@ public partial class SqliteConnection : DbConnection private readonly Dictionary<(string name, int arity), (int flags, object state, delegate_function_scalar func)> _functions = new Dictionary<(string, int), (int, object, delegate_function_scalar)>(FunctionsKeyComparer.Instance); - private readonly Dictionary<(string name, int arity), (int flags, object state, delegate_function_aggregate_step func_step, delegate_function_aggregate_final func_final)> _aggregates - = new Dictionary<(string, int), (int, object, delegate_function_aggregate_step, delegate_function_aggregate_final)>(FunctionsKeyComparer.Instance); + private readonly Dictionary<(string name, int arity), (int flags, object state, delegate_function_aggregate_step func_step, + delegate_function_aggregate_final func_final)> _aggregates + = new Dictionary<(string, int), (int, object, delegate_function_aggregate_step, delegate_function_aggregate_final)>( + FunctionsKeyComparer.Instance); private readonly HashSet<(string file, string proc)> _extensions = new HashSet<(string, string)>(); @@ -284,7 +285,8 @@ public override void Open() foreach (var item in _aggregates) { - rc = sqlite3_create_function(_db, item.Key.name, item.Key.arity, item.Value.state, item.Value.func_step, item.Value.func_final); + rc = sqlite3_create_function( + _db, item.Key.name, item.Key.arity, item.Value.state, item.Value.func_step, item.Value.func_final); SqliteException.ThrowExceptionForRC(rc, _db); } @@ -380,12 +382,7 @@ protected override void Dispose(bool disposing) /// transaction. /// public new virtual SqliteCommand CreateCommand() - => new SqliteCommand - { - Connection = this, - CommandTimeout = DefaultTimeout, - Transaction = Transaction - }; + => new SqliteCommand { Connection = this, CommandTimeout = DefaultTimeout, Transaction = Transaction }; /// /// Creates a new command associated with the connection. @@ -415,7 +412,8 @@ internal void RemoveCommand(SqliteCommand command) /// Name of the collation. /// Method that compares two strings. public virtual void CreateCollation(string name, Comparison comparison) - => CreateCollation(name, null, comparison != null ? (_, s1, s2) => comparison(s1, s2) : (Func)null); + => CreateCollation( + name, null, comparison != null ? (_, s1, s2) => comparison(s1, s2) : (Func)null); /// /// Create custom collation. @@ -785,7 +783,7 @@ private class FunctionsKeyComparer : IEqualityComparer<(string name, int arity)> public bool Equals((string name, int arity) x, (string name, int arity) y) => StringComparer.OrdinalIgnoreCase.Equals(x.name, y.name) - && x.arity == y.arity; + && x.arity == y.arity; public int GetHashCode((string name, int arity) obj) { diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteDataReader.cs b/src/Microsoft.Data.Sqlite.Core/SqliteDataReader.cs index fcbb072bf6b..ba4ebd90476 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteDataReader.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteDataReader.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -12,7 +12,6 @@ using System.Threading; using Microsoft.Data.Sqlite.Properties; using SQLitePCL; - using static SQLitePCL.raw; namespace Microsoft.Data.Sqlite @@ -176,25 +175,23 @@ public override bool NextResult() return true; } - else + + while (rc != SQLITE_DONE) { - while (rc != SQLITE_DONE) - { - rc = sqlite3_step(stmt); - SqliteException.ThrowExceptionForRC(rc, _command.Connection.Handle); - } + rc = sqlite3_step(stmt); + SqliteException.ThrowExceptionForRC(rc, _command.Connection.Handle); + } - sqlite3_reset(stmt); + sqlite3_reset(stmt); - var changes = sqlite3_changes(_command.Connection.Handle); - if (_recordsAffected == -1) - { - _recordsAffected = changes; - } - else - { - _recordsAffected += changes; - } + var changes = sqlite3_changes(_command.Connection.Handle); + if (_recordsAffected == -1) + { + _recordsAffected = changes; + } + else + { + _recordsAffected += changes; } } catch @@ -694,14 +691,16 @@ public override DataTable GetSchemaTable() var type = (string)command.ExecuteScalar(); schemaRow[DataType] = (type != null) - ? SqliteDataRecord.GetFieldType(type) - : SqliteDataRecord.GetFieldTypeFromSqliteType( - SqliteDataRecord.Sqlite3AffinityType(dataTypeName)); + ? SqliteDataRecord.GetFieldType(type) + : SqliteDataRecord.GetFieldTypeFromSqliteType( + SqliteDataRecord.Sqlite3AffinityType(dataTypeName)); } if (!string.IsNullOrEmpty(databaseName)) { - var rc = sqlite3_table_column_metadata(_command.Connection.Handle, databaseName, tableName, columnName, out var dataType, out var collSeq, out var notNull, out var primaryKey, out var autoInc); + var rc = sqlite3_table_column_metadata( + _command.Connection.Handle, databaseName, tableName, columnName, out var dataType, out var collSeq, + out var notNull, out var primaryKey, out var autoInc); SqliteException.ThrowExceptionForRC(rc, _command.Connection.Handle); schemaRow[IsKey] = primaryKey != 0; diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteDataRecord.cs b/src/Microsoft.Data.Sqlite.Core/SqliteDataRecord.cs index 0809bdd85cc..9327fde6363 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteDataRecord.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteDataRecord.cs @@ -1,14 +1,12 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Diagnostics; -using System.Globalization; using System.IO; using System.Linq; using Microsoft.Data.Sqlite.Properties; using SQLitePCL; - using static SQLitePCL.raw; namespace Microsoft.Data.Sqlite @@ -296,6 +294,7 @@ public bool Read() return HasRows; } + if (sqlite3_data_count(Handle) == 0) { return false; @@ -340,20 +339,20 @@ internal static int Sqlite3AffinityType(string dataTypeName) } var typeRules = new Func[] - { - name => Contains(name, "INT") ? SQLITE_INTEGER : (int?)null, - name => Contains(name, "CHAR") + { + name => Contains(name, "INT") ? SQLITE_INTEGER : (int?)null, + name => Contains(name, "CHAR") || Contains(name, "CLOB") || Contains(name, "TEXT") - ? SQLITE_TEXT - : (int?)null, - name => Contains(name, "BLOB") ? SQLITE_BLOB : (int?)null, - name => Contains(name, "REAL") + ? SQLITE_TEXT + : (int?)null, + name => Contains(name, "BLOB") ? SQLITE_BLOB : (int?)null, + name => Contains(name, "REAL") || Contains(name, "FLOA") || Contains(name, "DOUB") - ? SQLITE_FLOAT - : (int?)null - }; + ? SQLITE_FLOAT + : (int?)null + }; return typeRules.Select(r => r(dataTypeName)).FirstOrDefault(r => r != null) ?? SQLITE_TEXT; // code NUMERICAL affinity as TEXT } diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteException.cs b/src/Microsoft.Data.Sqlite.Core/SqliteException.cs index b56b33c167c..3d20d51bbef 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteException.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteException.cs @@ -1,11 +1,9 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Data.Common; using Microsoft.Data.Sqlite.Properties; using SQLitePCL; - using static SQLitePCL.raw; namespace Microsoft.Data.Sqlite diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteFactory.cs b/src/Microsoft.Data.Sqlite.Core/SqliteFactory.cs index 64545ec0b61..d68ba304395 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteFactory.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Data.Common; diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteOpenMode.cs b/src/Microsoft.Data.Sqlite.Core/SqliteOpenMode.cs index 1de5667bb2f..3bebaf57974 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteOpenMode.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteOpenMode.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. namespace Microsoft.Data.Sqlite diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteParameter.cs b/src/Microsoft.Data.Sqlite.Core/SqliteParameter.cs index ce83309af05..91df9f1ec12 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteParameter.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteParameter.cs @@ -6,7 +6,6 @@ using System.Data.Common; using Microsoft.Data.Sqlite.Properties; using SQLitePCL; - using static SQLitePCL.raw; namespace Microsoft.Data.Sqlite diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteParameterBinder.cs b/src/Microsoft.Data.Sqlite.Core/SqliteParameterBinder.cs index 6bdd5d2ce21..6633ba44424 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteParameterBinder.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteParameterBinder.cs @@ -1,9 +1,8 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using SQLitePCL; - using static SQLitePCL.raw; namespace Microsoft.Data.Sqlite diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteParameterReader.cs b/src/Microsoft.Data.Sqlite.Core/SqliteParameterReader.cs index dd4cd6af757..85d1a6b7fc8 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteParameterReader.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteParameterReader.cs @@ -1,9 +1,8 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.Data.Sqlite.Properties; using SQLitePCL; - using static SQLitePCL.raw; namespace Microsoft.Data.Sqlite diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteResultBinder.cs b/src/Microsoft.Data.Sqlite.Core/SqliteResultBinder.cs index 97bb085b695..7f14873f28d 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteResultBinder.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteResultBinder.cs @@ -1,8 +1,7 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using SQLitePCL; - using static SQLitePCL.raw; namespace Microsoft.Data.Sqlite diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteTransaction.cs b/src/Microsoft.Data.Sqlite.Core/SqliteTransaction.cs index ece925bde39..fd361b98a87 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteTransaction.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteTransaction.cs @@ -5,7 +5,6 @@ using System.Data; using System.Data.Common; using Microsoft.Data.Sqlite.Properties; - using static SQLitePCL.raw; namespace Microsoft.Data.Sqlite @@ -18,7 +17,6 @@ public class SqliteTransaction : DbTransaction private SqliteConnection _connection; private readonly IsolationLevel _isolationLevel; private bool _completed; - private bool _externalRollback; internal SqliteTransaction(SqliteConnection connection, IsolationLevel isolationLevel) { @@ -67,8 +65,7 @@ internal SqliteTransaction(SqliteConnection connection, IsolationLevel isolation protected override DbConnection DbConnection => Connection; - internal bool ExternalRollback - => _externalRollback; + internal bool ExternalRollback { get; private set; } /// /// Gets the isolation level for the transaction. This cannot be changed if the transaction is completed or @@ -152,7 +149,7 @@ private void RollbackInternal() private void RollbackExternal(object userData) { sqlite3_rollback_hook(_connection.Handle, null, null); - _externalRollback = true; + ExternalRollback = true; } } } diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteValueBinder.cs b/src/Microsoft.Data.Sqlite.Core/SqliteValueBinder.cs index 1be0cdeed42..534c86a62a0 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteValueBinder.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteValueBinder.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteValueReader.cs b/src/Microsoft.Data.Sqlite.Core/SqliteValueReader.cs index 43e7bb4abd9..703d212146b 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteValueReader.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteValueReader.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -6,7 +6,6 @@ using System.Globalization; using System.Text; using Microsoft.Data.Sqlite.Properties; - using static SQLitePCL.raw; namespace Microsoft.Data.Sqlite diff --git a/src/Microsoft.Data.Sqlite.Core/Utilities/BundleInitializer.cs b/src/Microsoft.Data.Sqlite.Core/Utilities/BundleInitializer.cs index 2df0e99af7e..fb8e0218ef3 100644 --- a/src/Microsoft.Data.Sqlite.Core/Utilities/BundleInitializer.cs +++ b/src/Microsoft.Data.Sqlite.Core/Utilities/BundleInitializer.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Reflection; diff --git a/src/Shared/MemberInfoExtensions.cs b/src/Shared/MemberInfoExtensions.cs index 12345133ec5..bf334566c66 100644 --- a/src/Shared/MemberInfoExtensions.cs +++ b/src/Shared/MemberInfoExtensions.cs @@ -22,7 +22,8 @@ public static bool IsSameAs(this MemberInfo propertyInfo, MemberInfo otherProper || propertyInfo.DeclaringType.GetTypeInfo().IsSubclassOf(otherPropertyInfo.DeclaringType) || otherPropertyInfo.DeclaringType.GetTypeInfo().IsSubclassOf(propertyInfo.DeclaringType) || propertyInfo.DeclaringType.GetTypeInfo().ImplementedInterfaces.Contains(otherPropertyInfo.DeclaringType) - || otherPropertyInfo.DeclaringType.GetTypeInfo().ImplementedInterfaces.Contains(propertyInfo.DeclaringType)))); + || otherPropertyInfo.DeclaringType.GetTypeInfo().ImplementedInterfaces + .Contains(propertyInfo.DeclaringType)))); public static string GetSimpleMemberName(this MemberInfo member) { diff --git a/src/dotnet-ef/Commands/ProjectCommandBase.cs b/src/dotnet-ef/Commands/ProjectCommandBase.cs index 6cc1ffad5a1..ebaef2d3756 100644 --- a/src/dotnet-ef/Commands/ProjectCommandBase.cs +++ b/src/dotnet-ef/Commands/ProjectCommandBase.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.DotNet.Cli.CommandLine; diff --git a/src/dotnet-ef/Exe.cs b/src/dotnet-ef/Exe.cs index 4a11c1c2bb5..1f48aa181e5 100644 --- a/src/dotnet-ef/Exe.cs +++ b/src/dotnet-ef/Exe.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; @@ -21,10 +21,7 @@ public static int Run( var startInfo = new ProcessStartInfo { - FileName = executable, - Arguments = arguments, - UseShellExecute = false, - RedirectStandardOutput = interceptOutput + FileName = executable, Arguments = arguments, UseShellExecute = false, RedirectStandardOutput = interceptOutput }; if (workingDirectory != null) { @@ -77,6 +74,7 @@ private static string ToArguments(IReadOnlyList args) builder.Append('\\', pendingBackslashes * 2); pendingBackslashes = 0; } + builder.Append("\\\""); break; diff --git a/src/dotnet-ef/Program.cs b/src/dotnet-ef/Program.cs index d293e23132e..14fab25e454 100644 --- a/src/dotnet-ef/Program.cs +++ b/src/dotnet-ef/Program.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -10,10 +10,7 @@ internal static class Program { private static int Main(string[] args) { - var app = new CommandLineApplication(throwOnUnexpectedArg: false) - { - Name = "dotnet ef" - }; + var app = new CommandLineApplication(throwOnUnexpectedArg: false) { Name = "dotnet ef" }; new RootCommand().Configure(app); @@ -23,7 +20,8 @@ private static int Main(string[] args) } catch (Exception ex) { - if (ex is CommandException || ex is CommandParsingException) + if (ex is CommandException + || ex is CommandParsingException) { Reporter.WriteVerbose(ex.ToString()); } diff --git a/src/dotnet-ef/Project.cs b/src/dotnet-ef/Project.cs index af2aa75c9be..89b099c79dc 100644 --- a/src/dotnet-ef/Project.cs +++ b/src/dotnet-ef/Project.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; @@ -78,10 +78,12 @@ public static Project FromFile( { propertyArg += ";TargetFramework=" + framework; } + if (configuration != null) { propertyArg += ";Configuration=" + configuration; } + if (runtime != null) { propertyArg += ";RuntimeIdentifier=" + runtime; @@ -138,10 +140,7 @@ public static Project FromFile( public void Build() { - var args = new List - { - "build" - }; + var args = new List { "build" }; if (_file != null) { diff --git a/src/dotnet-ef/ProjectOptions.cs b/src/dotnet-ef/ProjectOptions.cs index 7af371c16b7..1f7ef975872 100644 --- a/src/dotnet-ef/ProjectOptions.cs +++ b/src/dotnet-ef/ProjectOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.DotNet.Cli.CommandLine; @@ -8,44 +8,23 @@ namespace Microsoft.EntityFrameworkCore.Tools { internal class ProjectOptions { - private CommandOption _project; - private CommandOption _startupProject; - private CommandOption _framework; - private CommandOption _configuration; - private CommandOption _runtime; - private CommandOption _msbuildprojectextensionspath; - private CommandOption _noBuild; - - public CommandOption Project - => _project; - - public CommandOption StartupProject - => _startupProject; - - public CommandOption Framework - => _framework; - - public CommandOption Configuration - => _configuration; - - public CommandOption Runtime - => _runtime; - - public CommandOption MSBuildProjectExtensionsPath - => _msbuildprojectextensionspath; - - public CommandOption NoBuild - => _noBuild; + public CommandOption Project { get; private set; } + public CommandOption StartupProject { get; private set; } + public CommandOption Framework { get; private set; } + public CommandOption Configuration { get; private set; } + public CommandOption Runtime { get; private set; } + public CommandOption MSBuildProjectExtensionsPath { get; private set; } + public CommandOption NoBuild { get; private set; } public void Configure(CommandLineApplication command) { - _project = command.Option("-p|--project ", Resources.ProjectDescription); - _startupProject = command.Option("-s|--startup-project ", Resources.StartupProjectDescription); - _framework = command.Option("--framework ", Resources.FrameworkDescription); - _configuration = command.Option("--configuration ", Resources.ConfigurationDescription); - _runtime = command.Option("--runtime ", Resources.RuntimeDescription); - _msbuildprojectextensionspath = command.Option("--msbuildprojectextensionspath ", Resources.ProjectExtensionsDescription); - _noBuild = command.Option("--no-build", Resources.NoBuildDescription); + Project = command.Option("-p|--project ", Resources.ProjectDescription); + StartupProject = command.Option("-s|--startup-project ", Resources.StartupProjectDescription); + Framework = command.Option("--framework ", Resources.FrameworkDescription); + Configuration = command.Option("--configuration ", Resources.ConfigurationDescription); + Runtime = command.Option("--runtime ", Resources.RuntimeDescription); + MSBuildProjectExtensionsPath = command.Option("--msbuildprojectextensionspath ", Resources.ProjectExtensionsDescription); + NoBuild = command.Option("--no-build", Resources.NoBuildDescription); } } } diff --git a/src/dotnet-ef/Properties/AssemblyInfo.cs b/src/dotnet-ef/Properties/AssemblyInfo.cs index a5660f55717..8c70e81929c 100644 --- a/src/dotnet-ef/Properties/AssemblyInfo.cs +++ b/src/dotnet-ef/Properties/AssemblyInfo.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Runtime.CompilerServices; diff --git a/src/dotnet-ef/RootCommand.cs b/src/dotnet-ef/RootCommand.cs index a18bb0ab158..61959d89319 100644 --- a/src/dotnet-ef/RootCommand.cs +++ b/src/dotnet-ef/RootCommand.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -11,7 +11,6 @@ using Microsoft.DotNet.Cli.CommandLine; using Microsoft.EntityFrameworkCore.Tools.Commands; using Microsoft.EntityFrameworkCore.Tools.Properties; - using EFCommand = Microsoft.EntityFrameworkCore.Tools.Commands.RootCommand; namespace Microsoft.EntityFrameworkCore.Tools @@ -57,7 +56,8 @@ public override void Configure(CommandLineApplication command) protected override int Execute() { var commands = _args.TakeWhile(a => a[0] != '-').ToList(); - if (_help.HasValue() || ShouldHelp(commands)) + if (_help.HasValue() + || ShouldHelp(commands)) { return ShowHelp(_help.HasValue(), commands); } @@ -223,17 +223,20 @@ private static (string, string) ResolveProjects( : Resources.MultipleStartupProjects); } - if (projectPath != null && projects.Count == 0) + if (projectPath != null + && projects.Count == 0) { throw new CommandException(Resources.NoProjectInDirectory(projectPath)); } - if (startupProjectPath != null && startupProjects.Count == 0) + if (startupProjectPath != null + && startupProjects.Count == 0) { throw new CommandException(Resources.NoProjectInDirectory(startupProjectPath)); } - if (projectPath == null && startupProjectPath == null) + if (projectPath == null + && startupProjectPath == null) { return projects.Count == 0 ? throw new CommandException(Resources.NoProject) @@ -265,8 +268,8 @@ private static List ResolveProjects(string path) } var projectFiles = Directory.EnumerateFiles(path, "*.*proj", SearchOption.TopDirectoryOnly) - .Where(f => !string.Equals(Path.GetExtension(f), ".xproj", StringComparison.OrdinalIgnoreCase)) - .Take(2).ToList(); + .Where(f => !string.Equals(Path.GetExtension(f), ".xproj", StringComparison.OrdinalIgnoreCase)) + .Take(2).ToList(); return projectFiles; } @@ -277,17 +280,14 @@ private static string GetVersion() private static bool ShouldHelp(IReadOnlyList commands) => commands.Count == 0 - || (commands.Count == 1 - && (commands[0] == "database" - || commands[0] == "dbcontext" - || commands[0] == "migrations")); + || (commands.Count == 1 + && (commands[0] == "database" + || commands[0] == "dbcontext" + || commands[0] == "migrations")); private int ShowHelp(bool help, IEnumerable commands) { - var app = new CommandLineApplication - { - Name = _command.Name - }; + var app = new CommandLineApplication { Name = _command.Name }; new EFCommand().Configure(app); diff --git a/src/ef/AnsiConsole.cs b/src/ef/AnsiConsole.cs index 969c5cb3af0..ed3cb924c37 100644 --- a/src/ef/AnsiConsole.cs +++ b/src/ef/AnsiConsole.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/ef/AnsiConstants.cs b/src/ef/AnsiConstants.cs index ffa0b88b124..3980cdbeeaa 100644 --- a/src/ef/AnsiConstants.cs +++ b/src/ef/AnsiConstants.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. namespace Microsoft.EntityFrameworkCore.Tools diff --git a/src/ef/AnsiTextWriter.cs b/src/ef/AnsiTextWriter.cs index 032a58d96b0..737552a824e 100644 --- a/src/ef/AnsiTextWriter.cs +++ b/src/ef/AnsiTextWriter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/ef/AppDomainOperationExecutor.cs b/src/ef/AppDomainOperationExecutor.cs index df96fee0998..cdd7ab4e102 100644 --- a/src/ef/AppDomainOperationExecutor.cs +++ b/src/ef/AppDomainOperationExecutor.cs @@ -1,8 +1,7 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. #if NET461 - using System; using System.Collections; using System.IO; diff --git a/src/ef/CommandException.cs b/src/ef/CommandException.cs index 12a3ccae8bc..7cc5a1f4987 100644 --- a/src/ef/CommandException.cs +++ b/src/ef/CommandException.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/ef/CommandLineUtils/CommandLineApplication.cs b/src/ef/CommandLineUtils/CommandLineApplication.cs index b655da70d59..84d02e91b23 100644 --- a/src/ef/CommandLineUtils/CommandLineApplication.cs +++ b/src/ef/CommandLineUtils/CommandLineApplication.cs @@ -18,7 +18,7 @@ private enum ParseOptionResult Succeeded, ShowHelp, ShowVersion, - UnexpectedArgs, + UnexpectedArgs } // Indicates whether the parser should throw an exception when it runs into an unexpected argument. @@ -46,7 +46,7 @@ public CommandLineApplication(bool throwOnUnexpectedArg = true) public CommandOption OptionVersion { get; private set; } public List Arguments { get; } public List RemainingArguments { get; } - public bool IsShowingInformation { get; protected set; } // Is showing help or version? + public bool IsShowingInformation { get; protected set; } // Is showing help or version? public Func Invoke { get; set; } public Func LongVersionGetter { get; set; } public Func ShortVersionGetter { get; set; } @@ -59,7 +59,8 @@ public CommandLineApplication(bool throwOnUnexpectedArg = true) public CommandLineApplication Command(string name, bool throwOnUnexpectedArg = true) => Command(name, _ => { }, throwOnUnexpectedArg); - public CommandLineApplication Command(string name, Action configuration, + public CommandLineApplication Command( + string name, Action configuration, bool throwOnUnexpectedArg = true) { var command = new CommandLineApplication(throwOnUnexpectedArg) { Name = name, Parent = this }; @@ -87,7 +88,8 @@ public CommandArgument Argument(string name, string description, Action shortFormVersion); } - else - { - return VersionOption(template, () => shortFormVersion, () => longFormVersion); - } + + return VersionOption(template, () => shortFormVersion, () => longFormVersion); } // Helper method that adds a version option - public CommandOption VersionOption(string template, - Func shortFormVersionGetter, - Func longFormVersionGetter = null) + public CommandOption VersionOption( + string template, + Func shortFormVersionGetter, + Func longFormVersionGetter = null) { // Version option is special because we stop parsing once we see it // So we store it separately for further use @@ -304,7 +310,7 @@ public void ShowHint() { if (OptionHelp != null) { - Console.WriteLine(string.Format("Specify --{0} for a list of available options and commands.", OptionHelp.LongName)); + Console.WriteLine("Specify --{0} for a list of available options and commands.", OptionHelp.LongName); } } @@ -316,7 +322,8 @@ public void ShowHelp(string commandName = null) for (var cmd = this; cmd != null; cmd = cmd.Parent) { cmd.IsShowingInformation = true; - if (cmd != this && cmd.Arguments.Count > 0) + if (cmd != this + && cmd.Arguments.Count > 0) { var args = string.Join(" ", cmd.Arguments.Select(arg => arg.Name)); headerBuilder.Insert(usagePrefixLength, string.Format(" {0} {1}", cmd.Name, args)); @@ -329,7 +336,8 @@ public void ShowHelp(string commandName = null) CommandLineApplication target; - if (commandName == null || string.Equals(Name, commandName, StringComparison.OrdinalIgnoreCase)) + if (commandName == null + || string.Equals(Name, commandName, StringComparison.OrdinalIgnoreCase)) { target = this; } @@ -426,7 +434,8 @@ public void ShowHelp(string commandName = null) } } - if (target.AllowArgumentSeparator || target.HandleRemainingArguments) + if (target.AllowArgumentSeparator + || target.HandleRemainingArguments) { if (target.AllowArgumentSeparator) { @@ -452,7 +461,9 @@ public void ShowHelp(string commandName = null) nameAndVersion.AppendLine(GetFullNameAndVersion()); nameAndVersion.AppendLine(); - Console.Write("{0}{1}{2}{3}{4}{5}", nameAndVersion, headerBuilder, argumentsBuilder, optionsBuilder, commandsBuilder, argumentSeparatorBuilder); + Console.Write( + "{0}{1}{2}{3}{4}{5}", nameAndVersion, headerBuilder, argumentsBuilder, optionsBuilder, commandsBuilder, + argumentSeparatorBuilder); } public void ShowVersion() @@ -488,6 +499,7 @@ private static int MaxOptionTemplateLength(IEnumerable options) { maxLen = opt.Template.Length > maxLen ? opt.Template.Length : maxLen; } + return maxLen; } @@ -498,6 +510,7 @@ private static int MaxCommandLength(IEnumerable commands { maxLen = cmd.Name.Length > maxLen ? cmd.Name.Length : maxLen; } + return maxLen; } @@ -508,6 +521,7 @@ private static int MaxArgumentLength(IEnumerable arguments) { maxLen = arg.Name.Length > maxLen ? arg.Name.Length : maxLen; } + return maxLen; } @@ -518,10 +532,8 @@ private static void HandleUnexpectedArg(CommandLineApplication command, string[] command.ShowHint(); throw new CommandParsingException(command, $"Unrecognized {argTypeName} '{args[index]}'"); } - else - { - command.RemainingArguments.Add(args[index]); - } + + command.RemainingArguments.Add(args[index]); } private IEnumerable ExpandResponseFiles(IEnumerable args) diff --git a/src/ef/CommandLineUtils/CommandLineApplicationExtensions.cs b/src/ef/CommandLineUtils/CommandLineApplicationExtensions.cs index 1c43455ee15..346d8a80996 100644 --- a/src/ef/CommandLineUtils/CommandLineApplicationExtensions.cs +++ b/src/ef/CommandLineUtils/CommandLineApplicationExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. namespace Microsoft.DotNet.Cli.CommandLine diff --git a/src/ef/CommandLineUtils/CommandOption.cs b/src/ef/CommandLineUtils/CommandOption.cs index 7aa04874da6..0c947d6a929 100644 --- a/src/ef/CommandLineUtils/CommandOption.cs +++ b/src/ef/CommandLineUtils/CommandOption.cs @@ -25,7 +25,8 @@ public CommandOption(string template, CommandOptionType optionType) var optName = part.Substring(1); // If there is only one char and it is not an English letter, it is a symbol option (e.g. "-?") - if (optName.Length == 1 && !IsEnglishLetter(optName[0])) + if (optName.Length == 1 + && !IsEnglishLetter(optName[0])) { SymbolName = optName; } @@ -34,11 +35,14 @@ public CommandOption(string template, CommandOptionType optionType) ShortName = optName; } } - else if (part.StartsWith("<") && part.EndsWith(">")) + else if (part.StartsWith("<") + && part.EndsWith(">")) { ValueName = part.Substring(1, part.Length - 2); } - else if (optionType == CommandOptionType.MultipleValue && part.StartsWith("<") && part.EndsWith(">...")) + else if (optionType == CommandOptionType.MultipleValue + && part.StartsWith("<") + && part.EndsWith(">...")) { ValueName = part.Substring(1, part.Length - 5); } @@ -48,7 +52,9 @@ public CommandOption(string template, CommandOptionType optionType) } } - if (string.IsNullOrEmpty(LongName) && string.IsNullOrEmpty(ShortName) && string.IsNullOrEmpty(SymbolName)) + if (string.IsNullOrEmpty(LongName) + && string.IsNullOrEmpty(ShortName) + && string.IsNullOrEmpty(SymbolName)) { throw new ArgumentException($"Invalid template pattern '{template}'", nameof(template)); } @@ -76,6 +82,7 @@ public bool TryParse(string value) { return false; } + Values.Add(value); break; case CommandOptionType.BoolValue: @@ -100,18 +107,19 @@ public bool TryParse(string value) Values.Add(value); BoolValue = boolValue; } + break; case CommandOptionType.NoValue: if (value != null) { return false; } + // Add a value to indicate that this option was specified Values.Add("on"); break; - default: - break; } + return true; } diff --git a/src/ef/CommandLineUtils/CommandParsingException.cs b/src/ef/CommandLineUtils/CommandParsingException.cs index c735ecbf12d..f5e6da05f4e 100644 --- a/src/ef/CommandLineUtils/CommandParsingException.cs +++ b/src/ef/CommandLineUtils/CommandParsingException.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/ef/Commands/CommandBase.cs b/src/ef/Commands/CommandBase.cs index bb098ca408a..1bdde78a788 100644 --- a/src/ef/Commands/CommandBase.cs +++ b/src/ef/Commands/CommandBase.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.DotNet.Cli.CommandLine; @@ -18,15 +18,15 @@ public virtual void Configure(CommandLineApplication command) command.OnExecute( () => - { - Reporter.IsVerbose = verbose.HasValue(); - Reporter.NoColor = noColor.HasValue(); - Reporter.PrefixOutput = prefixOutput.HasValue(); + { + Reporter.IsVerbose = verbose.HasValue(); + Reporter.NoColor = noColor.HasValue(); + Reporter.PrefixOutput = prefixOutput.HasValue(); - Validate(); + Validate(); - return Execute(); - }); + return Execute(); + }); } protected virtual void Validate() diff --git a/src/ef/Commands/ContextCommandBase.cs b/src/ef/Commands/ContextCommandBase.cs index d65df2d6c78..8b4232815b2 100644 --- a/src/ef/Commands/ContextCommandBase.cs +++ b/src/ef/Commands/ContextCommandBase.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.DotNet.Cli.CommandLine; diff --git a/src/ef/Commands/DatabaseCommand.cs b/src/ef/Commands/DatabaseCommand.cs index ccff76f6cdb..a18eb48c62d 100644 --- a/src/ef/Commands/DatabaseCommand.cs +++ b/src/ef/Commands/DatabaseCommand.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.DotNet.Cli.CommandLine; diff --git a/src/ef/Commands/DatabaseDropCommand.Configure.cs b/src/ef/Commands/DatabaseDropCommand.Configure.cs index 8c899ee65d2..65df319a1c3 100644 --- a/src/ef/Commands/DatabaseDropCommand.Configure.cs +++ b/src/ef/Commands/DatabaseDropCommand.Configure.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.DotNet.Cli.CommandLine; diff --git a/src/ef/Commands/DatabaseDropCommand.cs b/src/ef/Commands/DatabaseDropCommand.cs index 09a118baa7d..b1b076260de 100644 --- a/src/ef/Commands/DatabaseDropCommand.cs +++ b/src/ef/Commands/DatabaseDropCommand.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/ef/Commands/DatabaseUpdateCommand.Configure.cs b/src/ef/Commands/DatabaseUpdateCommand.Configure.cs index 633fa58da20..7ea20a03b36 100644 --- a/src/ef/Commands/DatabaseUpdateCommand.Configure.cs +++ b/src/ef/Commands/DatabaseUpdateCommand.Configure.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.DotNet.Cli.CommandLine; diff --git a/src/ef/Commands/DatabaseUpdateCommand.cs b/src/ef/Commands/DatabaseUpdateCommand.cs index 040c8fd51dd..f916dd5fac9 100644 --- a/src/ef/Commands/DatabaseUpdateCommand.cs +++ b/src/ef/Commands/DatabaseUpdateCommand.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. namespace Microsoft.EntityFrameworkCore.Tools.Commands diff --git a/src/ef/Commands/DbContextCommand.cs b/src/ef/Commands/DbContextCommand.cs index 0c2de17ec68..e94048bcbc9 100644 --- a/src/ef/Commands/DbContextCommand.cs +++ b/src/ef/Commands/DbContextCommand.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.DotNet.Cli.CommandLine; diff --git a/src/ef/Commands/DbContextInfoCommand.Configure.cs b/src/ef/Commands/DbContextInfoCommand.Configure.cs index 641ff97725f..7426be15445 100644 --- a/src/ef/Commands/DbContextInfoCommand.Configure.cs +++ b/src/ef/Commands/DbContextInfoCommand.Configure.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.DotNet.Cli.CommandLine; diff --git a/src/ef/Commands/DbContextInfoCommand.cs b/src/ef/Commands/DbContextInfoCommand.cs index 92ca3b0be52..4dc81b94350 100644 --- a/src/ef/Commands/DbContextInfoCommand.cs +++ b/src/ef/Commands/DbContextInfoCommand.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections; diff --git a/src/ef/Commands/DbContextListCommand.Configure.cs b/src/ef/Commands/DbContextListCommand.Configure.cs index 47eda375637..26ab2d4d806 100644 --- a/src/ef/Commands/DbContextListCommand.Configure.cs +++ b/src/ef/Commands/DbContextListCommand.Configure.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.DotNet.Cli.CommandLine; diff --git a/src/ef/Commands/DbContextListCommand.cs b/src/ef/Commands/DbContextListCommand.cs index abcfd8a0467..921b9a7bceb 100644 --- a/src/ef/Commands/DbContextListCommand.cs +++ b/src/ef/Commands/DbContextListCommand.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections; diff --git a/src/ef/Commands/DbContextScaffoldCommand.Configure.cs b/src/ef/Commands/DbContextScaffoldCommand.Configure.cs index 5c775b9db1c..5d2b246f9c0 100644 --- a/src/ef/Commands/DbContextScaffoldCommand.Configure.cs +++ b/src/ef/Commands/DbContextScaffoldCommand.Configure.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.DotNet.Cli.CommandLine; diff --git a/src/ef/Commands/DbContextScaffoldCommand.cs b/src/ef/Commands/DbContextScaffoldCommand.cs index 3915bea1ae4..1b6d0905ba3 100644 --- a/src/ef/Commands/DbContextScaffoldCommand.cs +++ b/src/ef/Commands/DbContextScaffoldCommand.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections; @@ -18,6 +18,7 @@ protected override void Validate() { throw new CommandException(Resources.MissingArgument(_connection.Name)); } + if (string.IsNullOrEmpty(_provider.Value)) { throw new CommandException(Resources.MissingArgument(_provider.Name)); diff --git a/src/ef/Commands/DbContextScriptCommand.Configure.cs b/src/ef/Commands/DbContextScriptCommand.Configure.cs index 91b1efc0dbe..863dfe24e02 100644 --- a/src/ef/Commands/DbContextScriptCommand.Configure.cs +++ b/src/ef/Commands/DbContextScriptCommand.Configure.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.DotNet.Cli.CommandLine; diff --git a/src/ef/Commands/DbContextScriptCommand.cs b/src/ef/Commands/DbContextScriptCommand.cs index 066f67b6e34..6297713bd37 100644 --- a/src/ef/Commands/DbContextScriptCommand.cs +++ b/src/ef/Commands/DbContextScriptCommand.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.IO; diff --git a/src/ef/Commands/EFCommandBase.cs b/src/ef/Commands/EFCommandBase.cs index 2f671024f1d..4c392504990 100644 --- a/src/ef/Commands/EFCommandBase.cs +++ b/src/ef/Commands/EFCommandBase.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.DotNet.Cli.CommandLine; diff --git a/src/ef/Commands/HelpCommandBase.cs b/src/ef/Commands/HelpCommandBase.cs index 1f44ec2df12..42d3d648c00 100644 --- a/src/ef/Commands/HelpCommandBase.cs +++ b/src/ef/Commands/HelpCommandBase.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.DotNet.Cli.CommandLine; diff --git a/src/ef/Commands/MigrationsAddCommand.Configure.cs b/src/ef/Commands/MigrationsAddCommand.Configure.cs index f80bfbca262..5e3cb049566 100644 --- a/src/ef/Commands/MigrationsAddCommand.Configure.cs +++ b/src/ef/Commands/MigrationsAddCommand.Configure.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.DotNet.Cli.CommandLine; diff --git a/src/ef/Commands/MigrationsAddCommand.cs b/src/ef/Commands/MigrationsAddCommand.cs index 5a1e9a92469..37031581bd5 100644 --- a/src/ef/Commands/MigrationsAddCommand.cs +++ b/src/ef/Commands/MigrationsAddCommand.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections; diff --git a/src/ef/Commands/MigrationsCommand.cs b/src/ef/Commands/MigrationsCommand.cs index f8e5ae81456..7b084bc616a 100644 --- a/src/ef/Commands/MigrationsCommand.cs +++ b/src/ef/Commands/MigrationsCommand.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.DotNet.Cli.CommandLine; diff --git a/src/ef/Commands/MigrationsListCommand.Configure.cs b/src/ef/Commands/MigrationsListCommand.Configure.cs index 888f463cf18..21724423b2c 100644 --- a/src/ef/Commands/MigrationsListCommand.Configure.cs +++ b/src/ef/Commands/MigrationsListCommand.Configure.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.DotNet.Cli.CommandLine; diff --git a/src/ef/Commands/MigrationsListCommand.cs b/src/ef/Commands/MigrationsListCommand.cs index 1733528338c..dfd775ece7d 100644 --- a/src/ef/Commands/MigrationsListCommand.cs +++ b/src/ef/Commands/MigrationsListCommand.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections; diff --git a/src/ef/Commands/MigrationsRemoveCommand.Configure.cs b/src/ef/Commands/MigrationsRemoveCommand.Configure.cs index 7c1ab8024e0..ff6c223a23a 100644 --- a/src/ef/Commands/MigrationsRemoveCommand.Configure.cs +++ b/src/ef/Commands/MigrationsRemoveCommand.Configure.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.DotNet.Cli.CommandLine; diff --git a/src/ef/Commands/MigrationsRemoveCommand.cs b/src/ef/Commands/MigrationsRemoveCommand.cs index f19c8d1b8b4..4b8876b7ad4 100644 --- a/src/ef/Commands/MigrationsRemoveCommand.cs +++ b/src/ef/Commands/MigrationsRemoveCommand.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections; diff --git a/src/ef/Commands/MigrationsScriptCommand.Configure.cs b/src/ef/Commands/MigrationsScriptCommand.Configure.cs index 9ecddc4b3f5..329fed6f249 100644 --- a/src/ef/Commands/MigrationsScriptCommand.Configure.cs +++ b/src/ef/Commands/MigrationsScriptCommand.Configure.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.DotNet.Cli.CommandLine; diff --git a/src/ef/Commands/MigrationsScriptCommand.cs b/src/ef/Commands/MigrationsScriptCommand.cs index 5af6ee7e80a..bf91dd20b9d 100644 --- a/src/ef/Commands/MigrationsScriptCommand.cs +++ b/src/ef/Commands/MigrationsScriptCommand.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.IO; diff --git a/src/ef/Commands/ProjectCommandBase.cs b/src/ef/Commands/ProjectCommandBase.cs index 850518643c6..661ae7588c9 100644 --- a/src/ef/Commands/ProjectCommandBase.cs +++ b/src/ef/Commands/ProjectCommandBase.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.IO; diff --git a/src/ef/Commands/RootCommand.cs b/src/ef/Commands/RootCommand.cs index fd64f71d00a..a0b581747f7 100644 --- a/src/ef/Commands/RootCommand.cs +++ b/src/ef/Commands/RootCommand.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/ef/IOperationExecutor.cs b/src/ef/IOperationExecutor.cs index 6bf44abfdcd..766061b0500 100644 --- a/src/ef/IOperationExecutor.cs +++ b/src/ef/IOperationExecutor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/ef/Json.cs b/src/ef/Json.cs index 02845b183a7..2d6abe198ca 100644 --- a/src/ef/Json.cs +++ b/src/ef/Json.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.DotNet.Cli.CommandLine; diff --git a/src/ef/OperationExecutorBase.cs b/src/ef/OperationExecutorBase.cs index 465656d60d7..06f77618dbc 100644 --- a/src/ef/OperationExecutorBase.cs +++ b/src/ef/OperationExecutorBase.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections; @@ -85,54 +85,32 @@ private object InvokeOperationImpl(string operationName, IDictionary arguments) public IDictionary AddMigration(string name, string outputDir, string contextType) => InvokeOperation( "AddMigration", - new Dictionary - { - ["name"] = name, - ["outputDir"] = outputDir, - ["contextType"] = contextType - }); + new Dictionary { ["name"] = name, ["outputDir"] = outputDir, ["contextType"] = contextType }); public IDictionary RemoveMigration(string contextType, bool force) => InvokeOperation( "RemoveMigration", - new Dictionary - { - ["contextType"] = contextType, - ["force"] = force - }); + new Dictionary { ["contextType"] = contextType, ["force"] = force }); public IEnumerable GetMigrations(string contextType) => InvokeOperation>( "GetMigrations", - new Dictionary - { - ["contextType"] = contextType - }); + new Dictionary { ["contextType"] = contextType }); public void DropDatabase(string contextType) => InvokeOperation( "DropDatabase", - new Dictionary - { - ["contextType"] = contextType - }); + new Dictionary { ["contextType"] = contextType }); public IDictionary GetContextInfo(string name) => InvokeOperation( "GetContextInfo", - new Dictionary - { - ["contextType"] = name - }); + new Dictionary { ["contextType"] = name }); public void UpdateDatabase(string migration, string contextType) => InvokeOperation( "UpdateDatabase", - new Dictionary - { - ["targetMigration"] = migration, - ["contextType"] = contextType - }); + new Dictionary { ["targetMigration"] = migration, ["contextType"] = contextType }); public IEnumerable GetContextTypes() => InvokeOperation>("GetContextTypes"); @@ -182,9 +160,6 @@ public string ScriptMigration( public string ScriptDbContext(string contextType) => InvokeOperation( "ScriptDbContext", - new Dictionary - { - ["contextType"] = contextType - }); + new Dictionary { ["contextType"] = contextType }); } } diff --git a/src/ef/Program.cs b/src/ef/Program.cs index 4ad03a58794..7d169b6cf00 100644 --- a/src/ef/Program.cs +++ b/src/ef/Program.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -17,10 +17,7 @@ private static int Main(string[] args) Console.OutputEncoding = Encoding.UTF8; } - var app = new CommandLineApplication - { - Name = "ef" - }; + var app = new CommandLineApplication { Name = "ef" }; new RootCommand().Configure(app); diff --git a/src/ef/Properties/AssemblyInfo.cs b/src/ef/Properties/AssemblyInfo.cs index 7cb80598616..9a222d9fc92 100644 --- a/src/ef/Properties/AssemblyInfo.cs +++ b/src/ef/Properties/AssemblyInfo.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Runtime.CompilerServices; diff --git a/src/ef/ReflectionOperationExecutor.cs b/src/ef/ReflectionOperationExecutor.cs index 716e0f6f0d6..54e60e63ff3 100644 --- a/src/ef/ReflectionOperationExecutor.cs +++ b/src/ef/ReflectionOperationExecutor.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -6,8 +6,8 @@ using System.Collections.Generic; using System.IO; using System.Reflection; -using Microsoft.EntityFrameworkCore.Tools.Properties; using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Tools.Properties; namespace Microsoft.EntityFrameworkCore.Tools { diff --git a/src/ef/Reporter.cs b/src/ef/Reporter.cs index d433e9b69fe..219ca5a2022 100644 --- a/src/ef/Reporter.cs +++ b/src/ef/Reporter.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; diff --git a/src/ef/WrappedException.cs b/src/ef/WrappedException.cs index d16d691d043..d9574687301 100644 --- a/src/ef/WrappedException.cs +++ b/src/ef/WrappedException.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System;