DocumentClient.CreateDocumentQuery DocumentClient.CreateDocumentQuery Method

Definition

Overloads

CreateDocumentQuery(String, SqlQuerySpec, FeedOptions, Object) CreateDocumentQuery(String, SqlQuerySpec, FeedOptions, Object)

Overloaded. This method creates a query for documents under a collection in an Azure Cosmos DB database using a SQL statement with parameterized values. It returns an IQueryable{dynamic}. For more information on preparing SQL statements with parameterized values, please see SqlQuerySpec.

CreateDocumentQuery(String, String, FeedOptions, Object) CreateDocumentQuery(String, String, FeedOptions, Object)

Overloaded. This method creates a query for documents under a collection in an Azure Cosmos DB database using a SQL statement. It returns an IQueryable{dynamic}.

CreateDocumentQuery(Uri, String, FeedOptions) CreateDocumentQuery(Uri, String, FeedOptions)

Extension method to create a query for documents in the Azure Cosmos DB service.

CreateDocumentQuery(Uri, String, FeedOptions, Object) CreateDocumentQuery(Uri, String, FeedOptions, Object)

Extension method to create a query for documents in the Azure Cosmos DB service.

CreateDocumentQuery(Uri, SqlQuerySpec, FeedOptions, Object) CreateDocumentQuery(Uri, SqlQuerySpec, FeedOptions, Object)

Extension method to create a query for documents in the Azure Cosmos DB service.

CreateDocumentQuery(Uri, SqlQuerySpec, FeedOptions) CreateDocumentQuery(Uri, SqlQuerySpec, FeedOptions)

Extension method to create a query for documents in the Azure Cosmos DB service.

CreateDocumentQuery(String, String, FeedOptions) CreateDocumentQuery(String, String, FeedOptions)

Overloaded. This method creates a query for documents under a collection in an Azure Cosmos DB database using a SQL statement. It returns an IQueryable{dynamic}.

CreateDocumentQuery(String, SqlQuerySpec, FeedOptions) CreateDocumentQuery(String, SqlQuerySpec, FeedOptions)

Overloaded. This method creates a query for documents under a collection in an Azure Cosmos DB database using a SQL statement with parameterized values. It returns an IQueryable{dynamic}. For more information on preparing SQL statements with parameterized values, please see SqlQuerySpec.

CreateDocumentQuery(String, FeedOptions, Object) CreateDocumentQuery(String, FeedOptions, Object)

Overloaded. This method creates a query for documents under a collection in an Azure Cosmos DB service. It returns IOrderedQueryable{Document}.

CreateDocumentQuery(Uri, FeedOptions) CreateDocumentQuery(Uri, FeedOptions)

Extension method to create a query for documents in the Azure Cosmos DB service.

CreateDocumentQuery(String, FeedOptions) CreateDocumentQuery(String, FeedOptions)

Overloaded. This method creates a query for documents under a collection in an Azure Cosmos DB service. It returns IOrderedQueryable{Document}.

CreateDocumentQuery(Uri, FeedOptions, Object) CreateDocumentQuery(Uri, FeedOptions, Object)

Extension method to create a query for documents in the Azure Cosmos DB service.

CreateDocumentQuery<T>(Uri, SqlQuerySpec, FeedOptions) CreateDocumentQuery<T>(Uri, SqlQuerySpec, FeedOptions)

Extension method to create a query for documents in the Azure Cosmos DB service.

CreateDocumentQuery<T>(Uri, String, FeedOptions, Object) CreateDocumentQuery<T>(Uri, String, FeedOptions, Object)

Extension method to create a query for documents in the Azure Cosmos DB service.

CreateDocumentQuery<T>(Uri, SqlQuerySpec, FeedOptions, Object) CreateDocumentQuery<T>(Uri, SqlQuerySpec, FeedOptions, Object)

Extension method to create a query for documents for the Azure Cosmos DB service.

CreateDocumentQuery<T>(String, String, FeedOptions, Object) CreateDocumentQuery<T>(String, String, FeedOptions, Object)

Overloaded. This method creates a query for documents under a collection in an Azure Cosmos DB database using a SQL statement. It returns an IQueryable{T}.

CreateDocumentQuery<T>(String, SqlQuerySpec, FeedOptions, Object) CreateDocumentQuery<T>(String, SqlQuerySpec, FeedOptions, Object)

Overloaded. This method creates a query for documents under a collection in an Azure Cosmos DB database using a SQL statement with parameterized values. It returns an IQueryable{T}. For more information on preparing SQL statements with parameterized values, please see SqlQuerySpec.

CreateDocumentQuery<T>(Uri, String, FeedOptions) CreateDocumentQuery<T>(Uri, String, FeedOptions)

Extension method to create a query for documents in the Azure Cosmos DB service.

CreateDocumentQuery<T>(Uri, FeedOptions, Object) CreateDocumentQuery<T>(Uri, FeedOptions, Object)

Extension method to create a query for documents in the Azure Cosmos DB service.

CreateDocumentQuery<T>(String, String, FeedOptions) CreateDocumentQuery<T>(String, String, FeedOptions)

Overloaded. This method creates a query for documents under a collection in an Azure Cosmos DB database using a SQL statement. It returns an IQueryable{T}.

CreateDocumentQuery<T>(String, SqlQuerySpec, FeedOptions) CreateDocumentQuery<T>(String, SqlQuerySpec, FeedOptions)

Overloaded. This method creates a query for documents under a collection in an Azure Cosmos DB database using a SQL statement with parameterized values. It returns an IQueryable{T}. For more information on preparing SQL statements with parameterized values, please see SqlQuerySpec.

CreateDocumentQuery<T>(String, FeedOptions, Object) CreateDocumentQuery<T>(String, FeedOptions, Object)

Overloaded. This method creates a query for documents under a collection in an Azure Cosmos DB service.

CreateDocumentQuery<T>(Uri, FeedOptions) CreateDocumentQuery<T>(Uri, FeedOptions)

Extension method to create a query for documents in the Azure Cosmos DB service.

CreateDocumentQuery<T>(String, FeedOptions) CreateDocumentQuery<T>(String, FeedOptions)

Overloaded. This method creates a query for documents under a collection in an Azure Cosmos DB service.

CreateDocumentQuery(String, SqlQuerySpec, FeedOptions, Object) CreateDocumentQuery(String, SqlQuerySpec, FeedOptions, Object)

Warning

This API is now obsolete.

Overloaded. This method creates a query for documents under a collection in an Azure Cosmos DB database using a SQL statement with parameterized values. It returns an IQueryable{dynamic}. For more information on preparing SQL statements with parameterized values, please see SqlQuerySpec.

[System.Obsolete("Support for IPartitionResolver based method overloads is now obsolete. It's recommended that you use partitioned collections for higher storage and throughput. Please use the override that does not take a partitionKey parameter.")]
public System.Linq.IQueryable<dynamic> CreateDocumentQuery (string collectionLink, Microsoft.Azure.Documents.SqlQuerySpec querySpec, Microsoft.Azure.Documents.Client.FeedOptions feedOptions, object partitionKey);
member this.CreateDocumentQuery : string * Microsoft.Azure.Documents.SqlQuerySpec * Microsoft.Azure.Documents.Client.FeedOptions * obj -> System.Linq.IQueryable<obj>

Parameters

collectionLink
String String

The link to the parent document collection. Alternatively, this can be a path link to the database when using an IPartitionResolver, e.g. dbs/db_rid/

querySpec
SqlQuerySpec SqlQuerySpec

The SqlQuerySpec instance containing the SQL expression.

feedOptions
FeedOptions FeedOptions

The options for processing the query result feed. For details, see FeedOptions

partitionKey
Object Object

The partition key that can be used with an IPartitionResolver.

Returns

an IQueryable{dynamic> that can evaluate the query.

Remarks

Support for IPartitionResolver based method overloads is now obsolete. It's recommended that you use Partitioned Collections for higher storage and throughput.

CreateDocumentQuery(String, String, FeedOptions, Object) CreateDocumentQuery(String, String, FeedOptions, Object)

Warning

This API is now obsolete.

Overloaded. This method creates a query for documents under a collection in an Azure Cosmos DB database using a SQL statement. It returns an IQueryable{dynamic}.

[System.Obsolete("Support for IPartitionResolver based method overloads is now obsolete. It's recommended that you use partitioned collections for higher storage and throughput. Please use the override that does not take a partitionKey parameter.")]
public System.Linq.IQueryable<dynamic> CreateDocumentQuery (string collectionLink, string sqlExpression, Microsoft.Azure.Documents.Client.FeedOptions feedOptions, object partitionKey);
member this.CreateDocumentQuery : string * string * Microsoft.Azure.Documents.Client.FeedOptions * obj -> System.Linq.IQueryable<obj>

Parameters

collectionLink
String String

The link of the parent document collection. Alternatively, this can be a path link to the database when using an IPartitionResolver, e.g. dbs/db_rid/

sqlExpression
String String

The SQL statement.

feedOptions
FeedOptions FeedOptions

The options for processing the query result feed. For details, see FeedOptions

partitionKey
Object Object

The partition key that can be used with an IPartitionResolver.

Returns

an IQueryable{dynamic> that can evaluate the query.

Remarks

Support for IPartitionResolver based method overloads is now obsolete. It's recommended that you use Partitioned Collections for higher storage and throughput.

CreateDocumentQuery(Uri, String, FeedOptions) CreateDocumentQuery(Uri, String, FeedOptions)

Extension method to create a query for documents in the Azure Cosmos DB service.

public System.Linq.IQueryable<dynamic> CreateDocumentQuery (Uri documentCollectionOrDatabaseUri, string sqlExpression, Microsoft.Azure.Documents.Client.FeedOptions feedOptions = null);
abstract member CreateDocumentQuery : Uri * string * Microsoft.Azure.Documents.Client.FeedOptions -> System.Linq.IQueryable<obj>
override this.CreateDocumentQuery : Uri * string * Microsoft.Azure.Documents.Client.FeedOptions -> System.Linq.IQueryable<obj>

Parameters

documentCollectionOrDatabaseUri
Uri Uri

The URI of the document collection.

sqlExpression
String String

The sql query.

feedOptions
FeedOptions FeedOptions

The options for processing the query results feed.

Returns

The query result set.

Implements

CreateDocumentQuery(Uri, String, FeedOptions, Object) CreateDocumentQuery(Uri, String, FeedOptions, Object)

Warning

This API is now obsolete.

Extension method to create a query for documents in the Azure Cosmos DB service.

[System.Obsolete("Support for IPartitionResolver based method overloads is now obsolete. It's recommended that you use partitioned collections for higher storage and throughput. Please use the override that does not take a partitionKey parameter.")]
public System.Linq.IQueryable<dynamic> CreateDocumentQuery (Uri documentCollectionOrDatabaseUri, string sqlExpression, Microsoft.Azure.Documents.Client.FeedOptions feedOptions, object partitionKey);
member this.CreateDocumentQuery : Uri * string * Microsoft.Azure.Documents.Client.FeedOptions * obj -> System.Linq.IQueryable<obj>

Parameters

documentCollectionOrDatabaseUri
Uri Uri

The URI of the document collection, e.g. dbs/db_rid/colls/coll_rid/. Alternatively, this can be a URI of the database when using an IPartitionResolver, e.g. dbs/db_rid/

sqlExpression
String String

The sql query.

feedOptions
FeedOptions FeedOptions

The options for processing the query results feed.

partitionKey
Object Object

The partition key that can be used with an IPartitionResolver.

Returns

The query result set.

Remarks

Support for IPartitionResolver based method overloads is now obsolete. It's recommended that you use Partitioned Collections for higher storage and throughput.

CreateDocumentQuery(Uri, SqlQuerySpec, FeedOptions, Object) CreateDocumentQuery(Uri, SqlQuerySpec, FeedOptions, Object)

Warning

This API is now obsolete.

Extension method to create a query for documents in the Azure Cosmos DB service.

[System.Obsolete("Support for IPartitionResolver based method overloads is now obsolete. It's recommended that you use partitioned collections for higher storage and throughput. Please use the override that does not take a partitionKey parameter.")]
public System.Linq.IQueryable<dynamic> CreateDocumentQuery (Uri documentCollectionOrDatabaseUri, Microsoft.Azure.Documents.SqlQuerySpec querySpec, Microsoft.Azure.Documents.Client.FeedOptions feedOptions, object partitionKey);
member this.CreateDocumentQuery : Uri * Microsoft.Azure.Documents.SqlQuerySpec * Microsoft.Azure.Documents.Client.FeedOptions * obj -> System.Linq.IQueryable<obj>

Parameters

documentCollectionOrDatabaseUri
Uri Uri

The URI of the document collection, e.g. dbs/db_rid/colls/coll_rid/. Alternatively, this can be a URI of the database when using an IPartitionResolver, e.g. dbs/db_rid/

querySpec
SqlQuerySpec SqlQuerySpec

The sql query.

feedOptions
FeedOptions FeedOptions

The options for processing the query results feed.

partitionKey
Object Object

The partition key that can be used with an IPartitionResolver.

Returns

The query result set.

Remarks

Support for IPartitionResolver based method overloads is now obsolete. It's recommended that you use Partitioned Collections for higher storage and throughput.

CreateDocumentQuery(Uri, SqlQuerySpec, FeedOptions) CreateDocumentQuery(Uri, SqlQuerySpec, FeedOptions)

Extension method to create a query for documents in the Azure Cosmos DB service.

public System.Linq.IQueryable<dynamic> CreateDocumentQuery (Uri documentCollectionOrDatabaseUri, Microsoft.Azure.Documents.SqlQuerySpec querySpec, Microsoft.Azure.Documents.Client.FeedOptions feedOptions = null);
abstract member CreateDocumentQuery : Uri * Microsoft.Azure.Documents.SqlQuerySpec * Microsoft.Azure.Documents.Client.FeedOptions -> System.Linq.IQueryable<obj>
override this.CreateDocumentQuery : Uri * Microsoft.Azure.Documents.SqlQuerySpec * Microsoft.Azure.Documents.Client.FeedOptions -> System.Linq.IQueryable<obj>

Parameters

documentCollectionOrDatabaseUri
Uri Uri

The URI of the document collection.

querySpec
SqlQuerySpec SqlQuerySpec

The sql query.

feedOptions
FeedOptions FeedOptions

The options for processing the query results feed.

Returns

The query result set.

Implements

CreateDocumentQuery(String, String, FeedOptions) CreateDocumentQuery(String, String, FeedOptions)

Overloaded. This method creates a query for documents under a collection in an Azure Cosmos DB database using a SQL statement. It returns an IQueryable{dynamic}.

public System.Linq.IQueryable<dynamic> CreateDocumentQuery (string collectionLink, string sqlExpression, Microsoft.Azure.Documents.Client.FeedOptions feedOptions = null);
abstract member CreateDocumentQuery : string * string * Microsoft.Azure.Documents.Client.FeedOptions -> System.Linq.IQueryable<obj>
override this.CreateDocumentQuery : string * string * Microsoft.Azure.Documents.Client.FeedOptions -> System.Linq.IQueryable<obj>

Parameters

collectionLink
String String

The link to the parent document collection.

sqlExpression
String String

The SQL statement.

feedOptions
FeedOptions FeedOptions

The options for processing the query result feed. For details, see FeedOptions

Returns

an IQueryable{dynamic> that can evaluate the query.

Implements

Examples

This example below queries for book documents.


// SQL querying allows dynamic property access
dynamic document = client.CreateDocumentQuery<dynamic>(collectionLink,
    "SELECT * FROM books b WHERE b.title == 'War and Peace'").AsEnumerable().FirstOrDefault();

Remarks

Refer to https://msdn.microsoft.com/en-us/library/azure/dn782250.aspx and http://azure.microsoft.com/documentation/articles/documentdb-sql-query/ for syntax and examples.

See also

CreateDocumentQuery(String, SqlQuerySpec, FeedOptions) CreateDocumentQuery(String, SqlQuerySpec, FeedOptions)

Overloaded. This method creates a query for documents under a collection in an Azure Cosmos DB database using a SQL statement with parameterized values. It returns an IQueryable{dynamic}. For more information on preparing SQL statements with parameterized values, please see SqlQuerySpec.

public System.Linq.IQueryable<dynamic> CreateDocumentQuery (string collectionLink, Microsoft.Azure.Documents.SqlQuerySpec querySpec, Microsoft.Azure.Documents.Client.FeedOptions feedOptions = null);
abstract member CreateDocumentQuery : string * Microsoft.Azure.Documents.SqlQuerySpec * Microsoft.Azure.Documents.Client.FeedOptions -> System.Linq.IQueryable<obj>
override this.CreateDocumentQuery : string * Microsoft.Azure.Documents.SqlQuerySpec * Microsoft.Azure.Documents.Client.FeedOptions -> System.Linq.IQueryable<obj>

Parameters

collectionLink
String String

The link to the parent document collection.

querySpec
SqlQuerySpec SqlQuerySpec

The SqlQuerySpec instance containing the SQL expression.

feedOptions
FeedOptions FeedOptions

The options for processing the query result feed. For details, see FeedOptions

Returns

an IQueryable{dynamic> that can evaluate the query.

Implements

Examples

This example below queries for book documents.


// SQL querying allows dynamic property access
var query = new SqlQuerySpec(
    "SELECT * FROM books b WHERE b.title = @title", 
    new SqlParameterCollection(new SqlParameter[] { new SqlParameter { Name = "@title", Value = "War and Peace" }}));
    
dynamic document = client.CreateDocumentQuery<dynamic>(collectionLink, query).AsEnumerable().FirstOrDefault();

Remarks

Refer to https://msdn.microsoft.com/en-us/library/azure/dn782250.aspx and http://azure.microsoft.com/documentation/articles/documentdb-sql-query/ for syntax and examples.

See also

CreateDocumentQuery(String, FeedOptions, Object) CreateDocumentQuery(String, FeedOptions, Object)

Warning

This API is now obsolete.

Overloaded. This method creates a query for documents under a collection in an Azure Cosmos DB service. It returns IOrderedQueryable{Document}.

[System.Obsolete("Support for IPartitionResolver based method overloads is now obsolete. It's recommended that you use partitioned collections for higher storage and throughput. Please use the override that does not take a partitionKey parameter.")]
public System.Linq.IOrderedQueryable<Microsoft.Azure.Documents.Document> CreateDocumentQuery (string collectionLink, Microsoft.Azure.Documents.Client.FeedOptions feedOptions, object partitionKey);
member this.CreateDocumentQuery : string * Microsoft.Azure.Documents.Client.FeedOptions * obj -> System.Linq.IOrderedQueryable<Microsoft.Azure.Documents.Document>

Parameters

collectionLink
String String

The link to the parent document collection. Alternatively, this can be a path link to the database when using an IPartitionResolver.

feedOptions
FeedOptions FeedOptions

The options for processing the query result feed. For details, see FeedOptions

partitionKey
Object Object

Optional partition key that can be used with an IPartitionResolver.

Returns

An IOrderedQueryable{Document} that can evaluate the query.

Remarks

Support for IPartitionResolver based method overloads is now obsolete. It's recommended that you use Partitioned Collections for higher storage and throughput.

CreateDocumentQuery(Uri, FeedOptions) CreateDocumentQuery(Uri, FeedOptions)

Extension method to create a query for documents in the Azure Cosmos DB service.

public System.Linq.IOrderedQueryable<Microsoft.Azure.Documents.Document> CreateDocumentQuery (Uri documentCollectionOrDatabaseUri, Microsoft.Azure.Documents.Client.FeedOptions feedOptions = null);
abstract member CreateDocumentQuery : Uri * Microsoft.Azure.Documents.Client.FeedOptions -> System.Linq.IOrderedQueryable<Microsoft.Azure.Documents.Document>
override this.CreateDocumentQuery : Uri * Microsoft.Azure.Documents.Client.FeedOptions -> System.Linq.IOrderedQueryable<Microsoft.Azure.Documents.Document>

Parameters

documentCollectionOrDatabaseUri
Uri Uri

The URI of the document collection.

feedOptions
FeedOptions FeedOptions

The options for processing the query results feed.

Returns

The query result set.

Implements

CreateDocumentQuery(String, FeedOptions) CreateDocumentQuery(String, FeedOptions)

Overloaded. This method creates a query for documents under a collection in an Azure Cosmos DB service. It returns IOrderedQueryable{Document}.

public System.Linq.IOrderedQueryable<Microsoft.Azure.Documents.Document> CreateDocumentQuery (string collectionLink, Microsoft.Azure.Documents.Client.FeedOptions feedOptions = null);
abstract member CreateDocumentQuery : string * Microsoft.Azure.Documents.Client.FeedOptions -> System.Linq.IOrderedQueryable<Microsoft.Azure.Documents.Document>
override this.CreateDocumentQuery : string * Microsoft.Azure.Documents.Client.FeedOptions -> System.Linq.IOrderedQueryable<Microsoft.Azure.Documents.Document>

Parameters

collectionLink
String String

The link to the parent document collection.

feedOptions
FeedOptions FeedOptions

The options for processing the query result feed. For details, see FeedOptions

Returns

An IOrderedQueryable{Document} that can evaluate the query.

Implements

Examples

This example below queries for documents by id.


 Document document = client.CreateDocumentQuery<Document>(collectionLink)
     .Where(d => d.Id == "War and Peace").AsEnumerable().FirstOrDefault();

 

Remarks

This overload should be used when the schema of the queried documents is unknown or when querying by ID and replacing/deleting documents.

Since Document is a DynamicObject, it can be dynamically cast back to the original C# object.

See also

CreateDocumentQuery(Uri, FeedOptions, Object) CreateDocumentQuery(Uri, FeedOptions, Object)

Warning

This API is now obsolete.

Extension method to create a query for documents in the Azure Cosmos DB service.

[System.Obsolete("Support for IPartitionResolver based method overloads is now obsolete. It's recommended that you use partitioned collections for higher storage and throughput. Please use the override that does not take a partitionKey parameter.")]
public System.Linq.IOrderedQueryable<Microsoft.Azure.Documents.Document> CreateDocumentQuery (Uri documentCollectionOrDatabaseUri, Microsoft.Azure.Documents.Client.FeedOptions feedOptions, object partitionKey);
member this.CreateDocumentQuery : Uri * Microsoft.Azure.Documents.Client.FeedOptions * obj -> System.Linq.IOrderedQueryable<Microsoft.Azure.Documents.Document>

Parameters

documentCollectionOrDatabaseUri
Uri Uri

The URI of the document collection, e.g. dbs/db_rid/colls/coll_rid/. Alternatively, this can be a URI of the database when using an IPartitionResolver, e.g. dbs/db_rid/

feedOptions
FeedOptions FeedOptions

The options for processing the query results feed.

partitionKey
Object Object

The partition key that can be used with an IPartitionResolver.

Returns

The query result set.

Remarks

Support for IPartitionResolver based method overloads is now obsolete. It's recommended that you use Partitioned Collections for higher storage and throughput.

CreateDocumentQuery<T>(Uri, SqlQuerySpec, FeedOptions) CreateDocumentQuery<T>(Uri, SqlQuerySpec, FeedOptions)

Extension method to create a query for documents in the Azure Cosmos DB service.

public System.Linq.IQueryable<T> CreateDocumentQuery<T> (Uri documentCollectionOrDatabaseUri, Microsoft.Azure.Documents.SqlQuerySpec querySpec, Microsoft.Azure.Documents.Client.FeedOptions feedOptions = null);
abstract member CreateDocumentQuery : Uri * Microsoft.Azure.Documents.SqlQuerySpec * Microsoft.Azure.Documents.Client.FeedOptions -> System.Linq.IQueryable<'T>
override this.CreateDocumentQuery : Uri * Microsoft.Azure.Documents.SqlQuerySpec * Microsoft.Azure.Documents.Client.FeedOptions -> System.Linq.IQueryable<'T>

Type Parameters

T

The type of object to query.

Parameters

documentCollectionOrDatabaseUri
Uri Uri

The URI of the document collection.

querySpec
SqlQuerySpec SqlQuerySpec

The sql query.

feedOptions
FeedOptions FeedOptions

The options for processing the query results feed.

Returns

The query result set.

Implements

CreateDocumentQuery<T>(Uri, String, FeedOptions, Object) CreateDocumentQuery<T>(Uri, String, FeedOptions, Object)

Warning

This API is now obsolete.

Extension method to create a query for documents in the Azure Cosmos DB service.

[System.Obsolete("Support for IPartitionResolver based method overloads is now obsolete. It's recommended that you use partitioned collections for higher storage and throughput. Please use the override that does not take a partitionKey parameter.")]
public System.Linq.IQueryable<T> CreateDocumentQuery<T> (Uri documentCollectionOrDatabaseUri, string sqlExpression, Microsoft.Azure.Documents.Client.FeedOptions feedOptions, object partitionKey);
member this.CreateDocumentQuery : Uri * string * Microsoft.Azure.Documents.Client.FeedOptions * obj -> System.Linq.IQueryable<'T>

Type Parameters

T

The type of object to query.

Parameters

documentCollectionOrDatabaseUri
Uri Uri

The URI of the document collection, e.g. dbs/db_rid/colls/coll_rid/. Alternatively, this can be a URI of the database when using an IPartitionResolver, e.g. dbs/db_rid/

sqlExpression
String String

The sql query.

feedOptions
FeedOptions FeedOptions

The options for processing the query results feed.

partitionKey
Object Object

The partition key that can be used with an IPartitionResolver.

Returns

The query result set.

Remarks

Support for IPartitionResolver based method overloads is now obsolete. It's recommended that you use Partitioned Collections for higher storage and throughput.

CreateDocumentQuery<T>(Uri, SqlQuerySpec, FeedOptions, Object) CreateDocumentQuery<T>(Uri, SqlQuerySpec, FeedOptions, Object)

Warning

This API is now obsolete.

Extension method to create a query for documents for the Azure Cosmos DB service.

[System.Obsolete("Support for IPartitionResolver based method overloads is now obsolete. It's recommended that you use partitioned collections for higher storage and throughput. Please use the override that does not take a partitionKey parameter.")]
public System.Linq.IQueryable<T> CreateDocumentQuery<T> (Uri documentCollectionOrDatabaseUri, Microsoft.Azure.Documents.SqlQuerySpec querySpec, Microsoft.Azure.Documents.Client.FeedOptions feedOptions, object partitionKey);
member this.CreateDocumentQuery : Uri * Microsoft.Azure.Documents.SqlQuerySpec * Microsoft.Azure.Documents.Client.FeedOptions * obj -> System.Linq.IQueryable<'T>

Type Parameters

T

The type of object to query.

Parameters

documentCollectionOrDatabaseUri
Uri Uri

The URI of the document collection, e.g. dbs/db_rid/colls/coll_rid/. Alternatively, this can be a URI of the database when using an IPartitionResolver, e.g. dbs/db_rid/

querySpec
SqlQuerySpec SqlQuerySpec

The sql query.

feedOptions
FeedOptions FeedOptions

The options for processing the query results feed.

partitionKey
Object Object

The partition key that can be used with an IPartitionResolver.

Returns

The query result set.

Remarks

Support for IPartitionResolver based method overloads is now obsolete. It's recommended that you use Partitioned Collections for higher storage and throughput.

CreateDocumentQuery<T>(String, String, FeedOptions, Object) CreateDocumentQuery<T>(String, String, FeedOptions, Object)

Warning

This API is now obsolete.

Overloaded. This method creates a query for documents under a collection in an Azure Cosmos DB database using a SQL statement. It returns an IQueryable{T}.

[System.Obsolete("Support for IPartitionResolver based method overloads is now obsolete. It's recommended that you use partitioned collections for higher storage and throughput. Please use the override that does not take a partitionKey parameter.")]
public System.Linq.IQueryable<T> CreateDocumentQuery<T> (string collectionLink, string sqlExpression, Microsoft.Azure.Documents.Client.FeedOptions feedOptions, object partitionKey);
member this.CreateDocumentQuery : string * string * Microsoft.Azure.Documents.Client.FeedOptions * obj -> System.Linq.IQueryable<'T>

Type Parameters

T

The type of object to query.

Parameters

collectionLink
String String

The path link for the documents under a collection, e.g. dbs/db_rid/colls/coll_rid/docs/. Alternatively, this can be a path link to the database when using an IPartitionResolver, e.g. dbs/db_rid/

sqlExpression
String String

The SQL statement.

feedOptions
FeedOptions FeedOptions

The options for processing the query result feed. For details, see FeedOptions

partitionKey
Object Object

The partition key that can be used with an IPartitionResolver.

Returns

An IQueryable{T} that can evaluate the query.

Remarks

Support for IPartitionResolver based method overloads is now obsolete. It's recommended that you use Partitioned Collections for higher storage and throughput.

CreateDocumentQuery<T>(String, SqlQuerySpec, FeedOptions, Object) CreateDocumentQuery<T>(String, SqlQuerySpec, FeedOptions, Object)

Warning

This API is now obsolete.

Overloaded. This method creates a query for documents under a collection in an Azure Cosmos DB database using a SQL statement with parameterized values. It returns an IQueryable{T}. For more information on preparing SQL statements with parameterized values, please see SqlQuerySpec.

[System.Obsolete("Support for IPartitionResolver based method overloads is now obsolete. It's recommended that you use partitioned collections for higher storage and throughput. Please use the override that does not take a partitionKey parameter.")]
public System.Linq.IQueryable<T> CreateDocumentQuery<T> (string collectionLink, Microsoft.Azure.Documents.SqlQuerySpec querySpec, Microsoft.Azure.Documents.Client.FeedOptions feedOptions, object partitionKey);
member this.CreateDocumentQuery : string * Microsoft.Azure.Documents.SqlQuerySpec * Microsoft.Azure.Documents.Client.FeedOptions * obj -> System.Linq.IQueryable<'T>

Type Parameters

T

The type of object to query.

Parameters

collectionLink
String String

The link to the parent document collection. Alternatively, this can be a path link to the database when using an IPartitionResolver.

querySpec
SqlQuerySpec SqlQuerySpec

The SqlQuerySpec instance containing the SQL expression.

feedOptions
FeedOptions FeedOptions

The options for processing the query result feed. For details, see FeedOptions

partitionKey
Object Object

The partition key that can be used with an IPartitionResolver.

Returns

An IQueryable{T} that can evaluate the query.

Remarks

Support for IPartitionResolver based method overloads is now obsolete. It's recommended that you use Partitioned Collections for higher storage and throughput.

CreateDocumentQuery<T>(Uri, String, FeedOptions) CreateDocumentQuery<T>(Uri, String, FeedOptions)

Extension method to create a query for documents in the Azure Cosmos DB service.

public System.Linq.IQueryable<T> CreateDocumentQuery<T> (Uri documentCollectionOrDatabaseUri, string sqlExpression, Microsoft.Azure.Documents.Client.FeedOptions feedOptions = null);
abstract member CreateDocumentQuery : Uri * string * Microsoft.Azure.Documents.Client.FeedOptions -> System.Linq.IQueryable<'T>
override this.CreateDocumentQuery : Uri * string * Microsoft.Azure.Documents.Client.FeedOptions -> System.Linq.IQueryable<'T>

Type Parameters

T

the type of object to query.

Parameters

documentCollectionOrDatabaseUri
Uri Uri

The URI of the document collection.

sqlExpression
String String

The sql query.

feedOptions
FeedOptions FeedOptions

The options for processing the query results feed.

Returns

The query result set.

Implements

CreateDocumentQuery<T>(Uri, FeedOptions, Object) CreateDocumentQuery<T>(Uri, FeedOptions, Object)

Warning

This API is now obsolete.

Extension method to create a query for documents in the Azure Cosmos DB service.

[System.Obsolete("Support for IPartitionResolver based method overloads is now obsolete. Please use the override that does not take a partitionKey parameter.")]
public System.Linq.IOrderedQueryable<T> CreateDocumentQuery<T> (Uri documentCollectionOrDatabaseUri, Microsoft.Azure.Documents.Client.FeedOptions feedOptions, object partitionKey);
member this.CreateDocumentQuery : Uri * Microsoft.Azure.Documents.Client.FeedOptions * obj -> System.Linq.IOrderedQueryable<'T>

Type Parameters

T

the type of object to query.

Parameters

documentCollectionOrDatabaseUri
Uri Uri

The URI of the document collection, e.g. dbs/db_rid/colls/coll_rid/. Alternatively, this can be a URI of the database when using an IPartitionResolver, e.g. dbs/db_rid/

feedOptions
FeedOptions FeedOptions

The options for processing the query results feed.

partitionKey
Object Object

The partition key that can be used with an IPartitionResolver.

Returns

The query result set.

Remarks

Support for IPartitionResolver based method overloads is now obsolete. It's recommended that you use Partitioned Collections for higher storage and throughput.

CreateDocumentQuery<T>(String, String, FeedOptions) CreateDocumentQuery<T>(String, String, FeedOptions)

Overloaded. This method creates a query for documents under a collection in an Azure Cosmos DB database using a SQL statement. It returns an IQueryable{T}.

public System.Linq.IQueryable<T> CreateDocumentQuery<T> (string collectionLink, string sqlExpression, Microsoft.Azure.Documents.Client.FeedOptions feedOptions = null);
abstract member CreateDocumentQuery : string * string * Microsoft.Azure.Documents.Client.FeedOptions -> System.Linq.IQueryable<'T>
override this.CreateDocumentQuery : string * string * Microsoft.Azure.Documents.Client.FeedOptions -> System.Linq.IQueryable<'T>

Type Parameters

T

The type of object to query.

Parameters

collectionLink
String String

The link to the parent collection.

sqlExpression
String String

The SQL statement.

feedOptions
FeedOptions FeedOptions

The options for processing the query result feed. For details, see FeedOptions

Returns

An IQueryable{T} that can evaluate the query.

Implements

Examples

This example below queries for some book documents.


public class Book 
{
    [JsonProperty("title")]
    public string Title {get; set;}
    
    public Author Author {get; set;}
    
    public int Price {get; set;}
}

public class Author
{
    public string FirstName {get; set;}
    public string LastName {get; set;}
}

// Query by the Title property
Book book = client.CreateDocumentQuery<Book>(collectionLink, 
    "SELECT * FROM books b WHERE b.title  = 'War and Peace'").AsEnumerable().FirstOrDefault();

// Query a nested property
Book otherBook = client.CreateDocumentQuery<Book>(collectionLink,
    "SELECT * FROM books b WHERE b.Author.FirstName = 'Leo'").AsEnumerable().FirstOrDefault();

// Perform a range query (needs an IndexType.Range on price or FeedOptions.EnableScansInQuery)
foreach (Book matchingBook in client.CreateDocumentQuery<Book>(
    collectionLink, "SELECT * FROM books b where b.Price > 1000"))
{
    // Iterate through books
}

// Query asychronously. Optionally set FeedOptions.MaxItemCount to control page size
using (var queryable = client.CreateDocumentQuery<Book>(collectionLink, 
    "SELECT * FROM books b WHERE b.title  = 'War and Peace'", 
    new FeedOptions { MaxItemCount = 10 }).AsDocumentQuery())
{
    while (queryable.HasMoreResults) 
    {
        foreach(Book b in await queryable.ExecuteNextAsync<Book>())
        {
            // Iterate through books
        }
    }
}

Remarks

Refer to https://msdn.microsoft.com/en-us/library/azure/dn782250.aspx and http://azure.microsoft.com/documentation/articles/documentdb-sql-query/ for syntax and examples.

See also

CreateDocumentQuery<T>(String, SqlQuerySpec, FeedOptions) CreateDocumentQuery<T>(String, SqlQuerySpec, FeedOptions)

Overloaded. This method creates a query for documents under a collection in an Azure Cosmos DB database using a SQL statement with parameterized values. It returns an IQueryable{T}. For more information on preparing SQL statements with parameterized values, please see SqlQuerySpec.

public System.Linq.IQueryable<T> CreateDocumentQuery<T> (string collectionLink, Microsoft.Azure.Documents.SqlQuerySpec querySpec, Microsoft.Azure.Documents.Client.FeedOptions feedOptions = null);
abstract member CreateDocumentQuery : string * Microsoft.Azure.Documents.SqlQuerySpec * Microsoft.Azure.Documents.Client.FeedOptions -> System.Linq.IQueryable<'T>
override this.CreateDocumentQuery : string * Microsoft.Azure.Documents.SqlQuerySpec * Microsoft.Azure.Documents.Client.FeedOptions -> System.Linq.IQueryable<'T>

Type Parameters

T

The type of object to query.

Parameters

collectionLink
String String

The link to the parent document collection.

querySpec
SqlQuerySpec SqlQuerySpec

The SqlQuerySpec instance containing the SQL expression.

feedOptions
FeedOptions FeedOptions

The options for processing the query result feed. For details, see FeedOptions

Returns

An IQueryable{T} that can evaluate the query.

Implements

Examples

This example below queries for some book documents.


public class Book 
{
    [JsonProperty("title")]
    public string Title {get; set;}
    
    public Author Author {get; set;}
    
    public int Price {get; set;}
}

public class Author
{
    public string FirstName {get; set;}
    public string LastName {get; set;}
}

// Query using Title
Book book, otherBook;

var query = new SqlQuerySpec(
    "SELECT * FROM books b WHERE b.title = @title", 
    new SqlParameterCollection(new SqlParameter[] { new SqlParameter { Name = "@title", Value = "War and Peace" }}));
book = client.CreateDocumentQuery<Book>(collectionLink, query).AsEnumerable().FirstOrDefault();

// Query a nested property
query = new SqlQuerySpec(
    "SELECT * FROM books b WHERE b.Author.FirstName = @firstName", 
    new SqlParameterCollection(new SqlParameter[] { new SqlParameter { Name = "@firstName", Value = "Leo" }}));
otherBook = client.CreateDocumentQuery<Book>(collectionLink, query).AsEnumerable().FirstOrDefault();

// Perform a range query (needs an IndexType.Range on price or FeedOptions.EnableScansInQuery)
query = new SqlQuerySpec(
    "SELECT * FROM books b WHERE b.Price > @minPrice", 
    new SqlParameterCollection(new SqlParameter[] { new SqlParameter { Name = "@minPrice", Value = 1000 }}));
foreach (Book b in client.CreateDocumentQuery<Book>(
    collectionLink, query))
{
    // Iterate through books
}

// Query asychronously. Optionally set FeedOptions.MaxItemCount to control page size
query = new SqlQuerySpec(
    "SELECT * FROM books b WHERE b.title = @title", 
    new SqlParameterCollection(new SqlParameter[] { new SqlParameter { Name = "@title", Value = "War and Peace" }}));
    
using (var queryable = client.CreateDocumentQuery<Book>(collectionLink, query, 
    new FeedOptions { MaxItemCount = 10 }).AsDocumentQuery())
{
    while (queryable.HasMoreResults) 
    {
        foreach(Book b in await queryable.ExecuteNextAsync<Book>())
        {
            // Iterate through books
        }
    }
}

Remarks

Refer to https://msdn.microsoft.com/en-us/library/azure/dn782250.aspx and http://azure.microsoft.com/documentation/articles/documentdb-sql-query/ for syntax and examples.

See also

CreateDocumentQuery<T>(String, FeedOptions, Object) CreateDocumentQuery<T>(String, FeedOptions, Object)

Warning

This API is now obsolete.

Overloaded. This method creates a query for documents under a collection in an Azure Cosmos DB service.

[System.Obsolete("Support for IPartitionResolver based method overloads is now obsolete. It's recommended that you use partitioned collections for higher storage and throughput. Please use the override that does not take a partitionKey parameter.")]
public System.Linq.IOrderedQueryable<T> CreateDocumentQuery<T> (string documentsFeedOrDatabaseLink, Microsoft.Azure.Documents.Client.FeedOptions feedOptions, object partitionKey);
member this.CreateDocumentQuery : string * Microsoft.Azure.Documents.Client.FeedOptions * obj -> System.Linq.IOrderedQueryable<'T>

Type Parameters

T

The type of object to query.

Parameters

documentsFeedOrDatabaseLink
String String

The path link for the documents under a collection, e.g. dbs/db_rid/colls/coll_rid/docs/. Alternatively, this can be a path link to the database when using an IPartitionResolver, e.g. dbs/db_rid/

feedOptions
FeedOptions FeedOptions

The options for processing the query result feed. For details, see FeedOptions

partitionKey
Object Object

The partition key that can be used with an IPartitionResolver.

Returns

An IOrderedQueryable{T} that can evaluate the query.

Remarks

Support for IPartitionResolver based method overloads is now obsolete. It's recommended that you use Partitioned Collections for higher storage and throughput.

CreateDocumentQuery<T>(Uri, FeedOptions) CreateDocumentQuery<T>(Uri, FeedOptions)

Extension method to create a query for documents in the Azure Cosmos DB service.

public System.Linq.IOrderedQueryable<T> CreateDocumentQuery<T> (Uri documentCollectionUri, Microsoft.Azure.Documents.Client.FeedOptions feedOptions = null);
abstract member CreateDocumentQuery : Uri * Microsoft.Azure.Documents.Client.FeedOptions -> System.Linq.IOrderedQueryable<'T>
override this.CreateDocumentQuery : Uri * Microsoft.Azure.Documents.Client.FeedOptions -> System.Linq.IOrderedQueryable<'T>

Type Parameters

T

the type of object to query.

Parameters

documentCollectionUri
Uri Uri

The URI of the document collection.

feedOptions
FeedOptions FeedOptions

The options for processing the query results feed.

Returns

The query result set.

Implements

CreateDocumentQuery<T>(String, FeedOptions) CreateDocumentQuery<T>(String, FeedOptions)

Overloaded. This method creates a query for documents under a collection in an Azure Cosmos DB service.

public System.Linq.IOrderedQueryable<T> CreateDocumentQuery<T> (string collectionLink, Microsoft.Azure.Documents.Client.FeedOptions feedOptions = null);
abstract member CreateDocumentQuery : string * Microsoft.Azure.Documents.Client.FeedOptions -> System.Linq.IOrderedQueryable<'T>
override this.CreateDocumentQuery : string * Microsoft.Azure.Documents.Client.FeedOptions -> System.Linq.IOrderedQueryable<'T>

Type Parameters

T

The type of object to query.

Parameters

collectionLink
String String

The link to the parent collection resource.

feedOptions
FeedOptions FeedOptions

The options for processing the query result feed. For details, see FeedOptions

Returns

An IOrderedQueryable{T} that can evaluate the query.

Implements

Examples

This example below queries for some book documents.


public class Book 
{
    [JsonProperty("title")]
    public string Title {get; set;}
    
    public Author Author {get; set;}
    
    public int Price {get; set;}
}

public class Author
{
    public string FirstName {get; set;}
    public string LastName {get; set;}
}
 
// Query by the Title property
Book book = client.CreateDocumentQuery<Book>(collectionLink).Where(b => b.Title == "War and Peace").AsEnumerable().FirstOrDefault();

// Query a nested property
Book otherBook = client.CreateDocumentQuery<Book>(collectionLink).Where(b => b.Author.FirstName == "Leo").AsEnumerable().FirstOrDefault();

// Perform a range query (needs an IndexType.Range on price or FeedOptions.EnableScansInQuery)
foreach (Book matchingBook in client.CreateDocumentQuery<Book>(collectionLink).Where(b => b.Price > 100))
{
    // Iterate through books
}

// Query asychronously. Optionally set FeedOptions.MaxItemCount to control page size
using (var queryable = client.CreateDocumentQuery<Book>(
    collectionLink,
    new FeedOptions { MaxItemCount = 10 })
    .Where(b => b.Title == "War and Peace")
    .AsDocumentQuery())
{
    while (queryable.HasMoreResults) 
    {
        foreach(Book b in await queryable.ExecuteNextAsync<Book>())
        {
            // Iterate through books
        }
    }
}

Remarks

The Azure Cosmos DB LINQ provider compiles LINQ to SQL statements. Refer to http://azure.microsoft.com/documentation/articles/documentdb-sql-query/#linq-to-documentdb-sql for the list of expressions supported by the Azure Cosmos DB LINQ provider. ToString() on the generated IQueryable returns the translated SQL statement. The Azure Cosmos DB provider translates JSON.NET and DataContract serialization attributes for members to their JSON property names.

See also

Applies to