-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix table splitting for derived types in update pipeline.
Make the columns nullable for dependent types involved in table splitting. When uniquifying column names use the declaring entity type name as prefix. Fixes #8907
- Loading branch information
1 parent
7805579
commit 288ce2f
Showing
24 changed files
with
708 additions
and
159 deletions.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
src/EFCore.Relational.Specification.Tests/TableSplittingTestBase.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,106 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Linq; | ||
using Microsoft.EntityFrameworkCore.TestModels.TransportationModel; | ||
using Xunit; | ||
|
||
namespace Microsoft.EntityFrameworkCore | ||
{ | ||
public abstract class TableSplittingTestBase<TTestStore> | ||
where TTestStore : TestStore | ||
{ | ||
[Fact] | ||
public void Can_query_shared() | ||
{ | ||
using (var store = CreateTestStore(OnModelCreating)) | ||
{ | ||
using (var context = CreateContext(store, OnModelCreating)) | ||
{ | ||
Assert.Equal(4, context.Set<Operator>().ToList().Count); | ||
} | ||
} | ||
} | ||
|
||
[Fact(Skip = "#8973")] | ||
public void Can_query_shared_derived() | ||
{ | ||
using (var store = CreateTestStore(OnModelCreating)) | ||
{ | ||
using (var context = CreateContext(store, OnModelCreating)) | ||
{ | ||
Assert.Equal(2, context.Set<Engine>().ToList().Count); | ||
Assert.Equal(1, context.Set<FuelTank>().ToList().Count); | ||
} | ||
} | ||
} | ||
|
||
[Fact] | ||
public void Can_use_with_redundant_relationships() | ||
{ | ||
Test_roundtrip(OnModelCreating); | ||
} | ||
|
||
[Fact] | ||
public void Can_use_with_chained_relationships() | ||
{ | ||
Test_roundtrip(modelBuilder => | ||
{ | ||
OnModelCreating(modelBuilder); | ||
modelBuilder.Entity<FuelTank>(eb => | ||
{ | ||
eb.Ignore(e => e.Vehicle); | ||
}); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void Can_use_with_fanned_relationships() | ||
{ | ||
Test_roundtrip(modelBuilder => | ||
{ | ||
OnModelCreating(modelBuilder); | ||
modelBuilder.Entity<FuelTank>(eb => | ||
{ | ||
eb.Ignore(e => e.Engine); | ||
}); | ||
modelBuilder.Entity<CombustionEngine>(eb => | ||
{ | ||
eb.Ignore(e => e.FuelTank); | ||
}); | ||
}); | ||
} | ||
|
||
protected virtual void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
TransportationContext.OnModelCreatingBase(modelBuilder); | ||
|
||
modelBuilder.Entity<Vehicle>(eb => | ||
{ | ||
eb.HasDiscriminator<string>("Discriminator"); | ||
eb.Property<string>("Discriminator").HasColumnName("Discriminator"); | ||
eb.ToTable("Vehicles"); | ||
}); | ||
|
||
modelBuilder.Entity<Engine>().ToTable("Vehicles"); | ||
modelBuilder.Entity<Operator>().ToTable("Vehicles"); | ||
modelBuilder.Entity<FuelTank>().ToTable("Vehicles"); | ||
} | ||
|
||
protected void Test_roundtrip(Action<ModelBuilder> onModelCreating) | ||
{ | ||
using (var store = CreateTestStore(onModelCreating)) | ||
{ | ||
using (var context = CreateContext(store, onModelCreating)) | ||
{ | ||
context.AssertSeeded(); | ||
} | ||
} | ||
} | ||
|
||
protected static readonly string DatabaseName = "TableSplittingTest"; | ||
public abstract TTestStore CreateTestStore(Action<ModelBuilder> onModelCreating); | ||
public abstract TransportationContext CreateContext(TTestStore testStore, Action<ModelBuilder> onModelCreating); | ||
} | ||
} |
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
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
22 changes: 21 additions & 1 deletion
22
src/EFCore.Relational/Metadata/RelationalPropertyExtensions.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 |
---|---|---|
@@ -1,13 +1,33 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Linq; | ||
using JetBrains.Annotations; | ||
using Microsoft.EntityFrameworkCore.Metadata.Internal; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Metadata | ||
{ | ||
public static class RelationalPropertyExtensions | ||
{ | ||
public static bool IsColumnNullable([NotNull] this IProperty property) | ||
=> property.DeclaringEntityType.BaseType != null || property.IsNullable; | ||
{ | ||
if (property.DeclaringEntityType.BaseType != null | ||
|| property.IsNullable) | ||
{ | ||
return true; | ||
} | ||
|
||
if (property.IsPrimaryKey()) | ||
{ | ||
return false; | ||
} | ||
|
||
var pk = property.DeclaringEntityType.FindPrimaryKey(); | ||
return pk != null | ||
&& property.DeclaringEntityType.FindForeignKeys(pk.Properties) | ||
.Any(fk => fk.PrincipalKey.IsPrimaryKey() | ||
&& fk.DeclaringEntityType.Relational().TableName == fk.PrincipalEntityType.Relational().TableName | ||
&& fk.DeclaringEntityType.Relational().Schema == fk.PrincipalEntityType.Relational().Schema); | ||
} | ||
} | ||
} |
16 changes: 8 additions & 8 deletions
16
src/EFCore.Relational/Properties/RelationalStrings.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.