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
Description
When loading an entity from the DB, some owned dependent types are not fetched correctly using the SQL Server Provider. It happens when there is an owned dependent that itself references one or more owned dependents, but has no other primitive properties with a value.
Expected behavior
Owned types should always be fetched when one or more nested properties have a value.
Code to reproduce
usingSystem;usingSystem.Linq;usingMicrosoft.EntityFrameworkCore;usingNewtonsoft.Json;namespaceOwnedDependentNotIncludedInFetch{classProgram{staticvoidMain(string[]args){varaggregateRoot=newAnAggregateRoot{Id=Guid.NewGuid().ToString(),AProperty="My aggregate root",OwnedDependent1=newOwnedDependent1{MyProperty=null,// When this is null the nested owned dependent is not included in fetchOwnedDependent2=newOwnedDependent2{MyProperty="Nested owned dependent"}}};using(vardbContext=newExampleContext()){dbContext.Database.EnsureCreated();dbContext.AnAggregateRoots.Add(aggregateRoot);dbContext.SaveChanges();}using(vardbContext=newExampleContext()){varfetchedAggregateRoot=dbContext.AnAggregateRoots.Include(x =>x.OwnedDependent1).SingleOrDefault(x =>x.Id==aggregateRoot.Id);Console.WriteLine(JsonConvert.SerializeObject(fetchedAggregateRoot));}Console.ReadLine();}publicclassExampleContext:DbContext{publicDbSet<AnAggregateRoot>AnAggregateRoots{get;set;}protectedoverridevoidOnConfiguring(DbContextOptionsBuilderoptionsBuilder)=>optionsBuilder.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=TestDb;Trusted_Connection=True;MultipleActiveResultSets=true");protectedoverridevoidOnModelCreating(ModelBuildermodelBuilder){base.OnModelCreating(modelBuilder);modelBuilder.Entity<AnAggregateRoot>().HasKey(x =>x.Id);modelBuilder.Entity<AnAggregateRoot>().Property(x =>x.Id).ValueGeneratedNever();modelBuilder.Entity<AnAggregateRoot>().OwnsOne(x =>x.OwnedDependent1, x =>x.OwnsOne(y =>y.OwnedDependent2));}}publicclassAnAggregateRoot{publicstringId{get;set;}publicstringAProperty{get;set;}publicOwnedDependent1OwnedDependent1{get;set;}}publicclassOwnedDependent1{publicstringMyProperty{get;set;}publicOwnedDependent2OwnedDependent2{get;set;}}publicclassOwnedDependent2{publicstringMyProperty{get;set;}}}}
Console output:
{
"Id": "960c1a74-3bd7-4a42-a702-7c973c06fb19",
"AProperty": "My aggregate root",
"OwnedDependent1": null
}
Provider and version information
EF Core version:
EF Core version: 5.0.3
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET Core 3.1
Operating system: Windows 1909
IDE: Visual Studio 2019 16.7.6
This sample is working in EF Core 3.1.12 so it's a regression bug.
The text was updated successfully, but these errors were encountered:
Description
When loading an entity from the DB, some owned dependent types are not fetched correctly using the SQL Server Provider. It happens when there is an owned dependent that itself references one or more owned dependents, but has no other primitive properties with a value.
Expected behavior
Owned types should always be fetched when one or more nested properties have a value.
Code to reproduce
Console output:
Provider and version information
EF Core version:
EF Core version: 5.0.3
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET Core 3.1
Operating system: Windows 1909
IDE: Visual Studio 2019 16.7.6
This sample is working in EF Core 3.1.12 so it's a regression bug.
The text was updated successfully, but these errors were encountered: