-
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
Cosmos: Optimize Find
by querying by 'id'
#17310
Comments
Depends on #7391 to make the general case work, but before that is done that we can at least handle the case when the PK is |
@1iveowl The other option I mentioned in the comment above is to just handle the simple case where the PK consists of The next step up from this would be handling PKs that include the partition key, but don’t include the The above can be accomplished by detecting the query pattern generated by EntityFinder and instead of translating the query based on SelectExpression you'd need to create something like @smitpatel for thoughts or advice |
@1iveowl If the above doesn't fit in the time you can dedicate for this creating the extension you've proposed - |
ShapedQueryExpression does allow having an expression different than SelectExpression. It may require some conditional code in ShapedQueryCompilingExpressionVisitor. Or we can factor it differently to call shaper specific part outside of query pipeline. It would be a difficult change. Shaper compiler on cosmos is more complicated than core. |
@AndriySvyryd, @smitpatel Let's lock-in on the API first. A few questions
Where and how is the configuration of the DbSet determining the order of the two values specified/implied?
How will For Suggestion:Could the API be something like this: In which case, we assume a string and introduce a Cosmos specific syntax for If no delimiter ( The reason we don't assume myId in the single value scenario, is that this wouldn't work if the access key supplied is a resource token, rather than a master key. Alternatively we'd need to also check what type of access key is supplied and thrown a meaningful exception based on that, to guide the developer. |
@1iveowl The PK is configured in this way: modelBuilder.Entity<Car>().HasKey(c => new { c.State, c.LicensePlate, c.PartitionKey });
User always needs to specify all PK values in context.Set<Car>().Find("WA", "999ZZZ", "1234"); Currently this would translate into something like SELECT * from c
WHERE c.State = "WA" AND c.Plate = "999ZZZ" AND c.PartitionKey = "1234" But in most cases we know how to generate the
Yes, so the simple case is where the entity type is configured like this: modelBuilder.Entity<Car>().HasKey(c => new { c.id, c.PartitionKey }); So the context.Set<Car>().Find("WA|999ZZZ", "1234");
This doesn't follow current API conventions and would be confusing for existing EF users. |
Thank you @AndriySvyryd. Good comments. One more thing regarding:
This helps us build the query, but how do we identify the partition key explicitly? The example tricks us, because it's so obvious that the third value is the partition key. However it might as well have looked like this:. I guess for the generic |
Yes |
Regarding:
In this example, the assumption is made, that the However, in a scenario were the Cosmos documents were not created by EF.Core/Cosmosthe |
It's up to the user to provide the correct value generator, we'd just use whatever is configured on |
Ahh yes, using PropertyBuilder.HasValueGenerator Method. |
Add event ids Make GetProperty public Fix bad merge Part of #17310
Add event ids Make GetProperty public Fix bad merge Part of #17310
@bricelam Should this be in rc1? /cc @AndriySvyryd |
It shipped in preview 4 |
(I was cleaning up some closed issues on the Backlog) |
Use ReadItem
Include the partition key if present
The text was updated successfully, but these errors were encountered: