如何使用Azure Offline Sync使用参数提取数据? [英] how to Pull data with paramter using Azure Offline Sync?

查看:73
本文介绍了如何使用Azure Offline Sync使用参数提取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有如下所示的架构,当我必须提取所有数据时,我想知道是否可以通过CategoryId获得所有TaskCategoryMappings.我在此处浏览了文档>但是我不知道该怎么做?所有示例都类似于一个基于UserId的.但是userid也用于身份验证,并且在服务器端,我已经可以很好地返回仅属于相关用户的映射,并且我还希望按CategoryId进行过滤?

I have schema as below and I would like to know if I can get all the TaskCategoryMappings by CategoryId when I have to pulll all data. I went through the documentation here but I cant figure out how to do it ? All the examples are like this one based on UserId. but userid is used for also authentication and on the server side I already handle it fine to return only mappings belong to relevant user and i want in adition to filter by CategoryId?

另一个SO示例也在此处使用userId 通过Azure Get Service传递参数

another SO sample is here also using userId Parameter Passing with Azure Get Service

public class TaskCategoryMapping : TableData
    {
        public string TaskId { get; set; }

        public string CategoryId { get; set; }

        public string UserId { get; set; }

    }

推荐答案

根据您的描述,我检查了此问题,发现它可以按预期工作,您可以按照以下详细信息检查代码:

According to your description, I checked this issue on my side and found that it could work as expected, you could follow the details below to check your code:

后端模型:

public class Tag : EntityData
{
    public string TagName { get; set; }
    public bool Status { get; set; }
}

public class Message : EntityData
{
    public string UserId { get; set; }
    public string Text { get; set; }
    public virtual Tag Tag { get; set; }
    [ForeignKey("Tag")]
    public string Tag_Id { get; set; }
}

GetAllMessage操作:

// GET tables/Message
public IQueryable<Message> GetAllMessage()
{
    return Query();
}

对于客户端,我仅调用联机表来检索消息实体,如下所示:

For the client, I just invoke the online table for retrieving the message entities as follows:

客户端模型:

public class Message
{
    public string Id { get; set; }
    public string UserId { get; set; }
    public string Text { get; set; }
    public string Tag_Id { get; set; }
}

var result=await mobileServiceClient.GetTable<Message>().Where(msg => msg.Tag_Id == "c3cd4cf8-7af0-4267-817e-f84c6f0e1733").ToListAsync();

对于脱机表,拉操作查询将

For offline table, the pull operation query would

await messageSyncTable.PullAsync($"messages_{userid}", messageSyncTable.Where(m => m.Tag_Id == "<Tag_Id>"));

使用提琴手,您会发现请求看起来像这样:

Use fiddler, you could find that the request would look like this:

https://{your-app-name}.azurewebsites.net/tables/Message?$filter=Tag_Id eq 'c3cd4cf8-7af0-4267-817e-f84c6f0e1733'

这篇关于如何使用Azure Offline Sync使用参数提取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆