forked from dotnet/efcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdHocComplexTypeQueryTestBase.cs
82 lines (67 loc) · 2.5 KB
/
AdHocComplexTypeQueryTestBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// 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 }
}
});
context.SaveChanges();
});
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.IsRequired();
x.ComplexProperty(c => c.Containee1).IsRequired();
x.ComplexProperty(c => c.Containee2).IsRequired();
});
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";
}