What is the default sorting of GetItemLinqQueryable?
See original GitHub issueI want to construct a query with optional parameters in LINQ, basically this code:
IOrderedQueryable<User> query = _userContainer.GetItemLinqQueryable<User>();
if (id != null)
{
query = query.Where(user => user.Id == id); // returns IQueryable
}
if (name != null)
{
query = query.Where(user => user.Name == name); // returns IQueryable
}
This doesn’t work because IQueryable cannot be assigned to IOrderedQueryable which GetItemLinqQueryable
returns.
To avoid doing an expensive sort operation my theory is that I can apply the same sorting that GetItemLinqQueryable
uses in each of these if-blocks. I didn’t find the default sort mentioned in the documentation, so anyone knows what it is?
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 0207c888-39da-2768-71b5-2fc219f5ebad
- Version Independent ID: 4ed5c6d6-170d-50a5-7ac2-e8e64bd7d0f6
- Content: Container.GetItemLinqQueryable<T>(Boolean, String, QueryRequestOptions, CosmosLinqSerializerOptions) Method (Microsoft.Azure.Cosmos) - Azure for .NET Developers
- Content Source: xml/Microsoft.Azure.Cosmos/Container.xml
- Service: cosmos-db
- GitHub Login: @rloutlaw
- Microsoft Alias: routlaw
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
Container.GetItemLinqQueryable<T> Method
(Optional) An IOrderedQueryable{T} that can evaluate the query. Examples. This example below shows LINQ query generation and blocked execution. C#
Read more >GetItemLinqQueryable doesn't return any items
I believe your issue has to do with how the linq query in serialized. By default GetItemLinqQueryable doesn't use camel case.
Read more >Error when using OrderBy on field with possible NULL ...
Specifies that the values in the specified column should be sorted in ascending or descending order. ASC sorts from the lowest value to...
Read more >Using LINQ to Query Dynamic Schema-less ... - Jeremy Likness
I have a database named url-tracking with a container named url-stats . Cosmos DB Database and Container. I set up these names in...
Read more >Specifying default sort order in EF using query interceptors
So first, I need a way to somehow define the property which the sorting should be based on, and somehow also indicate the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Sti2nd We are proceeding with the closure with the issue.
@Sti2nd The recommendation is to use GetItemQueryIterator for queries and the order in which the items are returned depends on the query. For a simple scan like
SELECT * FROM c
it would return in <partition, rid> order.