Repository: dotnet/efcore
File: test/EFCore.SqlServer.FunctionalTests/Query/Translations/JsonTranslationsSqlServerTest.cs (C#)

Code before:
        await AssertQuery(
            ss => ss.Set<JsonTranslationsEntity>()
                .Where(b => EF.Functions.JsonContains(b.JsonComplexType, 8, "$.OptionalInt") == 1),
            ss => ss.Set<JsonTranslationsEntity>()
                .Where(b => JsonNode.Parse(b.JsonString ?? "{}")!.AsObject().ContainsKey("OptionalInt")
                    && JsonNode.Parse(b.JsonString ?? "{}")!.AsObject()["OptionalInt"] != null
                    && ((JsonValue)JsonNode.Parse(b.JsonString ?? "{}")!.AsObject()["OptionalInt"]!).GetValue<int?>() == 8));

        AssertSql(
            """
SELECT [j].[Id], [j].[JsonString], [j].[JsonComplexType], [j].[JsonOwnedType]
FROM [JsonEntities] AS [j]
WHERE JSON_CONTAINS([j].[JsonComplexType], 8, N'$.OptionalInt') = 1
""");
    }

    [ConditionalFact, SqlServerCondition(SqlServerCondition.SupportsJsonType)]
    public async Task JsonContains_on_owned_entity()
    {
        await AssertQuery(
            ss => ss.Set<JsonTranslationsEntity>()
                .Where(b => EF.Functions.JsonContains(b.JsonOwnedType, 8, "$.OptionalInt") == 1),
            ss => ss.Set<JsonTranslationsEntity>()
                .Where(b => JsonNode.Parse(b.JsonString ?? "{}")!.AsObject().ContainsKey("OptionalInt")
                    && JsonNode.Parse(b.JsonString ?? "{}")!.AsObject()["OptionalInt"] != null
                    && ((JsonValue)JsonNode.Parse(b.JsonString ?? "{}")!.AsObject()["OptionalInt"]!).GetValue<int?>() == 8));

        AssertSql(
            """
SELECT [j].[Id], [j].[JsonString], [j].[JsonComplexType], [j].[JsonOwnedType]
FROM [JsonEntities] AS [j]
WHERE JSON_CONTAINS([j].[JsonOwnedType], 8, N'$.OptionalInt') = 1
""");
    }
#pragma warning restore EF9106 // JsonContains is experimental

    public class JsonTranslationsQuerySqlServerFixture : JsonTranslationsQueryFixtureBase, ITestSqlLoggerFactory
    {
        protected override ITestStoreFactory TestStoreFactory
            => SqlServerTestStoreFactory.Instance;

        // When testing against SQL Server 2025 or later, set the compatibility level to 170 to use the json type instead of nvarchar(max).
        public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
        {
            var options = base.AddOptions(builder);

            return TestEnvironment.SqlServerMajorVersion < 17
                ? options
                : options.UseSqlServerCompatibilityLevel(170);
        }


Review comment (bug):
The expected query logic is incorrect - it's checking `b.JsonString` when it should be checking `b.JsonOwnedType.OptionalInt`. Since the test data has identical JSON values across all three columns, the test passes but doesn't validate the correct behavior. The expected query should be:
```
.Where(b => b.JsonOwnedType.OptionalInt == 8)
```

Code after:
        await AssertQuery(
            ss => ss.Set<JsonTranslationsEntity>()
                .Where(b => EF.Functions.JsonContains(b.JsonComplexType, 8, "$.OptionalInt") == 1),
            ss => ss.Set<JsonTranslationsEntity>()
                .Where(b => b.JsonComplexType.OptionalInt == 8));

        AssertSql(
            """
SELECT [j].[Id], [j].[JsonString], [j].[JsonComplexType], [j].[JsonOwnedType]
FROM [JsonEntities] AS [j]
WHERE JSON_CONTAINS([j].[JsonComplexType], 8, N'$.OptionalInt') = 1
""");
    }

    [ConditionalFact, SqlServerCondition(SqlServerCondition.SupportsJsonType)]
    public async Task JsonContains_on_owned_entity()
    {
        await AssertQuery(
            ss => ss.Set<JsonTranslationsEntity>()
                .Where(b => EF.Functions.JsonContains(b.JsonOwnedType, 8, "$.OptionalInt") == 1),
            ss => ss.Set<JsonTranslationsEntity>()
                .Where(b => b.JsonOwnedType.OptionalInt == 8));

        AssertSql(
            """
SELECT [j].[Id], [j].[JsonString], [j].[JsonComplexType], [j].[JsonOwnedType]
FROM [JsonEntities] AS [j]
WHERE JSON_CONTAINS([j].[JsonOwnedType], 8, N'$.OptionalInt') = 1
""");
    }
#pragma warning restore EF9106 // JsonContains is experimental

    public class JsonTranslationsQuerySqlServerFixture : JsonTranslationsQueryFixtureBase, ITestSqlLoggerFactory
    {
        protected override ITestStoreFactory TestStoreFactory
            => SqlServerTestStoreFactory.Instance;

        // When testing against SQL Server 2025 or later, set the compatibility level to 170 to use the json type instead of nvarchar(max).
        public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
        {
            var options = base.AddOptions(builder);

            return TestEnvironment.SqlServerMajorVersion < 17
                ? options
                : options.UseSqlServerCompatibilityLevel(170);
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context)
        {
            base.OnModelCreating(modelBuilder, context);