Container.GetItemLinqQueryable<T> メソッド

定義

このメソッドは、Azure Cosmos DB サービスのコンテナーの下に項目の LINQ クエリを作成します。 IQueryable 拡張メソッド ToFeedIterator() は、FeedIterator での非同期実行に使用する必要があります。例 2 を参照してください。

public abstract System.Linq.IOrderedQueryable<T> GetItemLinqQueryable<T> (bool allowSynchronousQueryExecution = false, string continuationToken = default, Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = default, Microsoft.Azure.Cosmos.CosmosLinqSerializerOptions linqSerializerOptions = default);
abstract member GetItemLinqQueryable : bool * string * Microsoft.Azure.Cosmos.QueryRequestOptions * Microsoft.Azure.Cosmos.CosmosLinqSerializerOptions -> System.Linq.IOrderedQueryable<'T>
Public MustOverride Function GetItemLinqQueryable(Of T) (Optional allowSynchronousQueryExecution As Boolean = false, Optional continuationToken As String = Nothing, Optional requestOptions As QueryRequestOptions = Nothing, Optional linqSerializerOptions As CosmosLinqSerializerOptions = Nothing) As IOrderedQueryable(Of T)

型パラメーター

T

クエリを実行するオブジェクトの型。

パラメーター

allowSynchronousQueryExecution
Boolean

(省略可能)IOrderedQueryable を使用してクエリを同期的に実行できるようにするオプション。

continuationToken
String

(省略可能)Azure Cosmos DB サービスの継続トークン。

requestOptions
QueryRequestOptions

(省略可能)項目クエリ要求のオプション。

linqSerializerOptions
CosmosLinqSerializerOptions

(省略可能)Linq Serializer プロパティを構成するためのオプション。 これにより、クライアントの作成時に CosmosSerializerOptions のプロパティがオーバーライドされます

戻り値

(省略可能)クエリを評価できる IOrderedQueryable{T}。

  1. 次の例は、LINQ クエリの生成とブロックされた実行を示しています。
public class Book 
{
    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 = container.GetItemLinqQueryable<Book>(true)
                     .Where(b => b.Title == "War and Peace")
                     .AsEnumerable()
                     .FirstOrDefault();

// Query a nested property
Book otherBook = container.GetItemLinqQueryable<Book>(true)
                          .Where(b => b.Author.FirstName == "Leo")
                          .AsEnumerable()
                          .FirstOrDefault();

// Perform iteration on books
foreach (Book matchingBook in container.GetItemLinqQueryable<Book>(true)
                           .Where(b => b.Price > 100))
{
    // Iterate through books
}
  1. 次の例は、FeedIterator を使用した LINQ クエリの生成と非同期実行を示しています。

// LINQ query generation
using (FeedIterator<Book> setIterator = container.GetItemLinqQueryable<Book>()
                     .Where(b => b.Title == "War and Peace")
                     .ToFeedIterator())
{                   
    //Asynchronous query execution
    while (setIterator.HasMoreResults)
    {
        foreach(var item in await setIterator.ReadNextAsync())
        {
            Console.WriteLine(item.Price); 
        }
    }
}

注釈

LINQ の実行は同期的であり、呼び出しのブロックに関連する問題が発生します。 常に ToFeedIterator() を使用し、非同期実行を実行することをお勧めします。

適用対象

こちらもご覧ください