Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET - c# - Cross partition query is required but disabled trouble on DocumentDB data access

I have written the following code to fetch a record from the DocumentDB

private static void QueryDocuments1(DocumentClient client)
{

    IQueryable<SearchInput> queryable =
client.CreateDocumentQuery<SearchInput>(UriFactory.CreateDocumentCollectionUri(DocumentDBName, DocumentDBCollectionName))
        .Where(x => x.Receiver == "8907180");
    List<SearchInput> posts = queryable.ToList();
}

And it is showing the following error on the code line List<SearchInput> posts = queryable.ToList();

{"Cross partition query is required but disabled. Please set x-ms-documentdb-query-enablecrosspartition to true, specify x-ms-documentdb-partitionkey, or revise your query to avoid this exception.\r\nActivityId: xxxxxx-xxxx-xxx-xxx-xxxxxxx"}

Please help me on it...

like image 480
Prasanth V M Avatar asked Sep 12 '17 07:09

Prasanth V M


People also ask

Is C and .NET same?

C# is a programming language, . NET is a blanket term that tends to cover both the . NET Framework (an application framework library) and the Common Language Runtime which is the runtime in which . NET assemblies are run.

What is .NET C#?

C# (pronounced "See Sharp") is a modern, object-oriented, and type-safe programming language. C# enables developers to build many types of secure and robust applications that run in . NET. C# has its roots in the C family of languages and will be immediately familiar to C, C++, Java, and JavaScript programmers.

Is .NET based on C?

. NET was fully written in C and C++ because the base was in assembly language.

Is .NET only C#?

NET framework. . NET not only has C#, but through it, you can work with VB, F#, etc.


1 Answers

You should use CreateDocumentQuery method with FeedOptions object as a parameter, this class has a property for x-ms-documentdb-query-enablecrosspartition called EnableCrossPartitionQuery.

Please follow links https://msdn.microsoft.com/library/en-us/Dn850285.aspx For REST https://learn.microsoft.com/en-us/rest/api/documentdb/querying-documentdb-resources-using-the-rest-api

Example:

you should have

 var option = new FeedOptions { EnableCrossPartitionQuery = true };
 IQueryable<SearchInput> queryable = client.CreateDocumentQuery<SearchInput>
 (UriFactory.CreateDocumentCollectionUri(DocumentDBName, 
 DocumentDBCollectionName), option ) .Where(x => x.Receiver == "8907180");
like image 73
Oleksii Avatar answered Oct 13 '22 08:10

Oleksii