-
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.
Avoid cascade cycles on SQL Server for derived-type referencing many-…
…to-many (#28937)
- Loading branch information
1 parent
75cee40
commit eb49719
Showing
36 changed files
with
827 additions
and
131 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
64 changes: 64 additions & 0 deletions
64
test/EFCore.Relational.Specification.Tests/ManyToManyTrackingRelationalTestBase.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,64 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.EntityFrameworkCore.TestModels.ManyToManyModel; | ||
|
||
namespace Microsoft.EntityFrameworkCore; | ||
|
||
public abstract class ManyToManyTrackingRelationalTestBase<TFixture> : ManyToManyTrackingTestBase<TFixture> | ||
where TFixture : ManyToManyTrackingRelationalTestBase<TFixture>.ManyToManyTrackingRelationalFixture | ||
{ | ||
protected ManyToManyTrackingRelationalTestBase(TFixture fixture) | ||
: base(fixture) | ||
{ | ||
} | ||
|
||
[ConditionalFact] | ||
public void Many_to_many_delete_behaviors_are_set() | ||
{ | ||
using var context = CreateContext(); | ||
var model = context.Model; | ||
|
||
var navigations = model.GetEntityTypes().SelectMany(e => e.GetDeclaredSkipNavigations()) | ||
.Where(e => e.ForeignKey.DeleteBehavior != DeleteBehavior.Cascade).ToList(); | ||
|
||
var builder = new StringBuilder(); | ||
foreach (var navigation in navigations) | ||
{ | ||
builder.AppendLine($"{{ \"{navigation.DeclaringEntityType.ShortName()}.{navigation.Name}\", DeleteBehavior.ClientCascade }},"); | ||
} | ||
|
||
var x = builder.ToString(); | ||
|
||
foreach (var skipNavigation in model.GetEntityTypes().SelectMany(e => e.GetSkipNavigations())) | ||
{ | ||
Assert.Equal( | ||
CustomDeleteBehaviors.TryGetValue( | ||
$"{skipNavigation.DeclaringEntityType.ShortName()}.{skipNavigation.Name}", out var deleteBehavior) | ||
? deleteBehavior | ||
: DeleteBehavior.Cascade, | ||
skipNavigation.ForeignKey.DeleteBehavior); | ||
} | ||
} | ||
|
||
protected virtual Dictionary<string, DeleteBehavior> CustomDeleteBehaviors { get; } = new(); | ||
|
||
protected override void UseTransaction(DatabaseFacade facade, IDbContextTransaction transaction) | ||
=> facade.UseTransaction(transaction.GetDbTransaction()); | ||
|
||
public abstract class ManyToManyTrackingRelationalFixture : ManyToManyTrackingFixtureBase | ||
{ | ||
protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context) | ||
{ | ||
base.OnModelCreating(modelBuilder, context); | ||
|
||
modelBuilder.Entity<EntityTableSharing1>().ToTable("TableSharing"); | ||
modelBuilder.Entity<EntityTableSharing2>( | ||
b => | ||
{ | ||
b.HasOne<EntityTableSharing1>().WithOne().HasForeignKey<EntityTableSharing2>(e => e.Id); | ||
b.ToTable("TableSharing"); | ||
}); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
test/EFCore.Relational.Specification.Tests/Query/ManyToManyQueryRelationalFixture.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,10 +1,25 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.EntityFrameworkCore.TestModels.ManyToManyModel; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query; | ||
|
||
public abstract class ManyToManyQueryRelationalFixture : ManyToManyQueryFixtureBase | ||
{ | ||
public TestSqlLoggerFactory TestSqlLoggerFactory | ||
=> (TestSqlLoggerFactory)ListLoggerFactory; | ||
|
||
protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context) | ||
{ | ||
base.OnModelCreating(modelBuilder, context); | ||
|
||
modelBuilder.Entity<EntityTableSharing1>().ToTable("TableSharing"); | ||
modelBuilder.Entity<EntityTableSharing2>( | ||
b => | ||
{ | ||
b.HasOne<EntityTableSharing1>().WithOne().HasForeignKey<EntityTableSharing2>(e => e.Id); | ||
b.ToTable("TableSharing"); | ||
}); | ||
} | ||
} |
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
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
Oops, something went wrong.