ronantakizawa/codereview-bench huggingface dataset:
Repository: dotnet/efcore
File: test/EFCore.SqlServer.Tests/Migrations/SqlServerModelDifferTest.cs (C#)

Code before:
                            d.Property(e => e.Viewers);
                            d.ToJson().HasColumnType("json");
                        });
                }),
            upOps =>
            {
                Assert.Equal(1, upOps.Count);

                var operation = Assert.IsType<AlterColumnOperation>(upOps[0]);
                Assert.Equal("Blog", operation.Table);
                Assert.Equal("Details", operation.Name);
                Assert.Equal("json", operation.ColumnType);
                Assert.Equal("nvarchar(max)", operation.OldColumn.ColumnType);
            },
            downOps =>
            {
                Assert.Equal(1, downOps.Count);

                var operation = Assert.IsType<AlterColumnOperation>(downOps[0]);
                Assert.Equal("Blog", operation.Table);
                Assert.Equal("Details", operation.Name);
                Assert.Equal("nvarchar(max)", operation.ColumnType);
                Assert.Equal("json", operation.OldColumn.ColumnType);
            });

    private class BlogDetails
    {
        public string Author { get; set; } = "";
        public int Viewers { get; set; }
    }
}


Review comment (suggestion):
@copilot Don't add a type for this, instead use `typeof(Dictionary<string, object>)` as a stand-in

Code after:
                            d.Property<int>("Viewers");
                            d.ToJson().HasColumnType("json");
                        });
                }),
            upOps =>
            {
                Assert.Equal(1, upOps.Count);

                var operation = Assert.IsType<AlterColumnOperation>(upOps[0]);
                Assert.Equal("Blog", operation.Table);
                Assert.Equal("Details", operation.Name);
                Assert.Equal("json", operation.ColumnType);
                Assert.Equal("nvarchar(max)", operation.OldColumn.ColumnType);
            },
            downOps =>
            {
                Assert.Equal(1, downOps.Count);

                var operation = Assert.IsType<AlterColumnOperation>(downOps[0]);
                Assert.Equal("Blog", operation.Table);
                Assert.Equal("Details", operation.Name);
                Assert.Equal("nvarchar(max)", operation.ColumnType);
                Assert.Equal("json", operation.OldColumn.ColumnType);
            });
}
Repository: dotnet/efcore
File: test/EFCore.Cosmos.FunctionalTests/Query/Associations/OwnedNavigations/OwnedNavigationsStructuralEqualityCosmosTest.cs (C#)

Code before:
""");
    }

    public override async Task Not_equals()
    {
        await base.Not_equals();

        AssertSql(
            """
SELECT VALUE c
FROM root c
WHERE false
""");
    }

    public override async Task Associate_with_inline_null()
    {
        await base.Associate_with_inline_null();

        AssertSql(
    """
SELECT VALUE c
FROM root c
WHERE (c["OptionalAssociate"] = null)
""");
    }

    public override Task Associate_with_parameter_null()
        => Assert.ThrowsAsync<InvalidOperationException>(() => base.Associate_with_parameter_null());

    public override async Task Nested_associate_with_inline_null()
    {
        await base.Nested_associate_with_inline_null();

        AssertSql(
    """
SELECT VALUE c
FROM root c
WHERE (c["RequiredAssociate"]["OptionalNestedAssociate"] = null)
""");
    }

    public override async Task Nested_associate_with_inline()
    {
        await base.Nested_associate_with_inline();

        AssertSql();
    }

    public override async Task Nested_associate_with_parameter()
    {

Review comment (suggestion):
Indentation is inconsistent with the rest of the file: the raw string literal passed to `AssertSql(...)` should be aligned like the other `AssertSql` calls (the `"""` should be indented under the argument list). This makes the baseline blocks harder to scan.

Code after:
""");
    }

    public override async Task Not_equals()
    {
        await base.Not_equals();

        AssertSql(
            """
SELECT VALUE c
FROM root c
WHERE false
""");
    }

    public override async Task Associate_with_inline_null()
    {
        await base.Associate_with_inline_null();

        AssertSql(
            """
SELECT VALUE c
FROM root c
WHERE (c["OptionalAssociate"] = null)
""");
    }

    public override Task Associate_with_parameter_null()
        => Assert.ThrowsAsync<InvalidOperationException>(() => base.Associate_with_parameter_null());

    public override async Task Nested_associate_with_inline_null()
    {
        await base.Nested_associate_with_inline_null();

        AssertSql(
            """
SELECT VALUE c
FROM root c
WHERE (c["RequiredAssociate"]["OptionalNestedAssociate"] = null)
""");
    }

    public override async Task Nested_associate_with_inline()
    {
        await base.Nested_associate_with_inline();

        AssertSql();
    }

    public override async Task Nested_associate_with_parameter()
    {
Repository: dotnet/efcore
File: test/EFCore.Cosmos.FunctionalTests/Query/Associations/OwnedNavigations/OwnedNavigationsStructuralEqualityCosmosTest.cs (C#)

Code before:
    public override async Task Associate_with_inline_null()
    {
        await base.Associate_with_inline_null();

        AssertSql(
    """
SELECT VALUE c
FROM root c
WHERE (c["OptionalAssociate"] = null)
""");
    }

    public override Task Associate_with_parameter_null()
        => Assert.ThrowsAsync<InvalidOperationException>(() => base.Associate_with_parameter_null());

    public override async Task Nested_associate_with_inline_null()
    {
        await base.Nested_associate_with_inline_null();

        AssertSql(
    """
SELECT VALUE c
FROM root c
WHERE (c["RequiredAssociate"]["OptionalNestedAssociate"] = null)
""");
    }

    public override async Task Nested_associate_with_inline()
    {
        await base.Nested_associate_with_inline();

        AssertSql();
    }

    public override async Task Nested_associate_with_parameter()
    {
        await base.Nested_associate_with_parameter();

        AssertSql();
    }

    public override async Task Two_nested_collections()
    {
        await base.Two_nested_collections();

        AssertSql(
            """
SELECT VALUE c
FROM root c
WHERE false
""");

Review comment (suggestion):
Indentation is inconsistent with the rest of the file: the raw string literal passed to `AssertSql(...)` should be aligned like the other `AssertSql` calls (indent the `"""` under the argument list).

Code after:
    public override async Task Associate_with_inline_null()
    {
        await base.Associate_with_inline_null();

        AssertSql(
            """
SELECT VALUE c
FROM root c
WHERE (c["OptionalAssociate"] = null)
""");
    }

    public override Task Associate_with_parameter_null()
        => Assert.ThrowsAsync<InvalidOperationException>(() => base.Associate_with_parameter_null());

    public override async Task Nested_associate_with_inline_null()
    {
        await base.Nested_associate_with_inline_null();

        AssertSql(
            """
SELECT VALUE c
FROM root c
WHERE (c["RequiredAssociate"]["OptionalNestedAssociate"] = null)
""");
    }

    public override async Task Nested_associate_with_inline()
    {
        await base.Nested_associate_with_inline();

        AssertSql();
    }

    public override async Task Nested_associate_with_parameter()
    {
        await base.Nested_associate_with_parameter();

        AssertSql();
    }

    public override async Task Two_nested_collections()
    {
        await base.Two_nested_collections();

        AssertSql(
            """
SELECT VALUE c
FROM root c
WHERE false
""");
Repository: dotnet/efcore
File: test/EFCore.Specification.Tests/Query/AdHocComplexTypeQueryTestBase.cs (C#)

Code before:
        {
            var entity = modelBuilder.Entity<EntityType>();
            entity.Property(p => p.Id);
            entity.HasKey(p => p.Id);

            var compl = entity.ComplexProperty(p => p.Prop);
            compl.Property(p => p.OptionalValue);
            compl.HasDiscriminator();

            // Shadow property added via convention (e.g., audit field)
            entity.Property<string>("CreatedBy").IsRequired(false);
        }

        public class EntityType
        {
            public Guid Id { get; set; }
            public OptionalComplexProperty? Prop { get; set; }
        }

        public class OptionalComplexProperty
        {
            public bool? OptionalValue { get; set; }
        }
    }

    #endregion Issue37634

    protected override string StoreName
        => "AdHocComplexTypeQueryTest";
}


Review comment (suggestion):
The region comment references "Issue37634" but should reference issue #37337 to match the actual issue being addressed in this PR. The closing region tag should match the opening tag.

Code after:
        {
            var entity = modelBuilder.Entity<EntityType>();
            entity.Property(p => p.Id);
            entity.HasKey(p => p.Id);

            var compl = entity.ComplexProperty(p => p.Prop);
            compl.Property(p => p.OptionalValue);
            compl.HasDiscriminator();

            // Shadow property added via convention (e.g., audit field)
            entity.Property<string>("CreatedBy").IsRequired(false);
        }

        public class EntityType
        {
            public Guid Id { get; set; }
            public OptionalComplexProperty? Prop { get; set; }
        }

        public class OptionalComplexProperty
        {
            public bool? OptionalValue { get; set; }
        }
    }

    #endregion Issue37337

    protected override string StoreName
        => "AdHocComplexTypeQueryTest";
}
Repository: dotnet/efcore
File: test/EFCore.Sqlite.FunctionalTests/BuiltInDataTypesSqliteTest.cs (C#)

Code before:

        var results = query
            .OrderBy(e => e.PartitionId)
            .ThenBy(e => e.TestDecimal)
            .Select(e => e.Id)
            .First();

        AssertSql(
            """
SELECT "b"."Id"
FROM "BuiltInDataTypes" AS "b"
WHERE "b"."PartitionId" = 208
ORDER BY "b"."PartitionId", "b"."TestDecimal" COLLATE EF_DECIMAL
LIMIT 1
""");

        var expectedResults = query.AsEnumerable()
            .OrderBy(e => e.PartitionId)
            .ThenBy(e => e.TestDecimal)
            .Select(e => e.Id)
            .First();

        Assert.Equal(expectedResults, results);
    }

    [ConditionalFact, UseCulture("tr-TR")]
    public virtual void Can_query_OrderBy_decimal_with_Turkish_culture()
    {
        using var context = CreateContext();
        var min = new BuiltInDataTypes
        {
            Id = 1,
            TestDecimal = 1.05m
        };
        context.Add(min);

        var middle = new BuiltInDataTypes
        {
            Id = 2,
            TestDecimal = 1.5m
        };
        context.Add(middle);

        var max = new BuiltInDataTypes
        {
            Id = 3,
            TestDecimal = 2.5m
        };
        context.Add(max);

        context.SaveChanges();

Review comment (suggestion):
```suggestion
    [ConditionalFact, UseCulture("tr-TR")] // #37432
```

Code after:

        var results = query
            .OrderBy(e => e.PartitionId)
            .ThenBy(e => e.TestDecimal)
            .Select(e => e.Id)
            .First();

        AssertSql(
            """
SELECT "b"."Id"
FROM "BuiltInDataTypes" AS "b"
WHERE "b"."PartitionId" = 208
ORDER BY "b"."PartitionId", "b"."TestDecimal" COLLATE EF_DECIMAL
LIMIT 1
""");

        var expectedResults = query.AsEnumerable()
            .OrderBy(e => e.PartitionId)
            .ThenBy(e => e.TestDecimal)
            .Select(e => e.Id)
            .First();

        Assert.Equal(expectedResults, results);
    }

    [ConditionalFact, UseCulture("tr-TR")] // #37432
    public virtual void Can_query_OrderBy_decimal_with_Turkish_culture()
    {
        using var context = CreateContext();
        var min = new BuiltInDataTypes
        {
            Id = 227,
            TestDecimal = 1.05m
        };
        context.Add(min);

        var middle = new BuiltInDataTypes
        {
            Id = 228,
            TestDecimal = 1.5m
        };
        context.Add(middle);

        var max = new BuiltInDataTypes
        {
            Id = 229,
            TestDecimal = 2.5m
        };
        context.Add(max);

        context.SaveChanges();
Repository: dotnet/efcore
File: test/EFCore.Tests/ServiceProviderCacheTest.cs (C#)

Code before:
            public override bool IsDatabaseProvider
                => false;

            public override int GetServiceProviderHashCode()
                => 0;

            public override bool ShouldUseSameServiceProvider(DbContextOptionsExtensionInfo other)
                => true;

            public override string LogFragment
                => "";

            public override void PopulateDebugInfo(IDictionary<string, string> debugInfo)
                => debugInfo["Fake2"] = "1";
        }
    }

    [ConditionalFact]
    public void Service_provider_cache_can_be_cleared()
    {
        var cache = ServiceProviderCache.Instance;
        var options = new DbContextOptionsBuilder().UseInMemoryDatabase("TestDB").Options;

        cache.GetOrAdd(options, providerRequired: false);

       
        EntityFrameworkMetrics.ClearServiceProviderCache();

        var field = typeof(ServiceProviderCache).GetField("_configurations", BindingFlags.NonPublic | BindingFlags.Instance);
        var dict = (System.Collections.IDictionary)field.GetValue(cache);

        Assert.Equal(0, dict.Count);
    }
}


Review comment (suggestion):
This line contains only whitespace. According to EF Core coding style guidelines, trailing whitespace should be trimmed.
```suggestion

```

Code after:
            public override bool IsDatabaseProvider
                => false;

            public override int GetServiceProviderHashCode()
                => 0;

            public override bool ShouldUseSameServiceProvider(DbContextOptionsExtensionInfo other)
                => true;

            public override string LogFragment
                => "";

            public override void PopulateDebugInfo(IDictionary<string, string> debugInfo)
                => debugInfo["Fake2"] = "1";
        }
    }

    [ConditionalFact]
    public void Service_provider_cache_can_be_cleared()
    {
        var cache = ServiceProviderCache.Instance;
        var options = new DbContextOptionsBuilder().UseInMemoryDatabase("TestDB").Options;

        var provider1 = cache.GetOrAdd(options, providerRequired: false);
        cache.Clear(); 

        var field = typeof(ServiceProviderCache).GetField("_configurations", BindingFlags.NonPublic | BindingFlags.Instance);
        var dict = (System.Collections.IDictionary)field.GetValue(cache);
        
        Assert.Equal(0, dict.Count);
        
        var provider2 = cache.GetOrAdd(options, providerRequired: false);
        
        Assert.NotNull(provider2);
        Assert.NotSame(provider1, provider2);
    }
}
Repository: dotnet/efcore
File: src/EFCore.SqlServer/Extensions/VectorSearchResult.cs (C#)

Code before:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;

namespace Microsoft.EntityFrameworkCore;

/// <summary>
///     Represents the results from a call to
///     <see cref="SqlServerQueryableExtensions.VectorSearch{T, TVector}(DbSet{T}, Expression{Func{T, TVector}}, TVector, string, int)" />.
/// </summary>
[Experimental(EFDiagnostics.SqlServerVectorSearch)]
public readonly struct VectorSearchResult<T>(T value, double distance)
{
    /// <summary>
    ///     The entity instance representing the row with a similar vector.
    /// </summary>
    public T Value { get; } = value;

    /// <summary>
    ///    The distance between the query vector and the similar vector.
    /// </summary>
    public double Distance { get; } = distance;

    /// <summary>
    ///     Deconstructs the result into its the returned entity and the distance.
    /// </summary>
    /// <param name="value">The entity instance representing the row with a similar vector.</param>
    /// <param name="distance">The distance between the query vector and the similar vector.</param>
    public void Deconstruct(out T value, out double distance)
    {
        value = Value;
        distance = Distance;
    }
}


Review comment (suggestion):
XML doc has a grammatical error: "into its the returned entity" should be corrected (e.g., "into the returned entity" or "into the returned value").
```suggestion
    ///     Deconstructs the result into the returned entity and the distance.
```

Code after:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;

namespace Microsoft.EntityFrameworkCore;

/// <summary>
///     Represents the results from a call to
///     <see cref="SqlServerQueryableExtensions.VectorSearch{T, TVector}(DbSet{T}, Expression{Func{T, TVector}}, TVector, string, int)" />.
/// </summary>
[Experimental(EFDiagnostics.SqlServerVectorSearch)]
public readonly struct VectorSearchResult<T>(T value, double distance)
{
    /// <summary>
    ///     The entity instance representing the row with a similar vector.
    /// </summary>
    public T Value { get; } = value;

    /// <summary>
    ///    The distance between the query vector and the similar vector.
    /// </summary>
    public double Distance { get; } = distance;

    /// <summary>
    ///     Deconstructs the result into the returned entity and the distance.
    /// </summary>
    /// <param name="value">The entity instance representing the row with a similar vector.</param>
    /// <param name="distance">The distance between the query vector and the similar vector.</param>
    public void Deconstruct(out T value, out double distance)
    {
        value = Value;
        distance = Distance;
    }
}
Repository: dotnet/efcore
File: src/ef/Commands/MigrationsRemoveCommand.cs (C#)

Code before:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections;

namespace Microsoft.EntityFrameworkCore.Tools.Commands;

// ReSharper disable once ArrangeTypeModifiers
internal partial class MigrationsRemoveCommand
{
    protected override int Execute(string[] args)
    {
        using var executor = CreateExecutor(args);
        var force = _force!.HasValue() || _offline!.HasValue();
        var result = executor.RemoveMigration(Context!.Value(), force, _connection!.Value());

        if (_json!.HasValue())
        {
            ReportJsonResults(result);
        }

        return base.Execute(args);
    }

    private static void ReportJsonResults(IDictionary result)
    {
        Reporter.WriteData("{");
        Reporter.WriteData("  \"migrationFile\": " + Json.Literal(result["MigrationFile"] as string) + ",");
        Reporter.WriteData("  \"metadataFile\": " + Json.Literal(result["MetadataFile"] as string) + ",");
        Reporter.WriteData("  \"snapshotFile\": " + Json.Literal(result["SnapshotFile"] as string));
        Reporter.WriteData("}");
    }
}


Review comment (suggestion):
@copilot Actually, `_force` and `_offline` should have different behaviors.  `_offline` shouldn't even try to connect to the database to check whether the migration has been applied

Code after:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections;
using Microsoft.EntityFrameworkCore.Tools.Properties;

namespace Microsoft.EntityFrameworkCore.Tools.Commands;

// ReSharper disable once ArrangeTypeModifiers
internal partial class MigrationsRemoveCommand
{
    protected override void Validate()
    {
        base.Validate();

        if (_offline!.HasValue() && _force!.HasValue())
        {
            throw new CommandException(Resources.OfflineForceConflict);
        }
    }

    protected override int Execute(string[] args)
    {
        using var executor = CreateExecutor(args);
        var result = executor.RemoveMigration(Context!.Value(), _force!.HasValue(), _offline!.HasValue(), _connection!.Value());

        if (_json!.HasValue())
        {
            ReportJsonResults(result);
        }

        return base.Execute(args);
    }

    private static void ReportJsonResults(IDictionary result)
    {
        Reporter.WriteData("{");
        Reporter.WriteData("  \"migrationFile\": " + Json.Literal(result["MigrationFile"] as string) + ",");
        Reporter.WriteData("  \"metadataFile\": " + Json.Literal(result["MetadataFile"] as string) + ",");
        Reporter.WriteData("  \"snapshotFile\": " + Json.Literal(result["SnapshotFile"] as string));
Repository: dotnet/efcore
File: src/ef/Commands/DatabaseDropCommand.cs (C#)

Code before:
        {
            var result = executor.GetContextInfo(Context!.Value());
            var databaseName = result["DatabaseName"] as string;
            var dataSource = result["DataSource"] as string;
            Reporter.WriteInformation(resource(databaseName, dataSource));
        }

        if (_dryRun!.HasValue())
        {
            LogDropCommand(Resources.DatabaseDropDryRun);

            return 0;
        }

        if (!_force!.HasValue())
        {
            LogDropCommand(Resources.DatabaseDropPrompt);
            var response = Console.ReadLine()!.Trim().ToUpperInvariant();
            if (response != "Y")
            {
                return 1;
            }
        }

        executor.DropDatabase(Context!.Value(), _connection!.Value());

        return base.Execute(args);
    }
}


Review comment (refactor):
With `--connection`, the command will drop the database using the provided connection string (line 41), but the prompt/dry-run messaging earlier in this method still calls `executor.GetContextInfo(...)` without that connection, so it can show a different database/server than the one actually being dropped. Consider plumbing the connection string into the context-info operation (or otherwise adjusting the prompt/dry-run output) so the user confirmation reflects the real target.

Code after:
        {
            var result = executor.GetContextInfo(Context!.Value(), _connection!.Value());
            var databaseName = result["DatabaseName"] as string;
            var dataSource = result["DataSource"] as string;
            Reporter.WriteInformation(resource(databaseName, dataSource));
        }

        if (_dryRun!.HasValue())
        {
            LogDropCommand(Resources.DatabaseDropDryRun);

            return 0;
        }

        if (!_force!.HasValue())
        {
            LogDropCommand(Resources.DatabaseDropPrompt);
            var response = Console.ReadLine()!.Trim().ToUpperInvariant();
            if (response != "Y")
            {
                return 1;
            }
        }

        executor.DropDatabase(Context!.Value(), _connection!.Value());

        return base.Execute(args);
    }
}