我正在尝试使用LINQ查询更新数据库,以更新其中x.Email == emailTextVal的'SoccerAvailability'表记录。我已经在Xamarin表单应用中编写了更新查询,但没有更新,请告知我查询中是否有任何要解决的问题
var availability = context.SoccerAvailability.Where(x => x.Email == emailTextVal);
foreach (var available in availability )
{
available.SoccerStatus += bonusToAdd;
available.CurrentDate += scoreToAdd;
}
答案 0 :(得分:3)
您只是在更新内存中存在的对象。要将更改保留到数据库中,您需要致电Update
var availability = context.SoccerAvailability.Where(x => x.Email == emailTextVal);
foreach (var available in availability )
{
available.SoccerStatus += bonusToAdd;
available.CurrentDate += scoreToAdd;
// assuming context is an SQLiteConnection
context.Update(available);
}