【问题标题】:How to use where query from IMobileServiceTableQuery in xamarin Forms?如何在 xamarin Forms 中使用来自 IMobileServiceTableQuery 的 where 查询?
【发布时间】:2018-05-01 00:41:31
【问题描述】:

我尝试从电子邮件中获取对象 ID,我可以在 IMobileServiceTableQuery 中执行此操作吗,所以如果我在 sql server 中编写查询,它将是这样的 SELECT id from Member where email = 'nani@gmail.com',那么如何在 IMobileServiceTableQuery 中做到这一点,据我所知,我只知道这个 IMobileServiceTableQuery<T> Where(Expression<Func<T, bool>> predicate);,但我不知道如何实现它。

好的,我试试这段代码,这段代码对吗?

 public async void GetId(AuthenticationResult result)
        {
            var client = new MobileServiceClient(Constants.ApplicationURL);
            IMobileServiceTable<Member> onlineTable = client.GetTable<Member>();
            var items = await onlineTable
                .Where(t => t.email == "gumilangtheodorus@gmail.com") // HardCode
                .Select(t => t.Id).ToListAsync();
        }

以及如何显示我得到的 id,我可以像这样使用 txtid.Text = t.Id; ?

【问题讨论】:

    标签: c# sql xamarin.forms azure-mobile-services mobileserviceclient


    【解决方案1】:

    你可以试试下面类似的代码:

    {           var client = new MobileServiceClient (Constantes.ApplicationURL);
                IMobileServiceTable perso = client.GetTable ();
                MobileServiceCollection <Personitas, Personitas> items = await perso
                                                  .Where (! Ti => ti.Nombre = null) .ToCollectionAsync ();
                listi.ItemsSource = items.Select (apa => string.Format ( "{0} {1}", apa.Name, apa.LastName));        }
    

    如果您使用的是 Node.js 后端,可以查看这篇文章:https://developer.xamarin.com/guides/xamarin-forms/cloud-services/consuming/azure/。您可以使用如下代码:

    public async Task<ObservableCollection<TodoItem>> GetTodoItemsAsync (bool syncItems = false)
    {
      ...
      IEnumerable<TodoItem> items = await todoTable
                  .Where (todoItem => !todoItem.Done)
                  .ToEnumerableAsync ();
    
      return new ObservableCollection<TodoItem> (items);
    }
    

    参考:https://adrianhall.github.io/develop-mobile-apps-with-csharp-and-azure/chapter3/client/

    【讨论】:

    • 在您的代码中,Personitas 是什么?是穆德尔吗,而 Nombre 是一个名字?什么是 ti?是参数还是变量
    • 你能给我第一个完整的方法吗,我真的需要这个谢谢
    • 我更新了我的答案,希望你解决了我的问题,谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多