-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detaching an entity results in modify references #19203
Labels
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
Servicing-approved
type-bug
Milestone
Comments
Note for triage: It looks like detaching is marking an FK as modified when it should not. Full repro: public class Class1
{
public long Id { get; set; }
public long? Class2Id { get; set; }
public Class2 Class2 { get; set; }
}
public class Class2
{
public long Id { get; set; }
}
public class BloggingContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder
.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=Test;ConnectRetryCount=0");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Class1>();
modelBuilder.Entity<Class2>();
}
}
public class Program
{
public static async Task Main()
{
using (var context = new BloggingContext())
{
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
context.Add(new Class1
{
Class2 = new Class2()
});
await context.SaveChangesAsync();
}
using (var context = new BloggingContext())
{
context.ChangeTracker.AutoDetectChangesEnabled = false;
var t1 = context.Set<Class1>().Include(m => m.Class2).FirstOrDefault();
var t2 = t1.Class2;
Console.WriteLine("T1>" + context.Entry(t1).State);
Console.WriteLine("T2>" + context.Entry(t2).State);
context.Entry(t2).State = EntityState.Detached;
Console.WriteLine("T1>" + context.Entry(t1).State);
Console.WriteLine("T2>" + context.Entry(t2).State);
}
}
} |
ajcvickers
added a commit
that referenced
this issue
Dec 30, 2019
ajcvickers
added a commit
that referenced
this issue
Dec 30, 2019
ajcvickers
added a commit
that referenced
this issue
Feb 13, 2020
ajcvickers
added a commit
that referenced
this issue
Feb 13, 2020
…elete issues We made tweeks to the cascade delete behavior in 3.0 and also changed the default timing for when cascades happen. This change introduced several bugs which all result in deletion or severing of relationships instead of detaching them. This was then hit by more people due to the timing change. Issues: #19203 #19137 #18982 #16546
ajcvickers
added a commit
that referenced
this issue
Feb 13, 2020
…elete issues We made tweeks to the cascade delete behavior in 3.0 and also changed the default timing for when cascades happen. This change introduced several bugs which all result in deletion or severing of relationships instead of detaching them. This was then hit by more people due to the timing change. Issues: #19203 #19137 #18982 #16546
ajcvickers
added a commit
that referenced
this issue
Feb 15, 2020
…elete issues We made tweeks to the cascade delete behavior in 3.0 and also changed the default timing for when cascades happen. This change introduced several bugs which all result in deletion or severing of relationships instead of detaching them. This was then hit by more people due to the timing change. Issues: #19203 #19137 #18982 #16546
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
Servicing-approved
type-bug
I disable AutoDetectChanges and load some related records from different tables. When I detach some entity, all references to it are automatically nullified.
Everything worked well on EF Core 2.*.
Steps to reproduce
Further technical details
EF Core version: 3.1.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: NET Core 3.1
Operating system: Windows 10
IDE: Visual Studio 2019 16.4
The text was updated successfully, but these errors were encountered: