efcore: Missing related data when inserting data into new item

I fetch the data from the database into a new declared object and I dont get the related data like I did in version 2.0.*.

Example:

public class SomeItem
{
     public int Id {get; set;}
     public List<OtherTable1> OtherTable1 {get;set}
}

var data = ctx.SomeTable.AsNoTracking()

.Include(x => x.OtherTable1)
.ThenInclude(x => x.OtherTable2)
.ThenInclude(x => x.SomeOtherTable)

.Include(x => x.OtherTable1)
.ThenInclude(x => x.OtherTable2)
.ThenInclude(x => x.SomeTypeTable)

.Select(c => new SomeItem {
    Id = c.Id,
    OtherTabledata = OtherTable1.ToList() <--This is missing the data from OtherTable2
}).ToList();

In my real life example OtherTable1 has a lot of Include/ThenInclude/ThenIncludes.

should I be doing something different in 2.1 or is this a bug/known issue?

No exceptions… except null exceptions…

Further technical details

EF Core version: 2.1 .Net Core version: 2.1 Database Provider: Microsoft.EntityFrameworkCore.SqlServer Operating system: Windows 2016 IDE: Visual Studio 2017 15.7.2

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 20 (11 by maintainers)

Most upvoted comments

@johanskoldekrans - Thanks for pointing out. I verified that there is no work-around yet.

Correlated subquery optimization causes the include annotations going through navigation being optimized to be ignored hence the navigation did not get populated. ~Work-around is to remove ToList to have 2.0 behavior.~