-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nested Entities coming as null on reading using EF core 6 with Azure Cosmos DB #30055
Comments
@smalviya01 A couple of things. First, FindAsync does not automatically load related entities. Second, mapping the child entities to another container means that loading the parents and children requires joining across the two containers, which is generally a very bad idea with Cosmos DB. What is the reason for mapping these things to separate containers? How do you conceptualize the documents in the database and how they will be used? |
Hi @ajcvickers , Our usecase is we have a very complex object which we store in Mysql DB by mapping its child entities to different tables then using EF core to do CRUD operations. Its a huge object with very high volume (we store ~12 million records every month , Size of one JSON is ~34KB). That is why we decided to move to COSMOS DB with Azure Databricks so that we process this data faster. Best way our partition key gets created is < Platform + ClaimTypeId + Product + BusinessSegmentId + providerMpin> and if we just keep one Document as you are saying then the month on month growth of 34KB sized JSONs becomes more than 20GB per partition. It would even go beyond ~1TB as we are migrating 3 years data. |
@smalviya01 It may be that you can't get the best of both worlds here if you need to do cross-container queries. Can you post an example of what the JSON documents look like in each container? |
Here is what my cosmos db looks like with related containers - Here is the example of Documents - Here is ClaimResolutionModel (Child Entity)- Just One question here @ajcvickers , If Cosmos DB EF provider can map a Parent object and its child entities to their respective containers by itself then why can't it read from the containers and return the consolidated object? |
@ajcvickers any update on this? |
@smalviya01 This is currently by-design and not likely to change soon. However, we're still thinking about potential directions we could go in the future that might make this easier. /cc @roji |
By any chance will this be released before end of this year? and will it be in EF core 6 ? |
No, and no. |
Note from triage: this is covered by #16920 (comment) |
Ask a question
I have create a DB Context to map nested entities of an object to different containers, it works fine when writing to the database
it automatically writes nested entities to their respective containers from parent entity but when I am reading using
context.FindAsync(id) , nested entities are not retrieved and are null in the response. Below is the Db context I have created.
Note: All Nested entities have same Id and Same partition key as their Parent Entity.
Remember:
Include your code
DbContext -
Parent Entity Model-
Child Entity Example -
Include stack traces
Include the full exception message and stack trace for any exception you encounter.
Use triple-tick fences for stack traces. For example:
Include verbose output
Please include verbose output when asking questions about the
dotnet ef
or Package Manager Console tools.Use triple-tick fences for tool output. For example:
Include provider and version information
EF Core version: .nuget\packages\microsoft.entityframeworkcore.cosmos\6.0.10
Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Target framework: (e.g. .NET 6.0) : NET 6.0
Operating system: Windows
IDE: (e.g. Visual Studio 2022 17.4) : Visual Studio 2022
The text was updated successfully, but these errors were encountered: