Skip to content

gustavlarson/efcore-record-bug

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EF Core Bug: In-Memory Corruption with Record 'with' Expression

This repository demonstrates a bug in Entity Framework Core 10.0.2 where using C# record's with expression on an owned entity stored as JSON causes in-memory corruption after calling SaveChanges().

Link to EF core issue tracker: dotnet/efcore#37581

Bug Description

When working with owned entities stored as JSON and using C# record's with expression, EF Core corrupts the in-memory representation of nested owned entities after the second call to SaveChanges(). The data is correctly persisted to the database, but the in-memory object becomes corrupted.

Symptoms

  • NullReferenceException when accessing nested properties of the owned entity
  • Nested owned entities (e.g., Weight) become null in memory after SaveChanges()
  • The corruption only affects the in-memory object graph
  • Database contains the correct, uncorrupted data
  • Re-querying the entity from the database returns the correct data

Reproduction Steps

  1. Create an entity with an owned entity stored as JSON
  2. Add the entity to the context and call SaveChanges() (first save)
  3. Use the with expression to create a modified copy of the owned entity
  4. Call SaveChanges() again (second save)
  5. Bug manifests: Nested properties of the owned entity become null in memory

Environment

  • .NET Version: 10.0
  • EF Core Version: 10.0.2
  • Database: SQL Server 2022 (reproduced using Testcontainers)
  • Language Features: C# records with with expression

About

Reproduction of bug in EF Core

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages