Updating an entry using Azure Mobile Services

2019-02-27 12:57发布

I am currently inserting data into a table using the below method.

public async void PerformRegistration()
{
    var personTable = App.MobileService.GetTable<PersonTable>();

    var person = new PersonTable
    {
        FirstName = FirstNameTextBox.Text,
        LastName = LastNameTextBox.Text,
        EmailAddress = EmailTextBox.Text,
        Password = PasswordTextBox.Password,
        DateOfRegister = DateTime.Now
    };

    await personTable.InsertAsync(person);
}

And I access it like seen below

var person = await personTable
    .Where(p => p.EmailAddress == EmailTextBox.Text)
    .ToListAsync();

What is the easiest way to perform an update on an entry already in the db? I am not sure on how to keep the Id the same value.

1条回答
小情绪 Triste *
2楼-- · 2019-02-27 13:17

You simply need to load an entity like you are doing

var person = await personTable
    .Where(p => p.EmailAddress == EmailTextBox.Text)
    .ToListAsync();

Then change the properties you want and after that call UpdateAsync

await personTable.UpdateAsync(person);

It's all explained in this tutorial

查看更多
登录 后发表回答