Update Pipeline: Implement cycle breaking for optional relationships
See original GitHub issueThe following model currently throws saying it hit a circular dependency
Test 'Microsoft.Data.Entity.SqlServer.FunctionalTests.NavigationTest.Duplicate_entries_are_not_created_for_navigations_E2E' failed:
System.InvalidOperationException : A circular dependency was detected: 'Person' {'SiblingReverseId'} -> 'Person' {'Id'}, 'Person' {'LoverId'} -> 'Person' {'Id'}.
Utilities\Multigraph.cs(338,0): at Microsoft.Data.Entity.Utilities.Multigraph`2.BatchingTopologicalSort(Func`2 formatCycle)
Update\CommandBatchPreparer.cs(108,0): at Microsoft.Data.Entity.Relational.Update.CommandBatchPreparer.TopologicalSort(IEnumerable`1 commands)
Update\CommandBatchPreparer.cs(50,0): at Microsoft.Data.Entity.Relational.Update.CommandBatchPreparer.<BatchCommands>d__1.MoveNext()
Update\BatchExecutor.cs(66,0): at Microsoft.Data.Entity.Relational.Update.BatchExecutor.Execute(IEnumerable`1 commandBatches, RelationalConnection connection)
RelationalDataStore.cs(82,0): at Microsoft.Data.Entity.Relational.RelationalDataStore.SaveChanges(IReadOnlyList`1 entries)
ChangeTracking\Internal\StateManager.cs(353,0): at Microsoft.Data.Entity.ChangeTracking.Internal.StateManager.SaveChanges(IReadOnlyList`1 entriesToSave)
ChangeTracking\Internal\StateManager.cs(308,0): at Microsoft.Data.Entity.ChangeTracking.Internal.StateManager.SaveChanges()
DbContext.cs(312,0): at Microsoft.Data.Entity.DbContext.SaveChanges()
NavigationTest.cs(73,0): at Microsoft.Data.Entity.SqlServer.FunctionalTests.NavigationTest.Duplicate_entries_are_not_created_for_navigations_E2E()
[Fact]
public void Duplicate_entries_are_not_created_for_navigations_E2E()
{
using (var ctx = new GoTContext())
{
ctx.Database.EnsureDeleted();
ctx.Database.EnsureCreated();
var cersei = new Person { Name = "Cersei" };
var jamie = new Person { Name = "Jamie" };
cersei.Lover = jamie;
cersei.Siblings = new List<Person> { jamie, };
ctx.People.AddRange(new[] { cersei, jamie, });
ctx.SaveChanges();
}
}
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public List<Person> Siblings { get; set; }
public Person Lover { get; set; }
public Person LoverReverse { get; set; }
public Person SiblingReverse { get; set; }
}
public class GoTContext : DbContext
{
public DbSet<Person> People { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Person>().HasMany(p => p.Siblings)
.WithOne(p => p.SiblingReverse).Required(false);
modelBuilder.Entity<Person>().HasOne(p => p.Lover)
.WithOne(p => p.LoverReverse).Required(false);
}
protected override void OnConfiguring(DbContextOptions options)
{
options.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=StateManagerBug;Trusted_Connection=True;MultipleActiveResultSets=true");
}
}
Issue Analytics
- State:
- Created 9 years ago
- Reactions:22
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Chapter 4. Pipelines OpenShift Container Platform 4.10
This update adds a default-forbidden-env parameter in optional pipeline properties. The parameter includes forbidden environment variables that should not be ...
Read more >Deprecations and removals by version | GitLab
The following GitLab features are deprecated and no longer recommended for use. Each deprecated feature will be removed in a future release. Some...
Read more >MLOps: Continuous delivery and automation pipelines in ...
In practice, models often break when they are deployed in the real world. ... An optional additional component for level 1 ML pipeline...
Read more >DependencyParser · spaCy API Documentation
The dependency parser jointly learns sentence segmentation and labelled dependency parsing, and can optionally learn to merge tokens that had been over- ...
Read more >Azure DevOpsServer 2020 Update 1 Release Notes
Azure DevOps Server 2020 introduces a new pipeline run (build) retention model that works based on project-level settings. Azure DevOps Server ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @ajcvickers, We have been converted our banking solution which has 1500 entities from nhibernate to ef7. I think its a major issue our current domain model has this kind of relationship. Do we have any workaround to break cycle for optional/not optional relationships until this implementation is done ?
While this feature is not ready, you can make one side of the relationship optional and override DB context SaveChanges to:
Here is a basic code that handles simple cases of circular reference:
Source code