Cosmos: How to configure DbContext for an infinite/recursive owned entity
See original GitHub issueHi!
Out of the documentation for Owned entities and cosmos, I cannot see if there is, or should be, a way to configure a DbContext so that an owned entity, that is recursive, will serialise the complete structure of the entity to Cosmos.
Steps to reproduce
- Create a containing Entity that ownes the recursive entity.
- Configure the DbContext with Owned for the recursive entity.
Since the recursive entity owns entities of itself, there should be a way to configure the context to just follow the navigation properties as long as there is relevant children populated in the entity graph.
This is what we would have:
//Entities
public class RootEntity
{
public string Id { get; set; }
public string PartitionKey { get; set; }
public string Name { get; set; }
public IEnumerable<RecursiveEntity> Children { get; set; }
}
public class RecursiveEntity
{
public string Name { get; set; }
public IEnumerable<RecursiveEntity> Children { get; set; }
}
//Context
modelBuilder.Owned<RecursiveEntity>();
modelBuilder.Entity<RootEntity>().HasPartitionKey(o => o.PartitionKey);
modelBuilder.Entity<RootEntity>().OwnsMany(p => p.Children);
Ideally in a pure Cosmos scenario this could be enough just to serialise the recursive structure(s) indefinitely since all entities in the RecursiveEntity are owned, but as of now we cannot find a way forward. We need a way to configure the DbContext to understand to navigate the recursive entity graph.
To set at fixed depth by nesting .OwnsMany()
in the context is unfortunately not an option in this case for the entities.
Further technical details
EF Core version: 3.1.0-preview3.19554.8 Database provider: Cosmos DB Target framework: .NET Core 3.1 Preview 3 Operating system: Mac OS X, Windows 10 IDE: Visual Studio Code
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:7 (4 by maintainers)
@gdahlin We’ll mention it in the breaking changes for the version in which it will change. There are currently no plans to change it.
@aladd04 We just discussed this as a team and it is not something we plan to implement.