-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Closed
Bug
Copy link
Description
await using var context = new BlogContext();
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();
context.Blogs.Add(new Blog
{
Name = "Blog 1",
Related = new List<Related>
{
new Related { Title = "Related 1" },
new Related { Title = "Related 2" }
}
});
await context.SaveChangesAsync();
public class BlogContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseSqlServer("Server=localhost;Database=test;User=SA;Password=Abcd5678;Connect Timeout=60;ConnectRetryCount=0;Encrypt=false")
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Blog>()
.ComplexCollection(b => b.Related, rrb =>
{
rrb.ToJson();
rrb.ComplexProperty(r => r.Nested);
});
}
}
public class Blog
{
public int Id { get; set; }
public string Name { get; set; }
public List<Related> Related { get; set; }
}
public class Related
{
public int Foo { get; set; }
public string Title { get; set; }
public Nested Nested { get; set; }
}
public class Nested
{
public int Bar { get; set; }
public string Bla { get; set; }
}Exception:
System.Diagnostics.UnreachableException: Check.DebugAssert failed: Property Related not contained under Blog.Related#Related
at Microsoft.EntityFrameworkCore.Utilities.Check.DebugAssert(Boolean condition, String message) in /Users/roji/projects/efcore/src/Shared/Check.cs:line 112
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntryBase.GetCurrentValue(IPropertyBase propertyBase) in /Users/roji/projects/efcore/src/EFCore/ChangeTracking/Internal/InternalEntryBase.cs:line 913
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntryBase.<PrepareToSave>g__CheckForNullComplexProperties|99_2(<>c__DisplayClass99_0&) in /Users/roji/projects/efcore/src/EFCore/ChangeTracking/Internal/InternalEntryBase.cs:line 1645
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntryBase.PrepareToSave() in /Users/roji/projects/efcore/src/EFCore/ChangeTracking/Internal/InternalEntryBase.cs:line 1581
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntryBase.PrepareToSave() in /Users/roji/projects/efcore/src/EFCore/ChangeTracking/Internal/InternalEntryBase.cs:line 1612
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.GetEntriesToSave(Boolean cascadeChanges) in /Users/roji/projects/efcore/src/EFCore/ChangeTracking/Internal/StateManager.cs:line 1166
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(StateManager stateManager, Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken) in /Users/roji/projects/efcore/src/EFCore/ChangeTracking/Internal/StateManager.cs:l
Reactions are currently unavailable