Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ INSERT INTO [Entities] ([Id], [Scenario], [OptionalReference], [RequiredReferenc

#region EnumLegacyValues

[ConditionalTheory, MemberData(nameof(IsAsyncData))]
[ConditionalTheory(Skip = "#36626"), MemberData(nameof(IsAsyncData))]
public virtual async Task Read_enum_property_with_legacy_values(bool async)
{
var contextFactory = await InitializeAsync<DbContext>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4905,6 +4905,6 @@ protected override string StoreName
=> "ComplexNavigations160";

public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> base.AddOptions(builder).UseSqlServer(b => b.UseCompatibilityLevel(160));
=> base.AddOptions(builder).UseSqlServerCompatibilityLevel(160);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8525,6 +8525,6 @@ protected override string StoreName
=> "ComplexNavigationsOwned160";

public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> base.AddOptions(builder).UseSqlServer(b => b.UseCompatibilityLevel(160));
=> base.AddOptions(builder).UseSqlServerCompatibilityLevel(160);
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,9 @@ private void AssertSql(params string[] expected)
public class Fixture160 : NorthwindQuerySqlServerFixture<NoopModelCustomizer>
{
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> base.AddOptions(builder).UseSqlServer(b => b.UseCompatibilityLevel(160));
{
var options = base.AddOptions(builder);
return options.UseSqlServerCompatibilityLevel(160);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,6 @@ protected override void ClearLog()
public class Fixture160 : NorthwindQuerySqlServerFixture<NoopModelCustomizer>
{
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> base.AddOptions(builder).UseSqlServer(b => b.UseCompatibilityLevel(160));
=> base.AddOptions(builder).UseSqlServerCompatibilityLevel(160);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,9 @@ protected override ITestStoreFactory TestStoreFactory
=> SqlServerTestStoreFactory.Instance;

public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
{
builder = base.AddOptions(builder);

// TODO: Figure out if there's a nice way to continue using the retrying strategy
var sqlServerOptionsBuilder = new SqlServerDbContextOptionsBuilder(builder);
sqlServerOptionsBuilder
.UseCompatibilityLevel(120)
.ExecutionStrategy(d => new NonRetryingExecutionStrategy(d));
return builder;
}
=> base.AddOptions(builder).UseSqlServerCompatibilityLevel(120)
.ConfigureSqlEngine(b => b.ExecutionStrategy(d => new NonRetryingExecutionStrategy(d)));

public override PrecompiledQueryTestHelpers PrecompiledQueryTestHelpers
=> SqlServerPrecompiledQueryTestHelpers.Instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,6 @@ protected override ITestStoreFactory TestStoreFactory

// Compatibility level 120 (SQL Server 2014) doesn't support OPENJSON
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> base.AddOptions(builder).UseSqlServer(o => o.UseCompatibilityLevel(120));
=> base.AddOptions(builder).UseSqlServerCompatibilityLevel(120);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2261,7 +2261,7 @@ protected override ITestStoreFactory TestStoreFactory
=> SqlServerTestStoreFactory.Instance;

public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> base.AddOptions(builder).UseSqlServer(b => b.UseCompatibilityLevel(160));
=> base.AddOptions(builder).UseSqlServerCompatibilityLevel(160);

protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public override async Task Parameter_collection_Count_with_column_predicate_with
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE (
SELECT COUNT(*)
FROM (VALUES (2), (999), (1000)) AS [i]([Value])
FROM (VALUES (CAST(2 AS int)), (999), (1000)) AS [i]([Value])
WHERE [i].[Value] > [p].[Id]) = 2
""");
}
Expand Down Expand Up @@ -1130,7 +1130,7 @@ public override async Task Column_collection_index_int()
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[NullableWrappedId], [p].[NullableWrappedIdWithNullableComparer], [p].[String], [p].[Strings], [p].[WrappedId]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE CAST(JSON_VALUE([p].[Ints], '$[1]') AS int) = 10
WHERE JSON_VALUE([p].[Ints], '$[1]' RETURNING int) = 10
""");
}

Expand All @@ -1142,7 +1142,7 @@ public override async Task Column_collection_index_string()
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[NullableWrappedId], [p].[NullableWrappedIdWithNullableComparer], [p].[String], [p].[Strings], [p].[WrappedId]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE JSON_VALUE([p].[Strings], '$[1]') = N'10'
WHERE JSON_VALUE([p].[Strings], '$[1]' RETURNING nvarchar(max)) = N'10'
""");
}

Expand All @@ -1154,7 +1154,7 @@ public override async Task Column_collection_index_datetime()
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[NullableWrappedId], [p].[NullableWrappedIdWithNullableComparer], [p].[String], [p].[Strings], [p].[WrappedId]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE CAST(JSON_VALUE([p].[DateTimes], '$[1]') AS datetime2) = '2020-01-10T12:30:00.0000000Z'
WHERE JSON_VALUE([p].[DateTimes], '$[1]' RETURNING datetime2) = '2020-01-10T12:30:00.0000000Z'
""");
}

Expand All @@ -1166,7 +1166,7 @@ public override async Task Column_collection_index_beyond_end()
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[NullableWrappedId], [p].[NullableWrappedIdWithNullableComparer], [p].[String], [p].[Strings], [p].[WrappedId]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE CAST(JSON_VALUE([p].[Ints], '$[999]') AS int) = 10
WHERE JSON_VALUE([p].[Ints], '$[999]' RETURNING int) = 10
""");
}

Expand All @@ -1179,7 +1179,7 @@ public override async Task Nullable_reference_column_collection_index_equals_nul
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[NullableWrappedId], [p].[NullableWrappedIdWithNullableComparer], [p].[String], [p].[Strings], [p].[WrappedId]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE JSON_VALUE([p].[NullableStrings], '$[2]') = [p].[NullableString] OR (JSON_VALUE([p].[NullableStrings], '$[2]') IS NULL AND [p].[NullableString] IS NULL)
WHERE JSON_VALUE([p].[NullableStrings], '$[2]' RETURNING nvarchar(max)) = [p].[NullableString] OR (JSON_VALUE([p].[NullableStrings], '$[2]' RETURNING nvarchar(max)) IS NULL AND [p].[NullableString] IS NULL)
""");
}

Expand All @@ -1193,7 +1193,7 @@ public override async Task Non_nullable_reference_column_collection_index_equals
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE EXISTS (
SELECT 1
FROM OPENJSON([p].[Strings]) AS [s]) AND JSON_VALUE([p].[Strings], '$[1]') = [p].[NullableString]
FROM OPENJSON([p].[Strings]) AS [s]) AND JSON_VALUE([p].[Strings], '$[1]' RETURNING nvarchar(max)) = [p].[NullableString]
""");
}

Expand Down Expand Up @@ -1221,11 +1221,7 @@ public override async Task Inline_collection_index_Column_with_EF_Constant()
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[NullableWrappedId], [p].[NullableWrappedIdWithNullableComparer], [p].[String], [p].[Strings], [p].[WrappedId]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE (
SELECT [i].[Value]
FROM (VALUES (0, CAST(1 AS int)), (1, 2), (2, 3)) AS [i]([_ord], [Value])
ORDER BY [i].[_ord]
OFFSET [p].[Int] ROWS FETCH NEXT 1 ROWS ONLY) = 1
WHERE CAST(JSON_VALUE(N'[1,2,3]', '$[' + CAST([p].[Int] AS nvarchar(max)) + ']') AS int) = 1
""");
}

Expand Down Expand Up @@ -1299,7 +1295,7 @@ public override async Task Column_collection_ElementAt()
"""
SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[NullableWrappedId], [p].[NullableWrappedIdWithNullableComparer], [p].[String], [p].[Strings], [p].[WrappedId]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE CAST(JSON_VALUE([p].[Ints], '$[1]') AS int) = 10
WHERE JSON_VALUE([p].[Ints], '$[1]' RETURNING int) = 10
""");
}

Expand Down Expand Up @@ -1827,7 +1823,7 @@ SELECT COUNT(*)
SELECT [i1].[Value]
FROM (
SELECT [i].[Value]
FROM (VALUES (1, @ints1), (2, @ints2)) AS [i]([_ord], [Value])
FROM (VALUES (0, @ints1), (1, @ints2)) AS [i]([_ord], [Value])
ORDER BY [i].[_ord]
OFFSET 1 ROWS
) AS [i1]
Expand Down Expand Up @@ -1917,7 +1913,7 @@ FROM [PrimitiveCollectionsEntity] AS [p]
SELECT COUNT(*)
FROM (
SELECT [i].[Value] AS [Value0]
FROM (VALUES (1, @ints1), (2, @ints2)) AS [i]([_ord], [Value])
FROM (VALUES (0, @ints1), (1, @ints2)) AS [i]([_ord], [Value])
ORDER BY [i].[_ord]
OFFSET 1 ROWS
) AS [i0]
Expand Down Expand Up @@ -2147,7 +2143,7 @@ public override async Task Project_primitive_collections_element()

AssertSql(
"""
SELECT CAST(JSON_VALUE([p].[Ints], '$[0]') AS int) AS [Indexer], CAST(JSON_VALUE([p].[DateTimes], '$[0]') AS datetime2) AS [EnumerableElementAt], JSON_VALUE([p].[Strings], '$[1]') AS [QueryableElementAt]
SELECT JSON_VALUE([p].[Ints], '$[0]' RETURNING int) AS [Indexer], JSON_VALUE([p].[DateTimes], '$[0]' RETURNING datetime2) AS [EnumerableElementAt], JSON_VALUE([p].[Strings], '$[1]' RETURNING nvarchar(max)) AS [QueryableElementAt]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE [p].[Id] < 4
ORDER BY [p].[Id]
Expand Down Expand Up @@ -2268,8 +2264,10 @@ protected override ITestStoreFactory TestStoreFactory
=> SqlServerTestStoreFactory.Instance;

public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> base.AddOptions(builder)
.UseSqlServer(b => b.UseCompatibilityLevel(160));
{
var options = base.AddOptions(builder);
return options.UseSqlServerCompatibilityLevel(160);
}

protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public override async Task Index_constant()
"""
SELECT [r].[Id], [r].[Name], [r].[OptionalRelated], [r].[RelatedCollection], [r].[RequiredRelated]
FROM [RootEntity] AS [r]
WHERE JSON_VALUE([r].[RelatedCollection], '$[0]' RETURNING int) = 8
WHERE JSON_VALUE([r].[RelatedCollection], '$[0].Int' RETURNING int) = 8
""");
}
else
Expand All @@ -152,7 +152,7 @@ public override async Task Index_parameter()

SELECT [r].[Id], [r].[Name], [r].[OptionalRelated], [r].[RelatedCollection], [r].[RequiredRelated]
FROM [RootEntity] AS [r]
WHERE JSON_VALUE([r].[RelatedCollection], '$[' + CAST(@i AS nvarchar(max)) + ']' RETURNING int) = 8
WHERE JSON_VALUE([r].[RelatedCollection], '$[' + CAST(@i AS nvarchar(max)) + '].Int' RETURNING int) = 8
""");
}
else
Expand All @@ -178,7 +178,7 @@ public override async Task Index_column()
"""
SELECT [r].[Id], [r].[Name], [r].[OptionalRelated], [r].[RelatedCollection], [r].[RequiredRelated]
FROM [RootEntity] AS [r]
WHERE JSON_VALUE([r].[RelatedCollection], '$[' + CAST([r].[Id] - 1 AS nvarchar(max)) + ']' RETURNING int) = 8
WHERE JSON_VALUE([r].[RelatedCollection], '$[' + CAST([r].[Id] - 1 AS nvarchar(max)) + '].Int' RETURNING int) = 8
""");
}
else
Expand All @@ -202,7 +202,7 @@ public override async Task Index_out_of_bounds()
"""
SELECT [r].[Id], [r].[Name], [r].[OptionalRelated], [r].[RelatedCollection], [r].[RequiredRelated]
FROM [RootEntity] AS [r]
WHERE JSON_VALUE([r].[RelatedCollection], '$[9999]' RETURNING int) = 8
WHERE JSON_VALUE([r].[RelatedCollection], '$[9999].Int' RETURNING int) = 8
""");
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ protected override ITestStoreFactory TestStoreFactory

// 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)
=> TestEnvironment.SqlServerMajorVersion >= 17
? builder.UseSqlServer(o => o.UseCompatibilityLevel(170))
: builder;
{
var options = base.AddOptions(builder);
return TestEnvironment.SqlServerMajorVersion < 17
? options
: options.UseSqlServerCompatibilityLevel(170);
}

public virtual bool UsingJsonType
=> TestEnvironment.SqlServerMajorVersion >= 17;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
public class BasicTypesQuerySqlServer160Fixture : BasicTypesQuerySqlServerFixture
{
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> base.AddOptions(builder).UseSqlServer(b => b.UseCompatibilityLevel(160));
=> base.AddOptions(builder).UseSqlServerCompatibilityLevel(160);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseSqlServer(_connectionString, b => b.ApplyConfiguration());

protected override void OnModelCreating(ModelBuilder modelBuilder)
=> modelBuilder.HasPerformanceLevelSql("ELASTIC_POOL ( name = unicornhack )");
=> modelBuilder.HasPerformanceLevelSql($"ELASTIC_POOL ( name = {TestEnvironment.ElasticPoolName} )");
}

[ConditionalFact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public Task Creates_schema_in_existing_database_with_filename(bool async, bool a
=> Creates_schema_in_existing_database_test(async, ambientTransaction, file: true);

private static Task Creates_schema_in_existing_database_test(bool async, bool ambientTransaction, bool file)
=> TestEnvironment.IsSqlAzure
=> TestEnvironment.IsAzureSql
? new TestSqlServerRetryingExecutionStrategy().ExecuteAsync(
(true, async, ambientTransaction, file), Creates_physical_database_and_schema_test)
: Creates_physical_database_and_schema_test((true, async, ambientTransaction, file));
Expand All @@ -201,7 +201,7 @@ public Task Creates_physical_database_with_filename_and_schema(bool async, bool
=> Creates_new_physical_database_and_schema_test(async, ambientTransaction, file: true);

private static Task Creates_new_physical_database_and_schema_test(bool async, bool ambientTransaction, bool file)
=> TestEnvironment.IsSqlAzure
=> TestEnvironment.IsAzureSql
? new TestSqlServerRetryingExecutionStrategy().ExecuteAsync(
(false, async, ambientTransaction, file), Creates_physical_database_and_schema_test)
: Creates_physical_database_and_schema_test((false, async, ambientTransaction, file));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public ValueTask<bool> IsMetAsync()

if (Conditions.HasFlag(SqlServerCondition.IsAzureSql))
{
isMet &= TestEnvironment.IsSqlAzure;
isMet &= TestEnvironment.IsAzureSql;
}

if (Conditions.HasFlag(SqlServerCondition.IsNotAzureSql))
{
isMet &= !TestEnvironment.IsSqlAzure;
isMet &= !TestEnvironment.IsAzureSql;
}

if (Conditions.HasFlag(SqlServerCondition.SupportsAttach))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,16 @@ public static AzureSynapseDbContextOptionsBuilder ApplyConfiguration(this AzureS

return optionsBuilder;
}

/// <summary>
/// Configures the SQL Server or Azure SQL provider with the specified compatibility level.
/// This method automatically chooses between UseAzureSql and UseSqlServer based on the current test environment.
/// </summary>
/// <param name="optionsBuilder">The options builder to configure.</param>
/// <param name="compatibilityLevel">The compatibility level to use.</param>
/// <returns>The configured options builder.</returns>
public static DbContextOptionsBuilder UseSqlServerCompatibilityLevel(this DbContextOptionsBuilder optionsBuilder, int compatibilityLevel)
=> TestEnvironment.IsAzureSql
? optionsBuilder.UseAzureSql(b => b.UseCompatibilityLevel(compatibilityLevel))
: optionsBuilder.UseSqlServer(b => b.UseCompatibilityLevel(compatibilityLevel));
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,12 @@ protected override async Task InitializeAsync(Func<DbContext> createContext, Fun

public override DbContextOptionsBuilder AddProviderOptions(DbContextOptionsBuilder builder)
=> (UseConnectionString
? builder.UseSqlServer(ConnectionString, b => b.ApplyConfiguration())
: builder.UseSqlServer(Connection, b => b.ApplyConfiguration()))
? TestEnvironment.IsAzureSql
? builder.UseAzureSql(ConnectionString, b => b.ApplyConfiguration())
: builder.UseSqlServer(ConnectionString, b => b.ApplyConfiguration())
: TestEnvironment.IsAzureSql
? builder.UseAzureSql(Connection, b => b.ApplyConfiguration())
: builder.UseSqlServer(Connection, b => b.ApplyConfiguration()))
.ConfigureWarnings(b => b.Ignore(SqlServerEventId.SavepointsDisabledBecauseOfMARS));

private async Task<bool> CleanDatabaseAsync(Func<DbContext, Task>? clean)
Expand Down Expand Up @@ -213,7 +217,7 @@ private static string GetCreateDatabaseStatement(string name, string? fileName)
{
var result = $"CREATE DATABASE [{name}]";

if (TestEnvironment.IsSqlAzure)
if (TestEnvironment.IsAzureSql)
{
var elasticGroupName = TestEnvironment.ElasticPoolName;
result += Environment.NewLine
Expand Down Expand Up @@ -450,7 +454,7 @@ public override async ValueTask DisposeAsync()
await base.DisposeAsync();

if (_fileName != null // Clean up the database using a local file, as it might get deleted later
|| (TestEnvironment.IsSqlAzure && !Shared))
|| (TestEnvironment.IsAzureSql && !Shared))
{
await DeleteDatabaseAsync();
}
Expand Down
Loading
Loading