You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The state of a removed many-to-many relation is deleted and stays deleted even after it is add again.
Or a other way to describe it is calling Detect Changes breaks the change tracker.
It looks like the change tracker DetectChanges only works the first time.
Is this by design? if so is there a way to change this behavior? (maybe with a payload)
I change the Many_to_many_relationships_3 sample function for clarification:
public static void Many_to_many_relationships_3()
{
Console.WriteLine($">>>> Sample: {nameof(Many_to_many_relationships_3)}");
Console.WriteLine();
Helpers.RecreateCleanDatabase();
Helpers.PopulateDatabase();
#region Many_to_many_relationships_3
using var context = new BlogsContext();
var post = context.Posts.Single(e => e.Id == 3);
var tag = context.Tags.Single(e => e.Id == 1);
post.Tags.Add(tag);
context.ChangeTracker.DetectChanges();
Console.WriteLine("After add the post/tag relation:");
Console.WriteLine(context.ChangeTracker.DebugView.LongView);
Console.WriteLine();
#endregion
//New code.
context.SaveChanges();
context.ChangeTracker.DetectChanges();
Console.WriteLine("After save:");
Console.WriteLine(context.ChangeTracker.DebugView.LongView);
Console.WriteLine();
post.Tags.Remove(tag);
context.ChangeTracker.DetectChanges();
Console.WriteLine("After remove the post/tag relation:");
Console.WriteLine(context.ChangeTracker.DebugView.LongView);
Console.WriteLine();
post.Tags.Add(tag); //This is not working, relation state is still deleted.
context.ChangeTracker.DetectChanges();
Console.WriteLine("After add it again:");
Console.WriteLine(context.ChangeTracker.DebugView.LongView);
Console.WriteLine();
}
The text was updated successfully, but these errors were encountered:
The state of a removed many-to-many relation is deleted and stays deleted even after it is add again.
Or a other way to describe it is calling Detect Changes breaks the change tracker.
It looks like the change tracker DetectChanges only works the first time.
Is this by design? if so is there a way to change this behavior? (maybe with a payload)
I change the Many_to_many_relationships_3 sample function for clarification:
The text was updated successfully, but these errors were encountered: