Windows Azure从特定列获取项目

时间:2013-06-01 14:33:23

标签: c# azure windows-8 azure-mobile-services

我正在使用Windows Azure移动服务(c#Win RT应用程序)。表“Game”包含“PlayerName”,“PlayerMail”和“PlayerAge”列。

例如:第1行:Tim tim@hotmail.com 21 |第2行:Jan jan@hotmail.com 23

在后面的代码中,我要求在文本框中填充PlayerName等于名称的所有行。 PlayerName只有Tim,只有一行。我想获得该人的PlayerMail并将其放入变量中。我怎么能这样做?

private IMobileServiceTable<Game> todoTable = App.MobileService.GetTable<Game>();

var player = Player.Text
var databynaam = await todoTable.Where(todoItem => todoItem.PlayerName == player).ToCollectionAsync();

1 个答案:

答案 0 :(得分:2)

您可以使用Select操作仅选择该字段:

IMobileServiceTable<Game> todoTable = App.MobileService.GetTable<Game>();
string player = Player.Text;
IEnumerable<string> emails = await todoTable
    .Where(game => game.PlayerName == player)
    .Select(game => game.PlayerMail)
    .ToEnumerableAsync();
string playerMail = emails.FirstOrDefault();