forked from dotnet/efcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix parameter names for nested types in complex type equality (dotnet…
…#33527) Fixes dotnet#33449
- Loading branch information
Showing
7 changed files
with
160 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
test/EFCore.Specification.Tests/Query/AdHocComplexTypeQueryTestBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query; | ||
|
||
// ReSharper disable ClassNeverInstantiated.Local | ||
|
||
public abstract class AdHocComplexTypeQueryTestBase : NonSharedModelTestBase | ||
{ | ||
#region 33449 | ||
|
||
[ConditionalFact] | ||
public virtual async Task Complex_type_equals_parameter_with_nested_types_with_property_of_same_name() | ||
{ | ||
var contextFactory = await InitializeAsync<Context33449>( | ||
seed: context => | ||
{ | ||
context.AddRange( | ||
new Context33449.EntityType | ||
{ | ||
ComplexContainer = new() | ||
{ | ||
Id = 1, | ||
Containee1 = new() { Id = 2 }, | ||
Containee2 = new() { Id = 3 } | ||
} | ||
}); | ||
return context.SaveChangesAsync(); | ||
}); | ||
|
||
await using var context = contextFactory.CreateContext(); | ||
|
||
var container = new Context33449.ComplexContainer | ||
{ | ||
Id = 1, | ||
Containee1 = new() { Id = 2 }, | ||
Containee2 = new() { Id = 3 } | ||
}; | ||
|
||
_ = await context.Set<Context33449.EntityType>().Where(b => b.ComplexContainer == container).SingleAsync(); | ||
} | ||
|
||
private class Context33449(DbContextOptions options) : DbContext(options) | ||
{ | ||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
=> modelBuilder.Entity<EntityType>().ComplexProperty(b => b.ComplexContainer, x => | ||
{ | ||
x.ComplexProperty(c => c.Containee1); | ||
x.ComplexProperty(c => c.Containee2); | ||
}); | ||
|
||
public class EntityType | ||
{ | ||
public int Id { get; set; } | ||
public ComplexContainer ComplexContainer { get; set; } = null!; | ||
} | ||
|
||
public class ComplexContainer | ||
{ | ||
public int Id { get; set; } | ||
|
||
public ComplexContainee1 Containee1 { get; set; } = null!; | ||
public ComplexContainee2 Containee2 { get; set; } = null!; | ||
} | ||
|
||
public class ComplexContainee1 | ||
{ | ||
public int Id { get; set; } | ||
} | ||
|
||
public class ComplexContainee2 | ||
{ | ||
public int Id { get; set; } | ||
} | ||
} | ||
|
||
#endregion 33449 | ||
|
||
protected override string StoreName | ||
=> "AdHocComplexTypeQueryTest"; | ||
} |
32 changes: 32 additions & 0 deletions
32
test/EFCore.SqlServer.FunctionalTests/Query/AdHocComplexTypeQuerySqlServerTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query; | ||
|
||
public class AdHocComplexTypeQuerySqlServerTest : AdHocComplexTypeQueryTestBase | ||
{ | ||
public override async Task Complex_type_equals_parameter_with_nested_types_with_property_of_same_name() | ||
{ | ||
await base.Complex_type_equals_parameter_with_nested_types_with_property_of_same_name(); | ||
|
||
AssertSql( | ||
""" | ||
@__entity_equality_container_0_Id='1' (Nullable = true) | ||
@__entity_equality_container_0_Containee1_Id='2' (Nullable = true) | ||
@__entity_equality_container_0_Containee2_Id='3' (Nullable = true) | ||
|
||
SELECT TOP(2) [e].[Id], [e].[ComplexContainer_Id], [e].[ComplexContainer_Containee1_Id], [e].[ComplexContainer_Containee2_Id] | ||
FROM [EntityType] AS [e] | ||
WHERE [e].[ComplexContainer_Id] = @__entity_equality_container_0_Id AND [e].[ComplexContainer_Containee1_Id] = @__entity_equality_container_0_Containee1_Id AND [e].[ComplexContainer_Containee2_Id] = @__entity_equality_container_0_Containee2_Id | ||
"""); | ||
} | ||
|
||
protected TestSqlLoggerFactory TestSqlLoggerFactory | ||
=> (TestSqlLoggerFactory)ListLoggerFactory; | ||
|
||
protected void AssertSql(params string[] expected) | ||
=> TestSqlLoggerFactory.AssertBaseline(expected); | ||
|
||
protected override ITestStoreFactory TestStoreFactory | ||
=> SqlServerTestStoreFactory.Instance; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
test/EFCore.Sqlite.FunctionalTests/Query/AdHocComplexTypeQuerySqliteTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query; | ||
|
||
public class AdHocComplexTypeQuerySqliteTest : AdHocComplexTypeQueryTestBase | ||
{ | ||
protected override ITestStoreFactory TestStoreFactory | ||
=> SqliteTestStoreFactory.Instance; | ||
} |
Oops, something went wrong.