Skip to content

Commit 1e15aa4

Browse files
committed
Add inheritance tests
1 parent 68e89c4 commit 1e15aa4

File tree

12 files changed

+382
-28
lines changed

12 files changed

+382
-28
lines changed

test/EFCore.Relational.Specification.Tests/TestModels/StoredProcedureUpdateModel/StoredProcedureUpdateContext.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ public DbSet<Entity> WithOriginalAndCurrentValueOnNonConcurrencyToken
4949
public DbSet<Entity> WithInputOutputParameterOnNonConcurrencyToken
5050
=> Set<Entity>(nameof(WithInputOutputParameterOnNonConcurrencyToken));
5151

52+
public DbSet<TphParent> TphParent { get; set; }
53+
public DbSet<TphChild> TphChild { get; set; }
54+
public DbSet<TptParent> TptParent { get; set; }
55+
public DbSet<TptChild> TptChild { get; set; }
56+
public DbSet<TptMixedParent> TptMixedParent { get; set; }
57+
public DbSet<TptMixedChild> TptMixedChild { get; set; }
58+
public DbSet<TpcParent> TpcParent { get; set; }
59+
public DbSet<TpcChild> TpcChild { get; set; }
60+
5261
public static void Clean(StoredProcedureUpdateContext context)
5362
{
5463
context.WithOutputParameter.RemoveRange(context.WithOutputParameter);
@@ -64,6 +73,14 @@ public static void Clean(StoredProcedureUpdateContext context)
6473
context.WithUserManagedConcurrencyToken.RemoveRange(context.WithUserManagedConcurrencyToken);
6574
context.WithOriginalAndCurrentValueOnNonConcurrencyToken.RemoveRange(context.WithOriginalAndCurrentValueOnNonConcurrencyToken);
6675
context.WithInputOutputParameterOnNonConcurrencyToken.RemoveRange(context.WithInputOutputParameterOnNonConcurrencyToken);
76+
context.TphParent.RemoveRange(context.TphParent);
77+
context.TphChild.RemoveRange(context.TphChild);
78+
context.TptParent.RemoveRange(context.TptParent);
79+
context.TptChild.RemoveRange(context.TptChild);
80+
context.TptMixedParent.RemoveRange(context.TptMixedParent);
81+
context.TptMixedChild.RemoveRange(context.TptMixedChild);
82+
context.TpcParent.RemoveRange(context.TpcParent);
83+
context.TpcChild.RemoveRange(context.TpcChild);
6784

6885
context.SaveChanges();
6986
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.EntityFrameworkCore.TestModels.StoredProcedureUpdateModel;
5+
6+
public class TpcChild : TpcParent
7+
{
8+
public int ChildProperty { get; set; }
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.EntityFrameworkCore.TestModels.StoredProcedureUpdateModel;
5+
6+
public class TpcParent
7+
{
8+
public int Id { get; set; }
9+
public string Name { get; set; }
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.EntityFrameworkCore.TestModels.StoredProcedureUpdateModel;
5+
6+
public class TphChild : TphParent
7+
{
8+
public int ChildProperty { get; set; }
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.EntityFrameworkCore.TestModels.StoredProcedureUpdateModel;
5+
6+
public class TphParent
7+
{
8+
public int Id { get; set; }
9+
public string Name { get; set; }
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.EntityFrameworkCore.TestModels.StoredProcedureUpdateModel;
5+
6+
public class TptChild : TptParent
7+
{
8+
public int ChildProperty { get; set; }
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.EntityFrameworkCore.TestModels.StoredProcedureUpdateModel;
5+
6+
public class TptMixedChild : TptMixedParent
7+
{
8+
public int ChildProperty { get; set; }
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.EntityFrameworkCore.TestModels.StoredProcedureUpdateModel;
5+
6+
public class TptMixedParent
7+
{
8+
public int Id { get; set; }
9+
public string Name { get; set; }
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.EntityFrameworkCore.TestModels.StoredProcedureUpdateModel;
5+
6+
public class TptParent
7+
{
8+
public int Id { get; set; }
9+
public string Name { get; set; }
10+
}

test/EFCore.Relational.Specification.Tests/Update/StoredProcedureUpdateFixtureBase.cs

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,76 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
158158
b.Property(w => w.AdditionalProperty2).HasComputedColumnSql("9");
159159

160160
b.UpdateUsingStoredProcedure(
161-
"WithOutputParameterAndResultColumnAndResultValue_Update", spb => spb
161+
nameof(StoredProcedureUpdateContext.WithOutputParameterAndResultColumnAndResultValue) + "_Update",
162+
spb => spb
162163
.HasParameter(w => w.Id)
163164
.HasParameter(w => w.Name)
164165
.HasParameter(w => w.AdditionalProperty1, pb => pb.IsOutput())
165166
.HasResultColumn(w => w.AdditionalProperty2)
166167
.HasRowsAffectedReturnValue());
167168
});
169+
170+
modelBuilder.Entity<TphParent>(
171+
b =>
172+
{
173+
b.ToTable("Tph");
174+
175+
b.InsertUsingStoredProcedure(
176+
"Tph_Insert",
177+
spb => spb
178+
.HasParameter(w => w.Id, pb => pb.IsOutput())
179+
.HasParameter("Discriminator")
180+
.HasParameter(w => w.Name)
181+
.HasParameter(nameof(TphChild.ChildProperty)));
182+
});
183+
184+
modelBuilder.Entity<TphChild>().ToTable("Tph");
185+
186+
modelBuilder.Entity<TptParent>(
187+
b =>
188+
{
189+
b.UseTptMappingStrategy();
190+
191+
b.InsertUsingStoredProcedure(
192+
"TptParent_Insert",
193+
spb => spb
194+
.HasParameter(w => w.Id, pb => pb.IsOutput())
195+
.HasParameter(w => w.Name));
196+
});
197+
198+
// TODO: The following fails validation:
199+
// The entity type 'TptChild' is mapped to the stored procedure 'TptChild_Insert', however the store-generated properties {'Id'} are not mapped to any output parameter or result column.
200+
modelBuilder.Entity<TptChild>()
201+
.InsertUsingStoredProcedure(
202+
"TptChild_Insert",
203+
spb => spb
204+
.HasParameter(w => w.Id)
205+
.HasParameter(w => w.ChildProperty));
206+
207+
modelBuilder.Entity<TptMixedParent>(
208+
b =>
209+
{
210+
b.UseTptMappingStrategy();
211+
212+
b.InsertUsingStoredProcedure(
213+
"TptMixedParent_Insert",
214+
spb => spb
215+
.HasParameter(w => w.Id, pb => pb.IsOutput())
216+
.HasParameter(w => w.Name));
217+
});
218+
219+
// No sproc mapping for TptMixedChild, use regular SQL
220+
221+
modelBuilder.Entity<TpcParent>().UseTpcMappingStrategy();
222+
223+
modelBuilder.Entity<TpcChild>()
224+
.UseTpcMappingStrategy()
225+
.InsertUsingStoredProcedure(
226+
"TpcChild_Insert",
227+
spb => spb
228+
.HasParameter(w => w.Id, pb => pb.IsOutput())
229+
.HasParameter(w => w.Name)
230+
.HasParameter(w => w.ChildProperty));
168231
}
169232

170233
/// <summary>

0 commit comments

Comments
 (0)