想要使用linq从azure移动服务表的特定列获取数据
本文关键字:数据 获取 服务 移动 linq azure | 更新日期: 2023-09-27 18:04:44
我已经采取了一个文本框,一个文本块和一个按钮来执行搜索的东西在azure移动服务表…我在文本框中给出了用户名,当我点击按钮时,我想在文本块中获得firstname,其用户名是在文本框中给出的。我已经尝试了下面的代码,但它不工作
private async void search_click(object sender, RoutedEventArgs e)
{
MobileServiceCollection<UserData, UserData> data;
IMobileServiceTable<UserData> dataTable = App.MobileService.GetTable<UserData>();
try
{
showBlock.Text = "searching.....";
statusBar.IsIndeterminate = true;
searchButton.IsEnabled = false;
if (searchBox.Text != "")
{
tempUnamePhone = await App.MobileService.GetTable<UserData>().Where(x => x.uname == searchBox.Text || x.phone == searchBox.Text).ToListAsync();
data = await dataTable.Where(x => x.uname == searchBox.Text).Select(x=>x.fname).ToCollectionAsync();
}
if (tempUnamePhone.Count != 0)
{
showBlock.Text = "item found"+fname;
statusBar.IsIndeterminate = false;
searchButton.IsEnabled = true;
}
else
{
showBlock.Text = "no match found";
statusBar.IsIndeterminate = false;
searchButton.IsEnabled = true;
}
}
catch (Exception )
{
var m = new MessageDialog("Network error..close the app and try again" ).ShowAsync();
}
}
}
var fname = string.Empty;
if (searchBox.Text != "")
{
tempUnamePhone = await App.MobileService.GetTable<UserData>().Where(x => x.uname == searchBox.Text || x.phone == searchBox.Text).ToListAsync();
fname =tempUnamePhone.Where(x => x.uname == searchBox.Text).FirstOrDefault() == null ? string.Empty : await dataTable.Where(x => x.uname == searchBox.Text).First().fname;
这里匹配的记录将作为一个集合得到。我没有看到从集合中查找fname的代码。我相信fname是用来存储匹配记录中的名字的。你必须检查'data'中是否有任何记录返回,然后将第一条记录赋值给'fname',然后设置为textblock
if (tempUnamePhone.Count != 0)
{
showBlock.Text = "item found" + fname;
statusBar.IsIndeterminate = false;
searchButton.IsEnabled = true;
}
else
{
showBlock.Text = "no match found";
statusBar.IsIndeterminate = false;
searchButton.IsEnabled = true;
}