我正在尝试使用azure移动服务开发适用于Windows手机的应用。我正在使用azure portal提供的身份验证服务。身份验证后,用户需要输入一些数据,如他的姓名,电子邮件ID等。另外,我限制一个用户使用插入脚本只使用一行。我正在使用多个页面进行输入。
myTable的
public class myTabble
{
public string Id { get; set; }
[JsonProperty(PropertyName = "name")]
public string name { get; set; }
[JsonProperty(PropertyName = "age")]
public int age { get; set; }
[JsonProperty(PropertyName = "fname")]
public string fname { get; set; }
[JsonProperty(PropertyName = "street")]
public string street { get; set; }
[JsonProperty(PropertyName = "college")]
public string college { get; set; }
}
我的更新第二页按钮上的功能
private async void UpdateCheckedTodoItem(myTabble item)
{
await todoTable.UpdateAsync(item);
}
private async void myFunction()
{
var names = await todoTable
.Select(t => t.Id)
.ToEnumerableAsync();
var myName = names.FirstOrDefault();
string a = myName;
var item = await todoTable
.Where(todoItem => todoItem.Id == a)
.ToCollectionAsync();
item.street = street.Text; //error
item.colege = colege.Text; //error
}
private void save_Click(object sender, RoutedEventArgs e)
{
try
{
myFunction();
}
catch
{
MessageBox.Show("Invalid input");
}
}
我收到此错误
Microsoft.WindowsAzure.MobileServices.MobileServiceCollection<Test.myTabble,Test.myTabble>' does not contain a definition for 'hobby' and no extension method 'hobby' accepting a first argument of type 'Microsoft.WindowsAzure.MobileServices.MobileServiceCollection<Test.myTabble,Test.myTabble>' could be found (are you missing a using directive or an assembly reference?
答案 0 :(得分:2)
var items = await todoTable
.Where(todoItem => todoItem.Id == a)
.ToCollectionAsync();
var item = items.FirstOrDefault();
if(item != null)
{
item.street = street.Text; //
item.colege = colege.Text; //
await todoTable.UpdateAsync(item);
}
我几乎忘记了API,我不记得是否有任何要求获得的API,在这种情况下,您不必执行ToCollectionAsync()
,这会返回collection
。