私が取り組んでいるプロジェクトには、OData レイヤーの上に Entity Framework があります。Odata レイヤーでは、サーバー側のページネーションが の値になっています75
。この件に関する私の読書は、このページネーションの値がテーブルごとではなく、全面的に使用されていると私に信じさせます。現在、すべてのデータを抽出しようとしているテーブルは、もちろん 75 行を超えています。エンティティ フレームワークを使用すると、私のコードは次のようになります。
public IQueryable<ProductColor> GetProductColors()
{
return db.ProductColors;
}
db
エンティティ コンテキストはどこにありますか。これは、最初の 75 レコードを返しています。次のコードを提供するためにパラメーターinlinecount
セットを追加できる場所を読みました。allpages
public IQueryable<ProductColor> GetProductColors()
{
return db.ProductColors.AddQueryOption("inlinecount","allpages");
}
ただし、これも 75 行を返します。
OData サーバー側のページネーションに関係なく、すべてのレコードを真に取得する方法を明らかにできる人はいますか?
重要:ページネーションを削除したり、オフにしたりすることはできません! これは、パフォーマンスが懸念される他のシナリオでは非常に価値があります。
更新: さらに検索して、このタスクの実行方法を説明しているMSDNを見つけました。
私はそれを完全なジェネリック メソッドに変換できるようにしたいと思っていますが、これはリフレクションを使用せずにジェネリックに到達できる限り近いものでした。
public IQueryable<T> TakeAll<T>(QueryOperationResponse<T> qor)
{
var collection = new List<T>();
DataServiceQueryContinuation<T> next = null;
QueryOperationResponse<T> response = qor;
do
{
if (next != null)
{
response = db.Execute<T>(next) as QueryOperationResponse<T>;
}
foreach (var elem in response)
{
collection.Add(elem);
}
} while ((next = response.GetContinuation()) != null);
return collection.AsQueryable();
}
次のように呼び出します:
public IQueryable<ProductColor> GetProductColors()
{
QueryOperationResponse<ProductColor> response = db.ProductColors.Execute() as QueryOperationResponse<ProductColor>;
var productColors = this.TakeAll<ProductColor>(response);
return productColors.AsQueryable();
}