Cosmos DB 中是否支持使用 OData 进行分页?

Is there support for paging with OData in Cosmos DB?

我可以看到在通过 SQL API 访问 Azure 中的 Cosmos DB 时支持 offset/limit - 但是 OData 支持吗?

更新

你可以下载my demo in github. And this article and offical document对你有帮助

我的存储帐户中的数据

邮递员测试

TestDataController.cs

public class TestDataController : ODataController
{
    [EnableQuery]
    public IHttpActionResult Get()
    {
        CloudStorageAccount account = CloudStorageAccount.Parse("DefaultEndpointsProtocol=***x=core.windows.net");
        CloudTableClient tableClient = account.CreateCloudTableClient();
        //table name
        CloudTable table = tableClient.GetTableReference("test");
        // all datas in table
        IQueryable<CustomerEntity> linqQuery = table.CreateQuery<CustomerEntity>().Where(x => x.PartitionKey != "0")
        .Select(x => new CustomerEntity() { PartitionKey = x.PartitionKey, RowKey = x.RowKey, Name = x.Name, Role = x.Role });
        // test data
        //var result = CreateTestData().AsQueryable();
        // real data in `test` table
        var a = linqQuery.ToList<CustomerEntity>().AsQueryable();
        return Ok(a);
    }

    public List<TestData> CreateTestData()
    {
        List<TestData> data = new List<TestData>();
        data.Add(new TestData { Id = 1, Name = "Jignesh", Role = "Project Manager" });
        data.Add(new TestData { Id = 2, Name = "Tejas", Role = "Architect" });
        data.Add(new TestData { Id = 3, Name = "Rakesh", Role = "Lead" });

        return data;
    }
}

WebApiConfig.cs

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        config.MapODataServiceRoute("odata", null, GetEdmModel(), new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer));
        config.EnsureInitialized();
       

    }
    private static IEdmModel GetEdmModel()
    {
        ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
        builder.Namespace = "WebAPITest";
        builder.ContainerName = "DefaultContainer";
        builder.EntitySet<TestData>("TestData");
        // you can dynamic load entitys later
        builder.EntitySet<CustomerEntity>("CustomerEntity");
        var edmModel = builder.GetEdmModel();
        return edmModel;
    }
}

原始

我不清楚这个解决方案。您将使用什么应用程序,桌面应用程序还是 Web 应用程序?

如果您的应用是网络应用,您可以查看这些文章。(offical document , Paging With OData And ASP.NET Web API )

如果您的应用程序不是 Web 应用程序。我建议你使用 linq 来解决这个问题。

    public static async Task Main(string[] args)
    {
        Console.WriteLine("Azure Cosmos Table Samples");
        CloudStorageAccount account = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=*****fix=core.windows.net");
        CloudTableClient tableClient = account.CreateCloudTableClient();
        CloudTable table = tableClient.GetTableReference("test");
        IQueryable<CustomerEntity> linqQuery = table.CreateQuery<CustomerEntity>().Where(x => x.PartitionKey != "0")
        .Select(x => new CustomerEntity() { PartitionKey = x.PartitionKey, RowKey = x.RowKey, Name = x.Name });
       // skip and take method 
       var c = linqQuery.ToList<CustomerEntity>().Skip(3).Take(1).ToList<CustomerEntity>();
        Console.Read();
    }