From 5784b52dd9f884cd91289a1c76216a15cd517abc Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Sun, 18 Jun 2023 15:13:33 +0200 Subject: [PATCH] Cleanup (#2794) --- .../Storage/Internal/IntervalRangeMapping.cs | 2 +- .../Internal/TimestampLocalDateTimeMapping.cs | 2 +- .../Internal/IReadOnlyListExtensions.cs | 4 +- .../Internal/NpgsqlSingletonOptions.cs | 1 - ...NpgsqlPostgresModelFinalizingConvention.cs | 3 +- .../Internal/NpgsqlAnnotationProvider.cs | 3 +- src/EFCore.PG/Metadata/PostgresExtension.cs | 2 +- .../NpgsqlMigrationsSqlGenerator.cs | 12 ++--- .../Internal/NpgsqlArrayMethodTranslator.cs | 2 +- .../NpgsqlJsonDbFunctionsTranslator.cs | 5 +- .../Internal/NpgsqlJsonDomTranslator.cs | 3 +- .../Internal/NpgsqlLikeTranslator.cs | 7 ++- .../NpgsqlObjectToStringTranslator.cs | 2 +- .../Internal/NpgsqlRangeTranslator.cs | 2 +- .../Internal/NpgsqlRowValueTranslator.cs | 2 +- .../Internal/NpgsqlStringMethodTranslator.cs | 6 +-- .../Internal/PostgresBinaryExpression.cs | 6 +-- .../Query/Internal/NpgsqlQuerySqlGenerator.cs | 10 ++-- .../Internal/NpgsqlSqlNullabilityProcessor.cs | 3 +- .../NpgsqlSqlTranslatingExpressionVisitor.cs | 36 +++++++-------- .../Query/NpgsqlSqlExpressionFactory.cs | 9 +--- .../Internal/NpgsqlDatabaseModelFactory.cs | 17 ++----- .../Storage/Internal/NpgsqlDatabaseCreator.cs | 23 ++++------ src/Shared/Check.cs | 3 +- src/Shared/SharedTypeExtensions.cs | 5 +- .../BuiltInDataTypesNpgsqlTest.cs | 2 +- ...FiltersInheritanceBulkUpdatesNpgsqlTest.cs | 2 +- .../InheritanceBulkUpdatesNpgsqlTest.cs | 2 +- .../NorthwindBulkUpdatesNpgsqlTest.cs | 2 +- ...FiltersInheritanceBulkUpdatesNpgsqlTest.cs | 2 +- .../TPCInheritanceBulkUpdatesNpgsqlTest.cs | 2 +- ...FiltersInheritanceBulkUpdatesNpgsqlTest.cs | 2 +- .../TPTInheritanceBulkUpdatesNpgsqlTest.cs | 2 +- .../ExecutionStrategyTest.cs | 20 ++++---- .../ExistingConnectionTest.cs | 6 +-- .../MigrationsInfrastructureNpgsqlTest.cs | 2 +- .../Migrations/MigrationsNpgsqlTest.cs | 2 +- .../NpgsqlDatabaseCreatorTest.cs | 46 +++++++++---------- .../OptimisticConcurrencyNpgsqlTest.cs | 16 +++---- .../Query/ArrayArrayQueryTest.cs | 2 +- .../Query/ArrayQueryTest.cs | 2 +- .../Query/EnumQueryTest.cs | 18 ++++---- .../Query/FromSqlQueryNpgsqlTest.cs | 8 ++-- .../Query/GearsOfWarQueryNpgsqlTest.cs | 2 +- .../Query/LegacyTimestampQueryTest.cs | 4 +- .../NorthwindFunctionsQueryNpgsqlTest.cs | 14 +++--- .../NorthwindMiscellaneousQueryNpgsqlTest.cs | 8 ++-- .../Query/TimestampQueryTest.cs | 32 ++++++------- .../SequenceEndToEndTest.cs | 10 ++-- .../SystemColumnTest.cs | 4 +- .../TestUtilities/NpgsqlTestStore.cs | 6 +-- .../TestUtilities/NpgsqlTestStoreFactory.cs | 2 +- .../TestNpgsqlRetryingExecutionStrategy.cs | 3 +- .../TransactionNpgsqlTest.cs | 6 +-- .../Update/StoreValueGenerationNpgsqlTest.cs | 2 +- .../ValueConvertersEndToEndNpgsqlTest.cs | 2 +- .../NodaTimeQueryNpgsqlTest.cs | 20 ++++---- .../Storage/NpgsqlTypeMappingSourceTest.cs | 2 +- 58 files changed, 193 insertions(+), 232 deletions(-) diff --git a/src/EFCore.PG.NodaTime/Storage/Internal/IntervalRangeMapping.cs b/src/EFCore.PG.NodaTime/Storage/Internal/IntervalRangeMapping.cs index 5c989d491..ed833a79a 100644 --- a/src/EFCore.PG.NodaTime/Storage/Internal/IntervalRangeMapping.cs +++ b/src/EFCore.PG.NodaTime/Storage/Internal/IntervalRangeMapping.cs @@ -118,7 +118,7 @@ public override Expression GenerateCodeLiteral(object value) { var interval = (Interval)value; - return interval.HasStart && interval.HasEnd + return interval is { HasStart: true, HasEnd: true } ? Expression.New( _constructor, TimestampTzInstantMapping.GenerateCodeLiteral(interval.Start), diff --git a/src/EFCore.PG.NodaTime/Storage/Internal/TimestampLocalDateTimeMapping.cs b/src/EFCore.PG.NodaTime/Storage/Internal/TimestampLocalDateTimeMapping.cs index e3b58b91d..ecf8a5620 100644 --- a/src/EFCore.PG.NodaTime/Storage/Internal/TimestampLocalDateTimeMapping.cs +++ b/src/EFCore.PG.NodaTime/Storage/Internal/TimestampLocalDateTimeMapping.cs @@ -124,7 +124,7 @@ private string GenerateLiteralCore(object value) internal static Expression GenerateCodeLiteral(LocalDateTime dateTime) { - if (dateTime.Second == 0 && dateTime.NanosecondOfSecond == 0) + if (dateTime is { Second: 0, NanosecondOfSecond: 0 }) { return ConstantNew(ConstructorWithMinutes, dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute); } diff --git a/src/EFCore.PG/Internal/IReadOnlyListExtensions.cs b/src/EFCore.PG/Internal/IReadOnlyListExtensions.cs index 0df45ff30..53c031578 100644 --- a/src/EFCore.PG/Internal/IReadOnlyListExtensions.cs +++ b/src/EFCore.PG/Internal/IReadOnlyListExtensions.cs @@ -9,8 +9,8 @@ public static IReadOnlyList Slice(this IReadOnlyList list, int start) private sealed class IReadOnlyListSlice : IReadOnlyList { - private IReadOnlyList _underlying; - private int _start; + private readonly IReadOnlyList _underlying; + private readonly int _start; internal IReadOnlyListSlice(IReadOnlyList underlying, int start) { diff --git a/src/EFCore.PG/Internal/NpgsqlSingletonOptions.cs b/src/EFCore.PG/Internal/NpgsqlSingletonOptions.cs index 3b057b93b..e2c6a1d84 100644 --- a/src/EFCore.PG/Internal/NpgsqlSingletonOptions.cs +++ b/src/EFCore.PG/Internal/NpgsqlSingletonOptions.cs @@ -94,7 +94,6 @@ public virtual void Initialize(IDbContextOptions options) public virtual void Validate(IDbContextOptions options) { var npgsqlOptions = options.FindExtension() ?? new(); - var coreOptions = options.FindExtension() ?? new(); if (PostgresVersion != npgsqlOptions.PostgresVersion) { diff --git a/src/EFCore.PG/Metadata/Conventions/NpgsqlPostgresModelFinalizingConvention.cs b/src/EFCore.PG/Metadata/Conventions/NpgsqlPostgresModelFinalizingConvention.cs index ec83cb4c7..6d6695649 100644 --- a/src/EFCore.PG/Metadata/Conventions/NpgsqlPostgresModelFinalizingConvention.cs +++ b/src/EFCore.PG/Metadata/Conventions/NpgsqlPostgresModelFinalizingConvention.cs @@ -71,8 +71,7 @@ protected virtual void DiscoverPostgresExtensions( /// protected virtual void ProcessRowVersionProperty(IConventionProperty property, RelationalTypeMapping typeMapping) { - if (property.ValueGenerated == ValueGenerated.OnAddOrUpdate - && property.IsConcurrencyToken + if (property is { ValueGenerated: ValueGenerated.OnAddOrUpdate, IsConcurrencyToken: true } && typeMapping.StoreType == "xid") { property.Builder.HasColumnName("xmin"); diff --git a/src/EFCore.PG/Metadata/Internal/NpgsqlAnnotationProvider.cs b/src/EFCore.PG/Metadata/Internal/NpgsqlAnnotationProvider.cs index 72789148c..b4cfed4e9 100644 --- a/src/EFCore.PG/Metadata/Internal/NpgsqlAnnotationProvider.cs +++ b/src/EFCore.PG/Metadata/Internal/NpgsqlAnnotationProvider.cs @@ -86,8 +86,7 @@ public override IEnumerable For(IColumn column, bool designTime) var valueGenerationStrategy = valueGeneratedProperty.GetValueGenerationStrategy(); yield return new Annotation(NpgsqlAnnotationNames.ValueGenerationStrategy, valueGenerationStrategy); - if (valueGenerationStrategy == NpgsqlValueGenerationStrategy.IdentityByDefaultColumn || - valueGenerationStrategy == NpgsqlValueGenerationStrategy.IdentityAlwaysColumn) + if (valueGenerationStrategy is NpgsqlValueGenerationStrategy.IdentityByDefaultColumn or NpgsqlValueGenerationStrategy.IdentityAlwaysColumn) { if (valueGeneratedProperty[NpgsqlAnnotationNames.IdentityOptions] is string identityOptions) { diff --git a/src/EFCore.PG/Metadata/PostgresExtension.cs b/src/EFCore.PG/Metadata/PostgresExtension.cs index 7b0899054..a91a5f0e1 100644 --- a/src/EFCore.PG/Metadata/PostgresExtension.cs +++ b/src/EFCore.PG/Metadata/PostgresExtension.cs @@ -192,7 +192,7 @@ private static (string? Schema, string? Name, string? Version) Deserialize(IAnno } // TODO: Can't actually use schema and name...they might not be set when this is first called. - var schemaNameValue = value.Split(',').Select(x => x.Trim()).Select(x => x == "" || x == "''" ? null : x).ToArray(); + var schemaNameValue = value.Split(',').Select(x => x.Trim()).Select(x => x is "" or "''" ? null : x).ToArray(); var schemaAndName = annotation.Name.Substring(NpgsqlAnnotationNames.PostgresExtensionPrefix.Length).Split('.'); switch (schemaAndName.Length) { diff --git a/src/EFCore.PG/Migrations/NpgsqlMigrationsSqlGenerator.cs b/src/EFCore.PG/Migrations/NpgsqlMigrationsSqlGenerator.cs index 21c28de80..d1ddb1ccb 100644 --- a/src/EFCore.PG/Migrations/NpgsqlMigrationsSqlGenerator.cs +++ b/src/EFCore.PG/Migrations/NpgsqlMigrationsSqlGenerator.cs @@ -169,7 +169,7 @@ protected override void Generate( builder.Append("CREATE "); - if (operation[NpgsqlAnnotationNames.UnloggedTable] is bool unlogged && unlogged) + if (operation[NpgsqlAnnotationNames.UnloggedTable] is true) { builder.Append("UNLOGGED "); } @@ -312,8 +312,8 @@ protected override void Generate(AlterTableOperation operation, IModel? model, M } // Unlogged table (null is equivalent to false) - var oldUnlogged = operation.OldTable[NpgsqlAnnotationNames.UnloggedTable] is bool ou && ou; - var newUnlogged = operation[NpgsqlAnnotationNames.UnloggedTable] is bool nu && nu; + var oldUnlogged = operation.OldTable[NpgsqlAnnotationNames.UnloggedTable] is true; + var newUnlogged = operation[NpgsqlAnnotationNames.UnloggedTable] is true; if (oldUnlogged != newUnlogged) { @@ -511,14 +511,14 @@ protected override void Generate(AlterColumnOperation operation, IModel? model, builder.AppendLine(";"); } - if (operation.IsNullable && !operation.OldColumn.IsNullable) + if (operation is { IsNullable: true, OldColumn.IsNullable: false }) { builder .Append(alterBase) .Append("DROP NOT NULL") .AppendLine(";"); } - else if (!operation.IsNullable && operation.OldColumn.IsNullable) + else if (operation is { IsNullable: false, OldColumn.IsNullable: true }) { // The column is being made non-nullable. Generate an update statement before doing that, to convert any existing null values to // the default value (otherwise PostgreSQL fails). @@ -2046,7 +2046,7 @@ private string IndexColumnList(IndexColumn[] columns, string? method) // Of the built-in access methods, only btree (the default) supports // sorting, thus we only want to emit sort options for btree indexes. - if (method is null || method == "btree") + if (method is null or "btree") { if (column.IsDescending) { diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlArrayMethodTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlArrayMethodTranslator.cs index a69714cb7..45e7169b9 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlArrayMethodTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlArrayMethodTranslator.cs @@ -17,7 +17,7 @@ public class NpgsqlArrayMethodTranslator : IMethodCallTranslator // ReSharper disable InconsistentNaming private static readonly MethodInfo Array_IndexOf1 = typeof(Array).GetTypeInfo().GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly) - .Single(m => m.Name == nameof(Array.IndexOf) && m.IsGenericMethod && m.GetParameters().Length == 2); + .Single(m => m is { Name: nameof(Array.IndexOf), IsGenericMethod: true } && m.GetParameters().Length == 2); private static readonly MethodInfo Array_IndexOf2 = typeof(Array).GetTypeInfo().GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly) diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlJsonDbFunctionsTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlJsonDbFunctionsTranslator.cs index c135c4f4b..01211b992 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlJsonDbFunctionsTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlJsonDbFunctionsTranslator.cs @@ -79,7 +79,7 @@ public NpgsqlJsonDbFunctionsTranslator( } // The following are jsonb-only, not support on json - if (args.Any(a => a.TypeMapping is NpgsqlJsonTypeMapping jsonMapping && !jsonMapping.IsJsonb)) + if (args.Any(a => a.TypeMapping is NpgsqlJsonTypeMapping { IsJsonb: false })) { throw new InvalidOperationException("JSON methods on EF.Functions only support the jsonb type, not json."); } @@ -109,8 +109,7 @@ SqlExpression Jsonb(SqlExpression e) static SqlExpression RemoveConvert(SqlExpression e) { - while (e is SqlUnaryExpression unary && - (unary.OperatorType == ExpressionType.Convert || unary.OperatorType == ExpressionType.ConvertChecked)) + while (e is SqlUnaryExpression { OperatorType: ExpressionType.Convert or ExpressionType.ConvertChecked } unary) { e = unary.Operand; } diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlJsonDomTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlJsonDomTranslator.cs index 79fdc6733..d1f6e07a7 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlJsonDomTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlJsonDomTranslator.cs @@ -75,8 +75,7 @@ public NpgsqlJsonDomTranslator( } if (member == RootElement && - instance is ColumnExpression column && - column.TypeMapping is NpgsqlJsonTypeMapping) + instance is ColumnExpression { TypeMapping: NpgsqlJsonTypeMapping } column) { // Simply get rid of the RootElement member access return column; diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlLikeTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlLikeTranslator.cs index ef892e43e..7c2bdbacc 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlLikeTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlLikeTranslator.cs @@ -76,9 +76,8 @@ public NpgsqlLikeTranslator(NpgsqlSqlExpressionFactory sqlExpressionFactory) var (match, pattern) = (arguments[1], arguments[2]); - if (pattern is SqlConstantExpression constantPattern && - constantPattern.Value is string patternValue && - !patternValue.Contains("\\")) + if (pattern is SqlConstantExpression { Value: string patternValue } + && !patternValue.Contains('\\')) { return sensitive ? _sqlExpressionFactory.Like(match, pattern) @@ -89,4 +88,4 @@ constantPattern.Value is string patternValue && ? _sqlExpressionFactory.Like(match, pattern, _sqlExpressionFactory.Constant(string.Empty)) : _sqlExpressionFactory.ILike(match, pattern, _sqlExpressionFactory.Constant(string.Empty)); } -} \ No newline at end of file +} diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlObjectToStringTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlObjectToStringTranslator.cs index 32694745a..94df91dee 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlObjectToStringTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlObjectToStringTranslator.cs @@ -67,7 +67,7 @@ public NpgsqlObjectToStringTranslator(IRelationalTypeMappingSource typeMappingSo if (instance.Type == typeof(bool)) { - return instance is ColumnExpression columnExpression && columnExpression.IsNullable + return instance is ColumnExpression { IsNullable: true } ? _sqlExpressionFactory.Case( new[] { diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlRangeTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlRangeTranslator.cs index 75d24b67d..5179dd4fe 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlRangeTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlRangeTranslator.cs @@ -144,7 +144,7 @@ public NpgsqlRangeTranslator( return null; } - if (member.Name == nameof(NpgsqlRange.LowerBound) || member.Name == nameof(NpgsqlRange.UpperBound)) + if (member.Name is nameof(NpgsqlRange.LowerBound) or nameof(NpgsqlRange.UpperBound)) { var typeMapping = instance!.TypeMapping is NpgsqlRangeTypeMapping rangeMapping ? rangeMapping.SubtypeMapping diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlRowValueTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlRowValueTranslator.cs index fc394d3f1..b8116cb60 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlRowValueTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlRowValueTranslator.cs @@ -58,7 +58,7 @@ public NpgsqlRowValueTranslator(NpgsqlSqlExpressionFactory sqlExpressionFactory) IDiagnosticsLogger logger) { // Translate ValueTuple.Create - if (method.DeclaringType == typeof(ValueTuple) && method.IsStatic && method.Name == nameof(ValueTuple.Create)) + if (method.DeclaringType == typeof(ValueTuple) && method is { IsStatic: true, Name: nameof(ValueTuple.Create) }) { return new PostgresRowValueExpression(arguments, method.ReturnType); } diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlStringMethodTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlStringMethodTranslator.cs index 68e7845c8..8cfe1f771 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlStringMethodTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlStringMethodTranslator.cs @@ -74,10 +74,10 @@ private static readonly MethodInfo LastOrDefaultMethodInfoWithoutArgs typeof(string).GetMethod(nameof(string.Join), new[] { typeof(char), typeof(string[]) })!; private static readonly MethodInfo String_Join_generic1 = typeof(string).GetTypeInfo().GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly) - .Single(m => m.Name == nameof(string.Join) && m.IsGenericMethod && m.GetParameters().Length == 2 && m.GetParameters()[0].ParameterType == typeof(string)); + .Single(m => m is { Name: nameof(string.Join), IsGenericMethod: true } && m.GetParameters().Length == 2 && m.GetParameters()[0].ParameterType == typeof(string)); private static readonly MethodInfo String_Join_generic2 = typeof(string).GetTypeInfo().GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly) - .Single(m => m.Name == nameof(string.Join) && m.IsGenericMethod && m.GetParameters().Length == 2 && m.GetParameters()[0].ParameterType == typeof(char)); + .Single(m => m is { Name: nameof(string.Join), IsGenericMethod: true } && m.GetParameters().Length == 2 && m.GetParameters()[0].ParameterType == typeof(char)); // ReSharper restore InconsistentNaming #endregion @@ -501,7 +501,7 @@ private SqlExpression TranslateStartsEndsWith(SqlExpression instance, SqlExpress : _sqlExpressionFactory.Equal(leftRight, castPattern); } - private bool IsLikeWildChar(char c) => c == '%' || c == '_'; + private bool IsLikeWildChar(char c) => c is '%' or '_'; private string EscapeLikePattern(string pattern) { diff --git a/src/EFCore.PG/Query/Expressions/Internal/PostgresBinaryExpression.cs b/src/EFCore.PG/Query/Expressions/Internal/PostgresBinaryExpression.cs index 13ad583a8..1c28089e1 100644 --- a/src/EFCore.PG/Query/Expressions/Internal/PostgresBinaryExpression.cs +++ b/src/EFCore.PG/Query/Expressions/Internal/PostgresBinaryExpression.cs @@ -122,9 +122,7 @@ protected override void Print(ExpressionPrinter expressionPrinter) PostgresExpressionType.LTreeMatches when Right.TypeMapping?.StoreType == "lquery" || - Right.TypeMapping is NpgsqlArrayTypeMapping arrayMapping && - arrayMapping.ElementTypeMapping.StoreType == "lquery" - => "~", + Right.TypeMapping is NpgsqlArrayTypeMapping { ElementTypeMapping.StoreType: "lquery" } => "~", PostgresExpressionType.LTreeMatches when Right.TypeMapping?.StoreType == "ltxtquery" => "@", @@ -156,7 +154,7 @@ Right.TypeMapping is NpgsqlArrayTypeMapping arrayMapping && expressionPrinter.Append(")"); } - static bool RequiresBrackets(SqlExpression expression) => expression is PostgresBinaryExpression || expression is LikeExpression; + static bool RequiresBrackets(SqlExpression expression) => expression is PostgresBinaryExpression or LikeExpression; } /// diff --git a/src/EFCore.PG/Query/Internal/NpgsqlQuerySqlGenerator.cs b/src/EFCore.PG/Query/Internal/NpgsqlQuerySqlGenerator.cs index 321b16917..05ad44e8c 100644 --- a/src/EFCore.PG/Query/Internal/NpgsqlQuerySqlGenerator.cs +++ b/src/EFCore.PG/Query/Internal/NpgsqlQuerySqlGenerator.cs @@ -464,13 +464,11 @@ protected virtual Expression VisitPostgresBinary(PostgresBinaryExpression binary .Append(binaryExpression.OperatorType switch { PostgresExpressionType.Contains - when binaryExpression.Left.TypeMapping is NpgsqlInetTypeMapping || - binaryExpression.Left.TypeMapping is NpgsqlCidrTypeMapping + when binaryExpression.Left.TypeMapping is NpgsqlInetTypeMapping or NpgsqlCidrTypeMapping => ">>", PostgresExpressionType.ContainedBy - when binaryExpression.Left.TypeMapping is NpgsqlInetTypeMapping || - binaryExpression.Left.TypeMapping is NpgsqlCidrTypeMapping + when binaryExpression.Left.TypeMapping is NpgsqlInetTypeMapping or NpgsqlCidrTypeMapping => "<<", PostgresExpressionType.Contains => "@>", @@ -500,9 +498,7 @@ binaryExpression.Left.TypeMapping is NpgsqlCidrTypeMapping PostgresExpressionType.LTreeMatches when binaryExpression.Right.TypeMapping.StoreType == "lquery" || - binaryExpression.Right.TypeMapping is NpgsqlArrayTypeMapping arrayMapping && - arrayMapping.ElementTypeMapping.StoreType == "lquery" - => "~", + binaryExpression.Right.TypeMapping is NpgsqlArrayTypeMapping { ElementTypeMapping.StoreType: "lquery" } => "~", PostgresExpressionType.LTreeMatches when binaryExpression.Right.TypeMapping.StoreType == "ltxtquery" => "@", diff --git a/src/EFCore.PG/Query/Internal/NpgsqlSqlNullabilityProcessor.cs b/src/EFCore.PG/Query/Internal/NpgsqlSqlNullabilityProcessor.cs index b7c20e5c1..cefacc177 100644 --- a/src/EFCore.PG/Query/Internal/NpgsqlSqlNullabilityProcessor.cs +++ b/src/EFCore.PG/Query/Internal/NpgsqlSqlNullabilityProcessor.cs @@ -629,8 +629,7 @@ protected virtual SqlExpression VisitUnknownBinary( private static bool MayContainNulls(SqlExpression arrayExpression) { - if (arrayExpression is SqlConstantExpression constantArrayExpression && - constantArrayExpression.Value is Array constantArray) + if (arrayExpression is SqlConstantExpression { Value: Array constantArray }) { for (var i = 0; i < constantArray.Length; i++) { diff --git a/src/EFCore.PG/Query/Internal/NpgsqlSqlTranslatingExpressionVisitor.cs b/src/EFCore.PG/Query/Internal/NpgsqlSqlTranslatingExpressionVisitor.cs index 9bc1c887d..e3dc67c7d 100644 --- a/src/EFCore.PG/Query/Internal/NpgsqlSqlTranslatingExpressionVisitor.cs +++ b/src/EFCore.PG/Query/Internal/NpgsqlSqlTranslatingExpressionVisitor.cs @@ -284,28 +284,24 @@ bool TryTranslateArguments(out SqlExpression[] sqlArguments) private static Expression TryRemoveImplicitConvert(Expression expression) { - if (expression is UnaryExpression unaryExpression) + if (expression is UnaryExpression { NodeType: ExpressionType.Convert or ExpressionType.ConvertChecked } unaryExpression) { - if (unaryExpression.NodeType == ExpressionType.Convert - || unaryExpression.NodeType == ExpressionType.ConvertChecked) + var innerType = unaryExpression.Operand.Type.UnwrapNullableType(); + if (innerType.IsEnum) { - var innerType = unaryExpression.Operand.Type.UnwrapNullableType(); - if (innerType.IsEnum) - { - innerType = Enum.GetUnderlyingType(innerType); - } - var convertedType = unaryExpression.Type.UnwrapNullableType(); - - if (innerType == convertedType - || (convertedType == typeof(int) - && (innerType == typeof(byte) - || innerType == typeof(sbyte) - || innerType == typeof(char) - || innerType == typeof(short) - || innerType == typeof(ushort)))) - { - return TryRemoveImplicitConvert(unaryExpression.Operand); - } + innerType = Enum.GetUnderlyingType(innerType); + } + var convertedType = unaryExpression.Type.UnwrapNullableType(); + + if (innerType == convertedType + || (convertedType == typeof(int) + && (innerType == typeof(byte) + || innerType == typeof(sbyte) + || innerType == typeof(char) + || innerType == typeof(short) + || innerType == typeof(ushort)))) + { + return TryRemoveImplicitConvert(unaryExpression.Operand); } } diff --git a/src/EFCore.PG/Query/NpgsqlSqlExpressionFactory.cs b/src/EFCore.PG/Query/NpgsqlSqlExpressionFactory.cs index 15f99deb9..a1fc75f03 100644 --- a/src/EFCore.PG/Query/NpgsqlSqlExpressionFactory.cs +++ b/src/EFCore.PG/Query/NpgsqlSqlExpressionFactory.cs @@ -431,14 +431,9 @@ private SqlBinaryExpression ApplyTypeMappingOnSqlBinary(SqlBinaryExpression bina || leftType == typeof(TimeOnly) ) || rightType.FullName == "NodaTime.Period" - && ( - leftType.FullName == "NodaTime.LocalDateTime" - || leftType.FullName == "NodaTime.LocalDate" - || leftType.FullName == "NodaTime.LocalTime") + && leftType.FullName is "NodaTime.LocalDateTime" or "NodaTime.LocalDate" or "NodaTime.LocalTime" || rightType.FullName == "NodaTime.Duration" - && ( - leftType.FullName == "NodaTime.Instant" - || leftType.FullName == "NodaTime.ZonedDateTime")) + && leftType.FullName is "NodaTime.Instant" or "NodaTime.ZonedDateTime") { var newLeft = ApplyTypeMapping(left, typeMapping); var newRight = ApplyDefaultTypeMapping(right); diff --git a/src/EFCore.PG/Scaffolding/Internal/NpgsqlDatabaseModelFactory.cs b/src/EFCore.PG/Scaffolding/Internal/NpgsqlDatabaseModelFactory.cs index b40361059..93c3b3670 100644 --- a/src/EFCore.PG/Scaffolding/Internal/NpgsqlDatabaseModelFactory.cs +++ b/src/EFCore.PG/Scaffolding/Internal/NpgsqlDatabaseModelFactory.cs @@ -1133,7 +1133,7 @@ FROM pg_collation coll private static void AdjustDefaults(DatabaseColumn column, string systemTypeName) { var defaultValue = column.DefaultValueSql; - if (defaultValue is null || defaultValue == "(NULL)") + if (defaultValue is null or "(NULL)") { column.DefaultValueSql = null; return; @@ -1146,25 +1146,16 @@ private static void AdjustDefaults(DatabaseColumn column, string systemTypeName) if (defaultValue == "0") { - if (systemTypeName == "float4" || - systemTypeName == "float8" || - systemTypeName == "int2" || - systemTypeName == "int4" || - systemTypeName == "int8" || - systemTypeName == "money" || - systemTypeName == "numeric") + if (systemTypeName is "float4" or "float8" or "int2" or "int4" or "int8" or "money" or "numeric") { column.DefaultValueSql = null; return; } } - if (defaultValue == "0.0" || defaultValue == "'0'::numeric") + if (defaultValue is "0.0" or "'0'::numeric") { - if (systemTypeName == "numeric" || - systemTypeName == "float4" || - systemTypeName == "float8" || - systemTypeName == "money") + if (systemTypeName is "numeric" or "float4" or "float8" or "money") { column.DefaultValueSql = null; return; diff --git a/src/EFCore.PG/Storage/Internal/NpgsqlDatabaseCreator.cs b/src/EFCore.PG/Storage/Internal/NpgsqlDatabaseCreator.cs index 7bf860cd7..c289f1cd5 100644 --- a/src/EFCore.PG/Storage/Internal/NpgsqlDatabaseCreator.cs +++ b/src/EFCore.PG/Storage/Internal/NpgsqlDatabaseCreator.cs @@ -62,7 +62,7 @@ public override void Create() Dependencies.MigrationCommandExecutor .ExecuteNonQuery(CreateCreateOperations(), masterConnection); } - catch (PostgresException e) when (e.SqlState == "23505" && e.ConstraintName == "pg_database_datname_index") + catch (PostgresException e) when (e is { SqlState: "23505", ConstraintName: "pg_database_datname_index" }) { // This occurs when two connections are trying to create the same database concurrently // (happens in the tests). Simply ignore the error. @@ -82,7 +82,8 @@ public override void Create() /// public override async Task CreateAsync(CancellationToken cancellationToken = default) { - using (var masterConnection = _connection.CreateAdminConnection()) + var masterConnection = _connection.CreateAdminConnection(); + await using (masterConnection.ConfigureAwait(false)) { try { @@ -90,7 +91,7 @@ await Dependencies.MigrationCommandExecutor .ExecuteNonQueryAsync(CreateCreateOperations(), masterConnection, cancellationToken) .ConfigureAwait(false); } - catch (PostgresException e) when (e.SqlState == "23505" && e.ConstraintName == "pg_database_datname_index") + catch (PostgresException e) when (e is { SqlState: "23505", ConstraintName: "pg_database_datname_index" }) { // This occurs when two connections are trying to create the same database concurrently // (happens in the tests). Simply ignore the error. @@ -242,10 +243,7 @@ e.InnerException is AggregateException ae && return false; } catch (NpgsqlException e) when ( - e.InnerException is IOException && - e.InnerException.InnerException is SocketException socketException && - socketException.SocketErrorCode == SocketError.ConnectionReset - ) + e.InnerException is IOException { InnerException: SocketException { SocketErrorCode: SocketError.ConnectionReset } }) { // Pretty awful hack around #104 return false; @@ -295,7 +293,8 @@ public override async Task DeleteAsync(CancellationToken cancellationToken = def { ClearAllPools(); - using (var masterConnection = _connection.CreateAdminConnection()) + var masterConnection = _connection.CreateAdminConnection(); + await using (masterConnection) { await Dependencies.MigrationCommandExecutor .ExecuteNonQueryAsync(CreateDropCommands(), masterConnection, cancellationToken) @@ -327,9 +326,7 @@ public override void CreateTables() { Dependencies.MigrationCommandExecutor.ExecuteNonQuery(commands, _connection); } - catch (PostgresException e) when ( - e.SqlState == "23505" && e.ConstraintName == "pg_type_typname_nsp_index" - ) + catch (PostgresException e) when (e is { SqlState: "23505", ConstraintName: "pg_type_typname_nsp_index" }) { // This occurs when two connections are trying to create the same database concurrently // (happens in the tests). Simply ignore the error. @@ -374,9 +371,7 @@ public override async Task CreateTablesAsync(CancellationToken cancellationToken await Dependencies.MigrationCommandExecutor.ExecuteNonQueryAsync(commands, _connection, cancellationToken) .ConfigureAwait(false); } - catch (PostgresException e) when ( - e.SqlState == "23505" && e.ConstraintName == "pg_type_typname_nsp_index" - ) + catch (PostgresException e) when (e is { SqlState: "23505", ConstraintName: "pg_type_typname_nsp_index" }) { // This occurs when two connections are trying to create the same database concurrently // (happens in the tests). Simply ignore the error. diff --git a/src/Shared/Check.cs b/src/Shared/Check.cs index a14cd1abf..ec25fe76b 100644 --- a/src/Shared/Check.cs +++ b/src/Shared/Check.cs @@ -72,8 +72,7 @@ public static string NotEmpty([NotNull] string? value, [InvokerParameterName] st IReadOnlyCollection? value, [InvokerParameterName] string parameterName) { - if (!ReferenceEquals(value, null) - && (value.Count == 0)) + if (value is { Count: 0 }) { NotEmpty(parameterName, nameof(parameterName)); diff --git a/src/Shared/SharedTypeExtensions.cs b/src/Shared/SharedTypeExtensions.cs index c6893c7b6..d37c585c3 100644 --- a/src/Shared/SharedTypeExtensions.cs +++ b/src/Shared/SharedTypeExtensions.cs @@ -178,8 +178,7 @@ public static PropertyInfo GetRequiredRuntimeProperty(this Type type, string nam ?? throw new InvalidOperationException($"Could not find property '{name}' on type '{type}'"); public static bool IsInstantiable(this Type type) - => !type.IsAbstract - && !type.IsInterface + => type is { IsAbstract: false, IsInterface: false } && (!type.IsGenericType || !type.IsGenericTypeDefinition); public static Type UnwrapEnumType(this Type type) @@ -548,4 +547,4 @@ public static ConstantExpression GetDefaultValueConstant(this Type type) private static ConstantExpression GenerateDefaultValueConstant() => Expression.Constant(default(TDefault), typeof(TDefault)); -} \ No newline at end of file +} diff --git a/test/EFCore.PG.FunctionalTests/BuiltInDataTypesNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/BuiltInDataTypesNpgsqlTest.cs index 8155d9cdf..4117d3040 100644 --- a/test/EFCore.PG.FunctionalTests/BuiltInDataTypesNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/BuiltInDataTypesNpgsqlTest.cs @@ -13,7 +13,7 @@ public BuiltInDataTypesNpgsqlTest(BuiltInDataTypesNpgsqlFixture fixture, ITestOu : base(fixture) { Fixture.TestSqlLoggerFactory.Clear(); - //Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); + Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); } [Fact] diff --git a/test/EFCore.PG.FunctionalTests/BulkUpdates/FiltersInheritanceBulkUpdatesNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/BulkUpdates/FiltersInheritanceBulkUpdatesNpgsqlTest.cs index b09e1740b..860c74bae 100644 --- a/test/EFCore.PG.FunctionalTests/BulkUpdates/FiltersInheritanceBulkUpdatesNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/BulkUpdates/FiltersInheritanceBulkUpdatesNpgsqlTest.cs @@ -10,7 +10,7 @@ public FiltersInheritanceBulkUpdatesNpgsqlTest( : base(fixture) { ClearLog(); - // Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); + Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); } public override async Task Delete_where_hierarchy(bool async) diff --git a/test/EFCore.PG.FunctionalTests/BulkUpdates/InheritanceBulkUpdatesNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/BulkUpdates/InheritanceBulkUpdatesNpgsqlTest.cs index 0a5c60f8a..4d364fed9 100644 --- a/test/EFCore.PG.FunctionalTests/BulkUpdates/InheritanceBulkUpdatesNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/BulkUpdates/InheritanceBulkUpdatesNpgsqlTest.cs @@ -10,7 +10,7 @@ public InheritanceBulkUpdatesNpgsqlTest( : base(fixture) { ClearLog(); - // Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); + Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); } public override async Task Delete_where_hierarchy(bool async) diff --git a/test/EFCore.PG.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesNpgsqlTest.cs index 77b9facab..56fbbec15 100644 --- a/test/EFCore.PG.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesNpgsqlTest.cs @@ -11,7 +11,7 @@ public NorthwindBulkUpdatesNpgsqlTest( : base(fixture) { ClearLog(); - // Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); + Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); } public override async Task Delete_Where_TagWith(bool async) diff --git a/test/EFCore.PG.FunctionalTests/BulkUpdates/TPCFiltersInheritanceBulkUpdatesNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/BulkUpdates/TPCFiltersInheritanceBulkUpdatesNpgsqlTest.cs index b41aabb9b..7f5fae808 100644 --- a/test/EFCore.PG.FunctionalTests/BulkUpdates/TPCFiltersInheritanceBulkUpdatesNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/BulkUpdates/TPCFiltersInheritanceBulkUpdatesNpgsqlTest.cs @@ -11,7 +11,7 @@ public TPCFiltersInheritanceBulkUpdatesNpgsqlTest( : base(fixture) { ClearLog(); - // Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); + Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); } public override async Task Delete_where_hierarchy(bool async) diff --git a/test/EFCore.PG.FunctionalTests/BulkUpdates/TPCInheritanceBulkUpdatesNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/BulkUpdates/TPCInheritanceBulkUpdatesNpgsqlTest.cs index 58a9d0108..97061ae80 100644 --- a/test/EFCore.PG.FunctionalTests/BulkUpdates/TPCInheritanceBulkUpdatesNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/BulkUpdates/TPCInheritanceBulkUpdatesNpgsqlTest.cs @@ -11,7 +11,7 @@ public TPCInheritanceBulkUpdatesNpgsqlTest( : base(fixture) { ClearLog(); - // Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); + Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); } public override async Task Delete_where_hierarchy(bool async) diff --git a/test/EFCore.PG.FunctionalTests/BulkUpdates/TPTFiltersInheritanceBulkUpdatesNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/BulkUpdates/TPTFiltersInheritanceBulkUpdatesNpgsqlTest.cs index 89bc6c5b1..1fce258be 100644 --- a/test/EFCore.PG.FunctionalTests/BulkUpdates/TPTFiltersInheritanceBulkUpdatesNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/BulkUpdates/TPTFiltersInheritanceBulkUpdatesNpgsqlTest.cs @@ -11,7 +11,7 @@ public TPTFiltersInheritanceBulkUpdatesSqlServerTest( : base(fixture) { ClearLog(); - // Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); + Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); } public override async Task Delete_where_hierarchy(bool async) diff --git a/test/EFCore.PG.FunctionalTests/BulkUpdates/TPTInheritanceBulkUpdatesNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/BulkUpdates/TPTInheritanceBulkUpdatesNpgsqlTest.cs index 189e70269..fa072b11d 100644 --- a/test/EFCore.PG.FunctionalTests/BulkUpdates/TPTInheritanceBulkUpdatesNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/BulkUpdates/TPTInheritanceBulkUpdatesNpgsqlTest.cs @@ -10,7 +10,7 @@ public TPTInheritanceBulkUpdatesNpgsqlTest( : base(fixture) { ClearLog(); - // Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); + Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); } public override async Task Delete_where_hierarchy(bool async) diff --git a/test/EFCore.PG.FunctionalTests/ExecutionStrategyTest.cs b/test/EFCore.PG.FunctionalTests/ExecutionStrategyTest.cs index b81c9d5bc..ebd28b0c4 100644 --- a/test/EFCore.PG.FunctionalTests/ExecutionStrategyTest.cs +++ b/test/EFCore.PG.FunctionalTests/ExecutionStrategyTest.cs @@ -189,7 +189,7 @@ private async Task Test_commit_failure_async( { CleanContext(); - using (var context = CreateContext()) + await using (var context = CreateContext()) { var connection = (TestNpgsqlConnection)context.GetService(); @@ -218,7 +218,7 @@ private async Task Test_commit_failure_async( Assert.Equal(realFailure ? 3 : 2, connection.OpenCount); } - using (var context = CreateContext()) + await using (var context = CreateContext()) { Assert.Equal(1, await context.Products.CountAsync()); } @@ -268,7 +268,7 @@ public async Task Retries_SaveChanges_on_execution_failure( { CleanContext(); - using (var context = CreateContext()) + await using (var context = CreateContext()) { var connection = (TestNpgsqlConnection)context.GetService(); @@ -357,7 +357,7 @@ public async Task Retries_SaveChanges_on_execution_failure( Assert.Equal(ConnectionState.Closed, context.Database.GetDbConnection().State); } - using (var context = CreateContext()) + await using (var context = CreateContext()) { Assert.Equal(2, context.Products.Count()); } @@ -369,7 +369,7 @@ public async Task Retries_query_on_execution_failure(bool externalStrategy, bool { CleanContext(); - using (var context = CreateContext()) + await using (var context = CreateContext()) { context.Products.Add(new Product()); context.Products.Add(new Product()); @@ -377,7 +377,7 @@ public async Task Retries_query_on_execution_failure(bool externalStrategy, bool context.SaveChanges(); } - using (var context = CreateContext()) + await using (var context = CreateContext()) { var connection = (TestNpgsqlConnection)context.GetService(); @@ -425,7 +425,7 @@ public async Task Retries_FromSqlRaw_on_execution_failure(bool externalStrategy, { CleanContext(); - using (var context = CreateContext()) + await using (var context = CreateContext()) { context.Products.Add(new Product()); context.Products.Add(new Product()); @@ -433,7 +433,7 @@ public async Task Retries_FromSqlRaw_on_execution_failure(bool externalStrategy, context.SaveChanges(); } - using (var context = CreateContext()) + await using (var context = CreateContext()) { var connection = (TestNpgsqlConnection)context.GetService(); @@ -489,7 +489,7 @@ public async Task Retries_FromSqlRaw_on_execution_failure(bool externalStrategy, [MemberData(nameof(DataGenerator.GetBoolCombinations), 2, MemberType = typeof(DataGenerator))] public async Task Retries_OpenConnection_on_execution_failure(bool externalStrategy, bool async) { - using var context = CreateContext(); + await using var context = CreateContext(); var connection = (TestNpgsqlConnection)context.GetService(); connection.OpenFailures.Enqueue(new bool?[] { true }); @@ -542,7 +542,7 @@ public async Task Retries_OpenConnection_on_execution_failure(bool externalStrat [InlineData(true)] public async Task Retries_BeginTransaction_on_execution_failure(bool async) { - using var context = CreateContext(); + await using var context = CreateContext(); var connection = (TestNpgsqlConnection)context.GetService(); connection.OpenFailures.Enqueue(new bool?[] { true }); diff --git a/test/EFCore.PG.FunctionalTests/ExistingConnectionTest.cs b/test/EFCore.PG.FunctionalTests/ExistingConnectionTest.cs index b501d9552..75ecc08a7 100644 --- a/test/EFCore.PG.FunctionalTests/ExistingConnectionTest.cs +++ b/test/EFCore.PG.FunctionalTests/ExistingConnectionTest.cs @@ -20,14 +20,14 @@ private static async Task Can_use_an_existing_closed_connection_test(bool openCo .AddEntityFrameworkNpgsql() .BuildServiceProvider(); - using (var store = NpgsqlTestStore.GetNorthwindStore()) + await using (var store = NpgsqlTestStore.GetNorthwindStore()) { store.CloseConnection(); var openCount = 0; var closeCount = 0; - using (var connection = new NpgsqlConnection(store.ConnectionString)) + await using (var connection = new NpgsqlConnection(store.ConnectionString)) { if (openConnection) { @@ -46,7 +46,7 @@ private static async Task Can_use_an_existing_closed_connection_test(bool openCo } }; - using (var context = new NorthwindContext(serviceProvider, connection)) + await using (var context = new NorthwindContext(serviceProvider, connection)) { Assert.Equal(91, await context.Customers.CountAsync()); } diff --git a/test/EFCore.PG.FunctionalTests/Migrations/MigrationsInfrastructureNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Migrations/MigrationsInfrastructureNpgsqlTest.cs index 69047e0bd..7c3e8d519 100644 --- a/test/EFCore.PG.FunctionalTests/Migrations/MigrationsInfrastructureNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Migrations/MigrationsInfrastructureNpgsqlTest.cs @@ -20,7 +20,7 @@ public override void Can_get_active_provider() [ConditionalFact] public async Task Empty_Migration_Creates_Database() { - using var context = new BloggingContext( + await using var context = new BloggingContext( Fixture.TestStore.AddProviderOptions( new DbContextOptionsBuilder().EnableServiceProviderCaching(false)).Options); diff --git a/test/EFCore.PG.FunctionalTests/Migrations/MigrationsNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Migrations/MigrationsNpgsqlTest.cs index 656c3d177..43cec53bb 100644 --- a/test/EFCore.PG.FunctionalTests/Migrations/MigrationsNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Migrations/MigrationsNpgsqlTest.cs @@ -14,7 +14,7 @@ public MigrationsNpgsqlTest(MigrationsNpgsqlFixture fixture, ITestOutputHelper t : base(fixture) { Fixture.TestSqlLoggerFactory.Clear(); - // Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); + Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); } #region Table diff --git a/test/EFCore.PG.FunctionalTests/NpgsqlDatabaseCreatorTest.cs b/test/EFCore.PG.FunctionalTests/NpgsqlDatabaseCreatorTest.cs index b23363ede..5f8fa51c5 100644 --- a/test/EFCore.PG.FunctionalTests/NpgsqlDatabaseCreatorTest.cs +++ b/test/EFCore.PG.FunctionalTests/NpgsqlDatabaseCreatorTest.cs @@ -16,8 +16,8 @@ public class NpgsqlDatabaseCreatorExistsTest : NpgsqlDatabaseCreatorTest [InlineData(false, false, true)] public async Task Returns_false_when_database_does_not_exist(bool async, bool ambientTransaction, bool useCanConnect) { - using var testDatabase = NpgsqlTestStore.Create("NonExisting"); - using var context = new BloggingContext(testDatabase); + await using var testDatabase = NpgsqlTestStore.Create("NonExisting"); + await using var context = new BloggingContext(testDatabase); var creator = GetDatabaseCreator(context); await context.Database.CreateExecutionStrategy().ExecuteAsync( @@ -46,8 +46,8 @@ await context.Database.CreateExecutionStrategy().ExecuteAsync( [InlineData(false, true, true)] public async Task Returns_true_when_database_exists(bool async, bool ambientTransaction, bool useCanConnect) { - using var testDatabase = NpgsqlTestStore.GetOrCreateInitialized("ExistingBlogging"); - using var context = new BloggingContext(testDatabase); + await using var testDatabase = NpgsqlTestStore.GetOrCreateInitialized("ExistingBlogging"); + await using var context = new BloggingContext(testDatabase); var creator = GetDatabaseCreator(context); await context.Database.CreateExecutionStrategy().ExecuteAsync( @@ -79,13 +79,13 @@ public class NpgsqlDatabaseCreatorEnsureDeletedTest : NpgsqlDatabaseCreatorTest [InlineData(false, true, false)] public async Task Deletes_database(bool async, bool open, bool ambientTransaction) { - using var testDatabase = NpgsqlTestStore.CreateInitialized("EnsureDeleteBlogging"); + await using var testDatabase = NpgsqlTestStore.CreateInitialized("EnsureDeleteBlogging"); if (!open) { testDatabase.CloseConnection(); } - using var context = new BloggingContext(testDatabase); + await using var context = new BloggingContext(testDatabase); var creator = GetDatabaseCreator(context); Assert.True(async ? await creator.ExistsAsync() : creator.Exists()); @@ -118,8 +118,8 @@ await GetExecutionStrategy(testDatabase).ExecuteAsync( [InlineData(false)] private static async Task Noop_when_database_does_not_exist_test(bool async) { - using var testDatabase = NpgsqlTestStore.Create("NonExisting"); - using var context = new BloggingContext(testDatabase); + await using var testDatabase = NpgsqlTestStore.Create("NonExisting"); + await using var context = new BloggingContext(testDatabase); var creator = GetDatabaseCreator(context); Assert.False(async ? await creator.ExistsAsync() : creator.Exists()); @@ -162,8 +162,8 @@ private static async Task Creates_physical_database_and_schema_test( (bool CreateDatabase, bool Async, bool ambientTransaction) options) { var (createDatabase, async, ambientTransaction) = options; - using var testDatabase = NpgsqlTestStore.Create("EnsureCreatedTest"); - using var context = new BloggingContext(testDatabase); + await using var testDatabase = NpgsqlTestStore.Create("EnsureCreatedTest"); + await using var context = new BloggingContext(testDatabase); if (createDatabase) { testDatabase.Initialize(null, (Func)null); @@ -232,8 +232,8 @@ private static async Task Creates_physical_database_and_schema_test( [InlineData(false)] public async Task Noop_when_database_exists_and_has_schema(bool async) { - using var testDatabase = NpgsqlTestStore.CreateInitialized("InitializedBlogging"); - using var context = new BloggingContext(testDatabase); + await using var testDatabase = NpgsqlTestStore.CreateInitialized("InitializedBlogging"); + await using var context = new BloggingContext(testDatabase); context.Database.EnsureCreatedResiliently(); if (async) @@ -256,7 +256,7 @@ public class NpgsqlDatabaseCreatorHasTablesTest : NpgsqlDatabaseCreatorTest [InlineData(false)] public async Task Throws_when_database_does_not_exist(bool async) { - using var testDatabase = NpgsqlTestStore.GetOrCreate("NonExisting"); + await using var testDatabase = NpgsqlTestStore.GetOrCreate("NonExisting"); var databaseCreator = GetDatabaseCreator(testDatabase); await databaseCreator.ExecutionStrategy.ExecuteAsync( databaseCreator, @@ -275,7 +275,7 @@ await databaseCreator.ExecutionStrategy.ExecuteAsync( [InlineData(false, true)] public async Task Returns_false_when_database_exists_but_has_no_tables(bool async, bool ambientTransaction) { - using var testDatabase = NpgsqlTestStore.GetOrCreateInitialized("Empty"); + await using var testDatabase = NpgsqlTestStore.GetOrCreateInitialized("Empty"); var creator = GetDatabaseCreator(testDatabase); await GetExecutionStrategy(testDatabase).ExecuteAsync( @@ -293,7 +293,7 @@ await GetExecutionStrategy(testDatabase).ExecuteAsync( [InlineData(false, false)] public async Task Returns_true_when_database_exists_and_has_any_tables(bool async, bool ambientTransaction) { - using var testDatabase = NpgsqlTestStore.GetOrCreate("ExistingTables") + await using var testDatabase = NpgsqlTestStore.GetOrCreate("ExistingTables") .InitializeNpgsql(null, t => new BloggingContext(t), null); var creator = GetDatabaseCreator(testDatabase); @@ -313,7 +313,7 @@ await GetExecutionStrategy(testDatabase).ExecuteAsync( [RequiresPostgis] public async Task Returns_false_when_database_exists_and_has_only_postgis_tables(bool async, bool ambientTransaction) { - using var testDatabase = NpgsqlTestStore.GetOrCreateInitialized("Empty"); + await using var testDatabase = NpgsqlTestStore.GetOrCreateInitialized("Empty"); testDatabase.ExecuteNonQuery("CREATE EXTENSION IF NOT EXISTS postgis"); var creator = GetDatabaseCreator(testDatabase); @@ -336,7 +336,7 @@ public class NpgsqlDatabaseCreatorDeleteTest : NpgsqlDatabaseCreatorTest [InlineData(false, false)] public static async Task Deletes_database(bool async, bool ambientTransaction) { - using var testDatabase = NpgsqlTestStore.CreateInitialized("DeleteBlogging"); + await using var testDatabase = NpgsqlTestStore.CreateInitialized("DeleteBlogging"); testDatabase.CloseConnection(); var creator = GetDatabaseCreator(testDatabase); @@ -363,7 +363,7 @@ public static async Task Deletes_database(bool async, bool ambientTransaction) [InlineData(false)] public async Task Throws_when_database_does_not_exist(bool async) { - using var testDatabase = NpgsqlTestStore.GetOrCreate("NonExistingBlogging"); + await using var testDatabase = NpgsqlTestStore.GetOrCreate("NonExistingBlogging"); var creator = GetDatabaseCreator(testDatabase); if (async) @@ -384,8 +384,8 @@ public class NpgsqlDatabaseCreatorCreateTablesTest : NpgsqlDatabaseCreatorTest [InlineData(false, false)] public async Task Creates_schema_in_existing_database_test(bool async, bool ambientTransaction) { - using var testDatabase = NpgsqlTestStore.GetOrCreateInitialized("ExistingBlogging" + (async ? "Async" : "")); - using var context = new BloggingContext(testDatabase); + await using var testDatabase = NpgsqlTestStore.GetOrCreateInitialized("ExistingBlogging" + (async ? "Async" : "")); + await using var context = new BloggingContext(testDatabase); var creator = GetDatabaseCreator(context); using (CreateTransactionScope(ambientTransaction)) @@ -434,7 +434,7 @@ public async Task Creates_schema_in_existing_database_test(bool async, bool ambi [InlineData(false)] public async Task Throws_if_database_does_not_exist(bool async) { - using var testDatabase = NpgsqlTestStore.GetOrCreate("NonExisting"); + await using var testDatabase = NpgsqlTestStore.GetOrCreate("NonExisting"); var creator = GetDatabaseCreator(testDatabase); var errorNumber @@ -500,7 +500,7 @@ public class NpgsqlDatabaseCreatorCreateTest : NpgsqlDatabaseCreatorTest [InlineData(false, true)] public async Task Creates_physical_database_but_not_tables(bool async, bool ambientTransaction) { - using var testDatabase = NpgsqlTestStore.GetOrCreate("CreateTest"); + await using var testDatabase = NpgsqlTestStore.GetOrCreate("CreateTest"); var creator = GetDatabaseCreator(testDatabase); creator.EnsureDeleted(); @@ -538,7 +538,7 @@ await testDatabase.QueryAsync( [InlineData(false)] public async Task Throws_if_database_already_exists(bool async) { - using var testDatabase = NpgsqlTestStore.GetOrCreateInitialized("ExistingBlogging"); + await using var testDatabase = NpgsqlTestStore.GetOrCreateInitialized("ExistingBlogging"); var creator = GetDatabaseCreator(testDatabase); var ex = async diff --git a/test/EFCore.PG.FunctionalTests/OptimisticConcurrencyNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/OptimisticConcurrencyNpgsqlTest.cs index a7490faf1..48cc60baf 100644 --- a/test/EFCore.PG.FunctionalTests/OptimisticConcurrencyNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/OptimisticConcurrencyNpgsqlTest.cs @@ -31,17 +31,17 @@ protected OptimisticConcurrencyNpgsqlTestBase(TFixture fixture) [ConditionalFact] public async Task Modifying_concurrency_token_only_is_noop() { - using var c = CreateF1Context(); + await using var c = CreateF1Context(); await c.Database.CreateExecutionStrategy().ExecuteAsync( c, async context => { - using var transaction = context.Database.BeginTransaction(); + await using var transaction = context.Database.BeginTransaction(); var driver = context.Drivers.Single(d => d.CarNumber == 1); driver.Podiums = StorePodiums; var firstVersion = context.Entry(driver).Property("Version").CurrentValue; await context.SaveChangesAsync(); - using var innerContext = CreateF1Context(); + await using var innerContext = CreateF1Context(); innerContext.Database.UseTransaction(transaction.GetDbTransaction()); driver = innerContext.Drivers.Single(d => d.CarNumber == 1); Assert.NotEqual(firstVersion, innerContext.Entry(driver).Property("Version").CurrentValue); @@ -50,7 +50,7 @@ await c.Database.CreateExecutionStrategy().ExecuteAsync( var secondVersion = innerContext.Entry(driver).Property("Version").CurrentValue; innerContext.Entry(driver).Property("Version").CurrentValue = firstVersion; await innerContext.SaveChangesAsync(); - using var validationContext = CreateF1Context(); + await using var validationContext = CreateF1Context(); validationContext.Database.UseTransaction(transaction.GetDbTransaction()); driver = validationContext.Drivers.Single(d => d.CarNumber == 1); Assert.Equal(secondVersion, validationContext.Entry(driver).Property("Version").CurrentValue); @@ -61,11 +61,11 @@ await c.Database.CreateExecutionStrategy().ExecuteAsync( [ConditionalFact] public async Task Database_concurrency_token_value_is_updated_for_all_sharing_entities() { - using var c = CreateF1Context(); + await using var c = CreateF1Context(); await c.Database.CreateExecutionStrategy().ExecuteAsync( c, async context => { - using var transaction = context.Database.BeginTransaction(); + await using var transaction = context.Database.BeginTransaction(); var sponsor = context.Set().Single(); var sponsorEntry = c.Entry(sponsor); var detailsEntry = sponsorEntry.Reference(s => s.Details).TargetEntry; @@ -95,11 +95,11 @@ await c.Database.CreateExecutionStrategy().ExecuteAsync( [ConditionalFact] public async Task Original_concurrency_token_value_is_used_when_replacing_owned_instance() { - using var c = CreateF1Context(); + await using var c = CreateF1Context(); await c.Database.CreateExecutionStrategy().ExecuteAsync( c, async context => { - using var transaction = context.Database.BeginTransaction(); + await using var transaction = context.Database.BeginTransaction(); var sponsor = context.Set().Single(); var sponsorEntry = c.Entry(sponsor); var sponsorVersion = sponsorEntry.Property("Version").CurrentValue; diff --git a/test/EFCore.PG.FunctionalTests/Query/ArrayArrayQueryTest.cs b/test/EFCore.PG.FunctionalTests/Query/ArrayArrayQueryTest.cs index 8f54f70fc..528c95e87 100644 --- a/test/EFCore.PG.FunctionalTests/Query/ArrayArrayQueryTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/ArrayArrayQueryTest.cs @@ -681,7 +681,7 @@ await AssertQuery( public override async Task Any_like_anonymous(bool async) { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); var patternsActual = new[] { "a%", "b%", "c%" }; var patternsExpected = new[] { "a", "b", "c" }; diff --git a/test/EFCore.PG.FunctionalTests/Query/ArrayQueryTest.cs b/test/EFCore.PG.FunctionalTests/Query/ArrayQueryTest.cs index 47683b80a..e6dd0fc43 100644 --- a/test/EFCore.PG.FunctionalTests/Query/ArrayQueryTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/ArrayQueryTest.cs @@ -411,7 +411,7 @@ public async Task New_array_with_heterogeneous_columns_throws(bool async) // Note that arrays of objects are treated specially by EF Core, so they're fine. // The below checks Bytea and ByteArray, which are the same CLR type (byte[]) but mapped to different PG types // (bytea and smallint[]) - using var context = CreateContext(); + await using var context = CreateContext(); var exception = async ? await Assert.ThrowsAsync( diff --git a/test/EFCore.PG.FunctionalTests/Query/EnumQueryTest.cs b/test/EFCore.PG.FunctionalTests/Query/EnumQueryTest.cs index 6f9516b90..7e21ea123 100644 --- a/test/EFCore.PG.FunctionalTests/Query/EnumQueryTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/EnumQueryTest.cs @@ -30,7 +30,7 @@ public void Roundtrip() [MemberData(nameof(IsAsyncData))] public async Task Where_with_constant(bool async) { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); await AssertQuery( async, @@ -49,7 +49,7 @@ FROM test."SomeEntities" AS s [MemberData(nameof(IsAsyncData))] public async Task Where_with_constant_schema_qualified(bool async) { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); await AssertQuery( async, @@ -68,7 +68,7 @@ FROM test."SomeEntities" AS s [MemberData(nameof(IsAsyncData))] public async Task Where_with_parameter(bool async) { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); var sad = MappedEnum.Sad; await AssertQuery( @@ -90,7 +90,7 @@ FROM test."SomeEntities" AS s [MemberData(nameof(IsAsyncData))] public async Task Where_with_unmapped_enum_parameter_downcasts_are_implicit(bool async) { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); var sad = UnmappedEnum.Sad; await AssertQuery( @@ -112,7 +112,7 @@ FROM test."SomeEntities" AS s [MemberData(nameof(IsAsyncData))] public async Task Where_with_unmapped_enum_parameter_downcasts_do_not_matter(bool async) { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); var sad = UnmappedEnum.Sad; await AssertQuery( @@ -134,7 +134,7 @@ FROM test."SomeEntities" AS s [MemberData(nameof(IsAsyncData))] public async Task Where_with_mapped_enum_parameter_downcasts_do_not_matter(bool async) { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); var sad = MappedEnum.Sad; await AssertQuery( @@ -156,7 +156,7 @@ FROM test."SomeEntities" AS s [MemberData(nameof(IsAsyncData))] public async Task Enum_ToString(bool async) { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); await AssertQuery( async, @@ -177,7 +177,7 @@ WHERE strpos(s."MappedEnum"::text, 'sa') > 0 [MemberData(nameof(IsAsyncData))] public async Task Where_byte_enum_array_contains_enum(bool async) { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); var values = new[] { ByteEnum.Sad }; await AssertQuery( @@ -199,7 +199,7 @@ FROM test."SomeEntities" AS s [MemberData(nameof(IsAsyncData))] public async Task Where_unmapped_byte_enum_array_contains_enum(bool async) { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); var values = new[] { UnmappedByteEnum.Sad }; await AssertQuery( diff --git a/test/EFCore.PG.FunctionalTests/Query/FromSqlQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/FromSqlQueryNpgsqlTest.cs index 03d1d96a8..4713f3418 100644 --- a/test/EFCore.PG.FunctionalTests/Query/FromSqlQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/FromSqlQueryNpgsqlTest.cs @@ -28,7 +28,7 @@ public override async Task FromSqlInterpolated_queryable_multiple_composed_with_ var startDate = new NpgsqlParameter { Value = new DateTime(1997, 1, 1), NpgsqlDbType = NpgsqlDbType.Timestamp }; var endDate = new NpgsqlParameter { Value = new DateTime(1998, 1, 1), NpgsqlDbType = NpgsqlDbType.Timestamp }; - using var context = CreateContext(); + await using var context = CreateContext(); var query = from c in context.Set().FromSqlRaw( NormalizeDelimitersInRawString("SELECT * FROM [Customers] WHERE [City] = {0}"), city) @@ -74,7 +74,7 @@ public override async Task FromSql_queryable_multiple_composed_with_parameters_a var startDate = new NpgsqlParameter { Value = new DateTime(1997, 1, 1), NpgsqlDbType = NpgsqlDbType.Timestamp }; var endDate = new NpgsqlParameter { Value = new DateTime(1998, 1, 1), NpgsqlDbType = NpgsqlDbType.Timestamp }; - using var context = CreateContext(); + await using var context = CreateContext(); var query = from c in context.Set().FromSqlRaw( NormalizeDelimitersInRawString("SELECT * FROM [Customers] WHERE [City] = {0}"), city) @@ -118,7 +118,7 @@ public override async Task FromSqlRaw_queryable_multiple_composed_with_parameter var startDate = new NpgsqlParameter { Value = new DateTime(1997, 1, 1), NpgsqlDbType = NpgsqlDbType.Timestamp }; var endDate = new NpgsqlParameter { Value = new DateTime(1998, 1, 1), NpgsqlDbType = NpgsqlDbType.Timestamp }; - using var context = CreateContext(); + await using var context = CreateContext(); var query = from c in context.Set().FromSqlRaw( NormalizeDelimitersInRawString("SELECT * FROM [Customers] WHERE [City] = {0}"), city) from o in context.Set().FromSqlRaw( @@ -161,7 +161,7 @@ public override async Task FromSqlRaw_queryable_multiple_composed_with_closure_p var startDate = new NpgsqlParameter { Value = new DateTime(1997, 1, 1), NpgsqlDbType = NpgsqlDbType.Timestamp }; var endDate = new NpgsqlParameter { Value = new DateTime(1998, 1, 1), NpgsqlDbType = NpgsqlDbType.Timestamp }; - using var context = CreateContext(); + await using var context = CreateContext(); var query = from c in context.Set().FromSqlRaw(NormalizeDelimitersInRawString("SELECT * FROM [Customers]")) from o in context.Set().FromSqlRaw( NormalizeDelimitersInRawString("SELECT * FROM [Orders] WHERE [OrderDate] BETWEEN {0} AND {1}"), diff --git a/test/EFCore.PG.FunctionalTests/Query/GearsOfWarQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/GearsOfWarQueryNpgsqlTest.cs index 9d856fa11..df2be04dd 100644 --- a/test/EFCore.PG.FunctionalTests/Query/GearsOfWarQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/GearsOfWarQueryNpgsqlTest.cs @@ -708,7 +708,7 @@ await AssertQuery( public virtual async Task TimeOnly_FromTimeSpan() { // We cannot evaluate TimeOnly.FromTimeSpan in .NET since there are some rows were the result is a day or more. - using var ctx = CreateContext(); + await using var ctx = CreateContext(); var id = (await ctx.Set().Where(m => TimeOnly.FromTimeSpan(m.Duration) == new TimeOnly(1, 2, 3)).SingleAsync()).Id; Assert.Equal(1, id); diff --git a/test/EFCore.PG.FunctionalTests/Query/LegacyTimestampQueryTest.cs b/test/EFCore.PG.FunctionalTests/Query/LegacyTimestampQueryTest.cs index 96c6f620d..82884ec86 100644 --- a/test/EFCore.PG.FunctionalTests/Query/LegacyTimestampQueryTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/LegacyTimestampQueryTest.cs @@ -34,7 +34,7 @@ public void DateTime_maps_to_timestamp_by_default() [ConditionalFact] public virtual async Task Where_datetime_now() { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); // Because we can't play around with the LegacyTimestampBehavior flag at the ADO level (different assembly already compile in // RELEASE), we need to make the ADO layer happy by sending a UTC DateTime - but it should be the same with non-UTC in legacy. @@ -55,7 +55,7 @@ WHERE now() <> @__myDatetime_0 [ConditionalFact] public virtual async Task Where_datetime_utcnow() { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); var myDatetime = new DateTime(2015, 4, 10); diff --git a/test/EFCore.PG.FunctionalTests/Query/NorthwindFunctionsQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/NorthwindFunctionsQueryNpgsqlTest.cs index 288ffba5d..a2b0d11ff 100644 --- a/test/EFCore.PG.FunctionalTests/Query/NorthwindFunctionsQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/NorthwindFunctionsQueryNpgsqlTest.cs @@ -437,7 +437,7 @@ GROUP BY c."City" [MemberData(nameof(IsAsyncData))] public virtual async Task GroupBy_ArrayAgg(bool async) { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); var query = ctx.Set() .GroupBy(c => c.City) @@ -473,7 +473,7 @@ GROUP BY c."City" [MemberData(nameof(IsAsyncData))] public virtual async Task GroupBy_JsonAgg(bool async) { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); var query = ctx.Set() .GroupBy(c => c.City) @@ -509,7 +509,7 @@ GROUP BY c."City" [MemberData(nameof(IsAsyncData))] public virtual async Task GroupBy_JsonbAgg(bool async) { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); var query = ctx.Set() .GroupBy(c => c.City) @@ -549,7 +549,7 @@ GROUP BY c."City" [MemberData(nameof(IsAsyncData))] public virtual async Task GroupBy_JsonObjectAgg(bool async) { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); var query = ctx.Set() .GroupBy(c => c.City) @@ -585,7 +585,7 @@ GROUP BY c."City" [MemberData(nameof(IsAsyncData))] public virtual async Task GroupBy_JsonObjectAgg_as_Dictionary(bool async) { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); var query = ctx.Set() .GroupBy(c => c.City) @@ -627,7 +627,7 @@ GROUP BY c."City" [MemberData(nameof(IsAsyncData))] public virtual async Task GroupBy_JsonbObjectAgg(bool async) { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); // Note that unlike with json, jsonb doesn't guarantee ordering; so we parse the JSON string client-side. var query = ctx.Set() @@ -670,7 +670,7 @@ GROUP BY c."City" [MemberData(nameof(IsAsyncData))] public virtual async Task GroupBy_JsonbObjectAgg_as_Dictionary(bool async) { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); var query = ctx.Set() .GroupBy(c => c.City) diff --git a/test/EFCore.PG.FunctionalTests/Query/NorthwindMiscellaneousQueryNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Query/NorthwindMiscellaneousQueryNpgsqlTest.cs index 8213d5540..ccc412f82 100644 --- a/test/EFCore.PG.FunctionalTests/Query/NorthwindMiscellaneousQueryNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/NorthwindMiscellaneousQueryNpgsqlTest.cs @@ -279,7 +279,7 @@ await AssertQuery( [MemberData(nameof(IsAsyncData))] public async Task Array_Any_Like(bool async) { - using var context = CreateContext(); + await using var context = CreateContext(); var collection = new[] { "A%", "B%", "C%" }; var query = context.Set().Where(c => collection.Any(y => EF.Functions.Like(c.Address, y))); @@ -305,7 +305,7 @@ public async Task Array_Any_Like(bool async) [MemberData(nameof(IsAsyncData))] public async Task Array_All_Like(bool async) { - using var context = CreateContext(); + await using var context = CreateContext(); var collection = new[] { "A%", "B%", "C%" }; var query = context.Set().Where(c => collection.All(y => EF.Functions.Like(c.Address, y))); @@ -327,7 +327,7 @@ public async Task Array_All_Like(bool async) [MemberData(nameof(IsAsyncData))] public async Task Array_Any_ILike(bool async) { - using var context = CreateContext(); + await using var context = CreateContext(); var collection = new[] { "a%", "b%", "c%" }; var query = context.Set().Where(c => collection.Any(y => EF.Functions.ILike(c.Address, y))); @@ -353,7 +353,7 @@ public async Task Array_Any_ILike(bool async) [MemberData(nameof(IsAsyncData))] public async Task Array_All_ILike(bool async) { - using var context = CreateContext(); + await using var context = CreateContext(); var collection = new[] { "a%", "b%", "c%" }; var query = context.Set().Where(c => collection.All(y => EF.Functions.ILike(c.Address, y))); diff --git a/test/EFCore.PG.FunctionalTests/Query/TimestampQueryTest.cs b/test/EFCore.PG.FunctionalTests/Query/TimestampQueryTest.cs index 741a53013..afedfc63b 100644 --- a/test/EFCore.PG.FunctionalTests/Query/TimestampQueryTest.cs +++ b/test/EFCore.PG.FunctionalTests/Query/TimestampQueryTest.cs @@ -56,7 +56,7 @@ public void DateTime_range_maps_to_timestamptz_by_default() [ConditionalFact] public async Task Cannot_insert_utc_datetime_into_timestamp() { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); ctx.Entities.Add(new() { TimestampDateTime = DateTime.UtcNow }); var exception = await Assert.ThrowsAsync(() => ctx.SaveChangesAsync()); @@ -66,7 +66,7 @@ public async Task Cannot_insert_utc_datetime_into_timestamp() [ConditionalFact] public async Task Cannot_insert_unspecified_datetime_into_timestamptz() { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); ctx.Entities.Add(new() { TimestamptzDateTime = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Unspecified) }); var exception = await Assert.ThrowsAsync(() => ctx.SaveChangesAsync()); @@ -76,7 +76,7 @@ public async Task Cannot_insert_unspecified_datetime_into_timestamptz() [ConditionalFact] public async Task Cannot_insert_local_datetime_into_timestamptz() { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); ctx.Entities.Add(new() { TimestamptzDateTime = DateTime.Now }); var exception = await Assert.ThrowsAsync(() => ctx.SaveChangesAsync()); @@ -152,7 +152,7 @@ await AssertQuery( [ConditionalFact] public async Task Cannot_compare_timestamp_column_to_utc_DateTime_literal() { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); await Assert.ThrowsAsync( () => ctx.Entities.Where(e => e.TimestampDateTime == new DateTime(1998, 4, 12, 13, 26, 38, DateTimeKind.Utc)) @@ -162,7 +162,7 @@ await Assert.ThrowsAsync( [ConditionalFact] public async Task Cannot_compare_timestamp_column_to_utc_DateTime_parameter() { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); var dateTime = new DateTime(1998, 4, 12, 13, 26, 38, DateTimeKind.Utc); @@ -212,7 +212,7 @@ await AssertQuery( [ConditionalFact] public async Task Cannot_compare_timestamptz_column_to_local_DateTime_literal() { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); await Assert.ThrowsAsync( () => ctx.Entities.Where(e => e.TimestamptzDateTime == new DateTime(1998, 4, 12, 13, 26, 38, DateTimeKind.Local)) @@ -222,7 +222,7 @@ await Assert.ThrowsAsync( [ConditionalFact] public async Task Cannot_compare_timestamptz_column_to_local_DateTime_parameter() { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); var dateTime = new DateTime(1998, 4, 12, 13, 26, 38, DateTimeKind.Local); @@ -234,7 +234,7 @@ await Assert.ThrowsAsync( [ConditionalFact] public async Task Cannot_compare_timestamptz_column_to_unspecified_DateTime_literal() { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); await Assert.ThrowsAsync( () => ctx.Entities.Where(e => e.TimestamptzDateTime == new DateTime(1998, 4, 12, 13, 26, 38, DateTimeKind.Unspecified)) @@ -244,7 +244,7 @@ await Assert.ThrowsAsync( [ConditionalFact] public async Task Cannot_compare_timestamptz_column_to_unspecified_DateTime_parameter() { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); var dateTime = new DateTime(1998, 4, 12, 13, 26, 38, DateTimeKind.Unspecified); @@ -256,7 +256,7 @@ await Assert.ThrowsAsync( [ConditionalFact] public async Task Cannot_compare_timestamptz_column_to_timestamp_column() { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); await Assert.ThrowsAsync( () => ctx.Entities.Where(e => e.TimestamptzDateTime == e.TimestampDateTime) @@ -266,7 +266,7 @@ await Assert.ThrowsAsync( [ConditionalFact] public async Task Compare_timestamptz_column_to_timestamp_column_with_ToUniversalTime() { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); // We can't use AssertQuery since the local (expected) evaluation is dependent on the machine's timezone, which is out of // our control. @@ -287,7 +287,7 @@ SELECT count(*)::int [ConditionalFact] public async Task Compare_timestamptz_column_to_timestamp_column_with_ToLocalTime() { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); // We can't use AssertQuery since the local (expected) evaluation is dependent on the machine's timezone, which is out of // our control. @@ -613,7 +613,7 @@ await AssertQuery( [ConditionalFact] public async Task DateTime_SpecifyKind_with_parameter_kind_throws() { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); var kind = DateTimeKind.Local; @@ -649,7 +649,7 @@ await AssertQuery( [ConditionalFact] public virtual async Task Where_ConvertTimeBySystemTimeZoneId_fails_on_DateTime_timestamp_column() { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); await Assert.ThrowsAsync( () => ctx.Set().Where( @@ -662,7 +662,7 @@ public virtual async Task Where_ConvertTimeToUtc_on_DateTime_timestamp_column() { // We can't use AssertQuery since the local (expected) evaluation is dependent on the machine's timezone, which is out of // our control. - using var ctx = CreateContext(); + await using var ctx = CreateContext(); var count = await ctx.Set() .Where(e => TimeZoneInfo.ConvertTimeToUtc(e.TimestampDateTime) == new DateTime(1998, 4, 12, 13, 26, 38, DateTimeKind.Utc)) @@ -681,7 +681,7 @@ SELECT count(*)::int [ConditionalFact] public virtual async Task Where_ConvertTimeToUtc_fails_on_DateTime_timestamptz_column() { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); await Assert.ThrowsAsync( () => ctx.Set().Where( diff --git a/test/EFCore.PG.FunctionalTests/SequenceEndToEndTest.cs b/test/EFCore.PG.FunctionalTests/SequenceEndToEndTest.cs index 1f94e8c1d..78f7650a6 100644 --- a/test/EFCore.PG.FunctionalTests/SequenceEndToEndTest.cs +++ b/test/EFCore.PG.FunctionalTests/SequenceEndToEndTest.cs @@ -127,7 +127,7 @@ public async Task Can_use_sequence_end_to_end_async() .AddEntityFrameworkNpgsql() .BuildServiceProvider(); - using (var context = new BronieContext(serviceProvider, TestStore.Name)) + await using (var context = new BronieContext(serviceProvider, TestStore.Name)) { context.Database.EnsureCreatedResiliently(); } @@ -143,7 +143,7 @@ public async Task Can_use_sequence_end_to_end_async() await AddEntitiesAsync(serviceProvider, TestStore.Name); - using (var context = new BronieContext(serviceProvider, TestStore.Name)) + await using (var context = new BronieContext(serviceProvider, TestStore.Name)) { var pegasuses = await context.Pegasuses.ToListAsync(); @@ -157,7 +157,7 @@ public async Task Can_use_sequence_end_to_end_async() private static async Task AddEntitiesAsync(IServiceProvider serviceProvider, string databaseName) { - using var context = new BronieContext(serviceProvider, databaseName); + await using var context = new BronieContext(serviceProvider, databaseName); for (var i = 0; i < 10; i++) { await context.AddAsync( @@ -176,7 +176,7 @@ public async Task Can_use_sequence_end_to_end_from_multiple_contexts_concurrentl .AddEntityFrameworkNpgsql() .BuildServiceProvider(); - using (var context = new BronieContext(serviceProvider, TestStore.Name)) + await using (var context = new BronieContext(serviceProvider, TestStore.Name)) { context.Database.EnsureCreatedResiliently(); } @@ -197,7 +197,7 @@ public async Task Can_use_sequence_end_to_end_from_multiple_contexts_concurrentl await t; } - using (var context = new BronieContext(serviceProvider, TestStore.Name)) + await using (var context = new BronieContext(serviceProvider, TestStore.Name)) { var pegasuses = await context.Pegasuses.ToListAsync(); diff --git a/test/EFCore.PG.FunctionalTests/SystemColumnTest.cs b/test/EFCore.PG.FunctionalTests/SystemColumnTest.cs index d15c98e2d..8095ca2d6 100644 --- a/test/EFCore.PG.FunctionalTests/SystemColumnTest.cs +++ b/test/EFCore.PG.FunctionalTests/SystemColumnTest.cs @@ -10,7 +10,7 @@ public SystemColumnTest(SystemColumnFixture fixture, ITestOutputHelper testOutpu { Fixture = fixture; Fixture.TestSqlLoggerFactory.Clear(); - //Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); + Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); } [Fact] @@ -65,4 +65,4 @@ public class SystemColumnFixture : SharedStoreFixtureBase protected override ITestStoreFactory TestStoreFactory => NpgsqlTestStoreFactory.Instance; public TestSqlLoggerFactory TestSqlLoggerFactory => (TestSqlLoggerFactory)ListLoggerFactory; } -} \ No newline at end of file +} diff --git a/test/EFCore.PG.FunctionalTests/TestUtilities/NpgsqlTestStore.cs b/test/EFCore.PG.FunctionalTests/TestUtilities/NpgsqlTestStore.cs index 63dc89e0c..6daf5a4b2 100644 --- a/test/EFCore.PG.FunctionalTests/TestUtilities/NpgsqlTestStore.cs +++ b/test/EFCore.PG.FunctionalTests/TestUtilities/NpgsqlTestStore.cs @@ -310,7 +310,7 @@ public Task> QueryAsync(string sql, params object[] parameters private static Task> QueryAsync(DbConnection connection, string sql, object[] parameters = null) => ExecuteAsync(connection, async command => { - using (var dataReader = await command.ExecuteReaderAsync()) + await using (var dataReader = await command.ExecuteReaderAsync()) { var results = Enumerable.Empty(); while (await dataReader.ReadAsync()) @@ -374,10 +374,10 @@ private static async Task ExecuteCommandAsync( await connection.OpenAsync(); try { - using (var transaction = useTransaction ? connection.BeginTransaction() : null) + await using (var transaction = useTransaction ? connection.BeginTransaction() : null) { T result; - using (var command = CreateCommand(connection, sql, parameters)) + await using (var command = CreateCommand(connection, sql, parameters)) { result = await executeAsync(command); } diff --git a/test/EFCore.PG.FunctionalTests/TestUtilities/NpgsqlTestStoreFactory.cs b/test/EFCore.PG.FunctionalTests/TestUtilities/NpgsqlTestStoreFactory.cs index 2c217ccd2..d536d461a 100644 --- a/test/EFCore.PG.FunctionalTests/TestUtilities/NpgsqlTestStoreFactory.cs +++ b/test/EFCore.PG.FunctionalTests/TestUtilities/NpgsqlTestStoreFactory.cs @@ -2,7 +2,7 @@ public class NpgsqlTestStoreFactory : RelationalTestStoreFactory { - private string _connectionStringOptions; + private readonly string _connectionStringOptions; public static NpgsqlTestStoreFactory Instance { get; } = new(); diff --git a/test/EFCore.PG.FunctionalTests/TestUtilities/TestNpgsqlRetryingExecutionStrategy.cs b/test/EFCore.PG.FunctionalTests/TestUtilities/TestNpgsqlRetryingExecutionStrategy.cs index a7ed7b02c..a1f37a75b 100644 --- a/test/EFCore.PG.FunctionalTests/TestUtilities/TestNpgsqlRetryingExecutionStrategy.cs +++ b/test/EFCore.PG.FunctionalTests/TestUtilities/TestNpgsqlRetryingExecutionStrategy.cs @@ -51,8 +51,7 @@ protected override bool ShouldRetryOn(Exception exception) } #pragma warning restore 162 - return exception is InvalidOperationException invalidOperationException - && invalidOperationException.Message == "Internal .Net Framework Data Provider error 6."; + return exception is InvalidOperationException { Message: "Internal .Net Framework Data Provider error 6." }; } public new virtual TimeSpan? GetNextDelay(Exception lastException) diff --git a/test/EFCore.PG.FunctionalTests/TransactionNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/TransactionNpgsqlTest.cs index 190a10c1f..5e30515d2 100644 --- a/test/EFCore.PG.FunctionalTests/TransactionNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/TransactionNpgsqlTest.cs @@ -45,11 +45,11 @@ protected override DbContext CreateContextWithConnectionString() // so none of the inserts are left. public override async Task SaveChanges_can_be_used_with_no_savepoint(bool async) { - using (var context = CreateContext()) + await using (var context = CreateContext()) { context.Database.AutoSavepointsEnabled = false; - using var transaction = async + await using var transaction = async ? await context.Database.BeginTransactionAsync() : context.Database.BeginTransaction(); @@ -81,7 +81,7 @@ public override async Task SaveChanges_can_be_used_with_no_savepoint(bool async) context.Database.AutoSavepointsEnabled = true; } - using (var context = CreateContext()) + await using (var context = CreateContext()) { Assert.Equal(2, context.Set().Max(c => c.Id)); } diff --git a/test/EFCore.PG.FunctionalTests/Update/StoreValueGenerationNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/Update/StoreValueGenerationNpgsqlTest.cs index 81f99f84a..c328eb238 100644 --- a/test/EFCore.PG.FunctionalTests/Update/StoreValueGenerationNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/Update/StoreValueGenerationNpgsqlTest.cs @@ -13,7 +13,7 @@ public StoreValueGenerationNpgsqlTest(StoreValueGenerationNpgsqlFixture fixture, : base(fixture) { fixture.TestSqlLoggerFactory.Clear(); - // fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); + fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); } protected override bool ShouldCreateImplicitTransaction( diff --git a/test/EFCore.PG.FunctionalTests/ValueConvertersEndToEndNpgsqlTest.cs b/test/EFCore.PG.FunctionalTests/ValueConvertersEndToEndNpgsqlTest.cs index 9d3dd7165..5e2e0878b 100644 --- a/test/EFCore.PG.FunctionalTests/ValueConvertersEndToEndNpgsqlTest.cs +++ b/test/EFCore.PG.FunctionalTests/ValueConvertersEndToEndNpgsqlTest.cs @@ -161,7 +161,7 @@ public virtual void Properties_with_conversions_map_to_appropriately_null_column [ConditionalFact] public async Task Can_insert_and_read_back_with_value_converted_array() { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); var entity = new ValueConvertedArrayEntity { Values = new IntWrapper[] { new(8), new(9) } }; ctx.Add(entity); diff --git a/test/EFCore.PG.NodaTime.FunctionalTests/NodaTimeQueryNpgsqlTest.cs b/test/EFCore.PG.NodaTime.FunctionalTests/NodaTimeQueryNpgsqlTest.cs index 36ccd3571..a12be5d98 100644 --- a/test/EFCore.PG.NodaTime.FunctionalTests/NodaTimeQueryNpgsqlTest.cs +++ b/test/EFCore.PG.NodaTime.FunctionalTests/NodaTimeQueryNpgsqlTest.cs @@ -880,7 +880,7 @@ public Task Period_FromTicks_is_not_translated() [MemberData(nameof(IsAsyncData))] public async Task GroupBy_Property_Select_Sum_over_Period(bool async) { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); // Note: Unlike Duration, Period can't be converted to total ticks (because its absolute time varies). var query = ctx.Set() @@ -903,7 +903,7 @@ GROUP BY n."Id" [MemberData(nameof(IsAsyncData))] public async Task GroupBy_Property_Select_Average_over_Period(bool async) { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); // Note: Unlike Duration, Period can't be converted to total ticks (because its absolute time varies). var query = ctx.Set() @@ -1238,7 +1238,7 @@ WHERE @__interval_0 @> n."Instant" [MemberData(nameof(IsAsyncData))] public async Task Interval_RangeAgg(bool async) { - using var context = CreateContext(); + await using var context = CreateContext(); var query = context.NodaTimeTypes .GroupBy(x => true) @@ -1268,7 +1268,7 @@ LIMIT 2 [MemberData(nameof(IsAsyncData))] public async Task Interval_Intersect_aggregate(bool async) { - using var context = CreateContext(); + await using var context = CreateContext(); var query = context.NodaTimeTypes .GroupBy(x => true) @@ -1437,7 +1437,7 @@ await AssertQuery( [MemberData(nameof(IsAsyncData))] public async Task DateInterval_RangeAgg(bool async) { - using var context = CreateContext(); + await using var context = CreateContext(); var query = context.NodaTimeTypes .GroupBy(x => true) @@ -1466,7 +1466,7 @@ LIMIT 2 [MemberData(nameof(IsAsyncData))] public async Task DateInterval_Intersect_aggregate(bool async) { - using var context = CreateContext(); + await using var context = CreateContext(); var query = context.NodaTimeTypes .GroupBy(x => true) @@ -1599,7 +1599,7 @@ await AssertQuery( [ConditionalFact] public async Task Instance_InZone_without_LocalDateTime_fails() { - using var ctx = CreateContext(); + await using var ctx = CreateContext(); await Assert.ThrowsAsync( () => ctx.Set().Where(t => t.Instant.InZone(DateTimeZoneProviders.Tzdb["Europe/Berlin"]) == default) @@ -1884,7 +1884,7 @@ LIMIT 1 private NodaTimeContext CreateContext() => Fixture.CreateContext(); - private static Period _defaultPeriod = Period.FromYears(2018) + Period.FromMonths(4) + Period.FromDays(20) + + private static readonly Period _defaultPeriod = Period.FromYears(2018) + Period.FromMonths(4) + Period.FromDays(20) + Period.FromHours(10) + Period.FromMinutes(31) + Period.FromSeconds(23) + Period.FromMilliseconds(666); @@ -2012,9 +2012,9 @@ public IReadOnlyDictionary EntityAsserters }.ToDictionary(e => e.Key, e => (object)e.Value); } - protected class NodaTimeData : ISetSource + private class NodaTimeData : ISetSource { - public IReadOnlyList NodaTimeTypes { get; } + private IReadOnlyList NodaTimeTypes { get; } public NodaTimeData() => NodaTimeTypes = CreateNodaTimeTypes(); diff --git a/test/EFCore.PG.Tests/Storage/NpgsqlTypeMappingSourceTest.cs b/test/EFCore.PG.Tests/Storage/NpgsqlTypeMappingSourceTest.cs index 7d8cad8af..c12579fa8 100644 --- a/test/EFCore.PG.Tests/Storage/NpgsqlTypeMappingSourceTest.cs +++ b/test/EFCore.PG.Tests/Storage/NpgsqlTypeMappingSourceTest.cs @@ -302,7 +302,7 @@ public RelationalTypeMapping FindMapping(in RelationalTypeMappingInfo mappingInf ? _dummyMapping : null; - private DummyMapping _dummyMapping = new(); + private readonly DummyMapping _dummyMapping = new(); private class DummyMapping : RelationalTypeMapping {