-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Closed as not planned
Closed as not planned
Copy link
Labels
Description
File a bug
When the InitializedInstance of IMaterializationInterceptor is called, only properties that belong to the current object are loaded, child entities (objects) fetched with Include() are not. On the position where I fetch the record from the database is the object loaded correctly with its childs.
Include your code
public interface IMaterializable
{
void OnMaterialized();
}
public class MaterializedInterceptor : IMaterializationInterceptor
{
public object InitializedInstance(MaterializationInterceptionData materializationData, object instance)
{
if (instance is IMaterializable materializable)
{
materializable.OnMaterialized();
}
return instance;
}
}
public class MyDbContext : IdentityDbContext
{
private static readonly MaterializedInterceptor _materializedInterceptor = new();
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.AddInterceptors(_materializedInterceptor);
}
}
public class Father() : IMaterializable
{
public int Id { get; set; }
public string Name { get; set; }
public Daughter Daughter { get; set; }
public List<Son> Sons { get; set; }
public void OnMaterialized()
{
// Id and Name are loaded
// Daughter and Sons are not loaded
}
}
public class Son() : IMaterializable
{
public int Id { get; set; }
public string Name { get; set; }
public void OnMaterialized()
{
}
}
public class Daughter() : IMaterializable
{
public int Id { get; set; }
public string Name { get; set; }
public void OnMaterialized()
{
}
}
public void GetFathers()
{
Father father = await _dbContext.Fathers.Include(b => b.Daughter).Include(i => i.Sons).FirstOrDefaultAsync();
// father.Daughter and father.Sons are loaded
}Include provider and version information
EF Core version: 7.0.14 and 8.0.0 (both)
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 8.0.100
Operating system: Windows 10
IDE: Visual Studio 2022 17.9.0 Preview 1.1
Reactions are currently unavailable