c# - 如何更新 EF Core 中包含的表?
问题描述
我使用此代码,我需要更新同一代码中的数据。我知道我可以使用相同的查询获取数据,但我喜欢通过这段代码来完成。
我怎样才能做到这一点?
List<TblUserCity> removedUserCityData = new List<TblUserCity>();
var removedUserCities = userData
.TblUserCities
.Where(x => !cityIdList.Contains(x.TblCityId))
.ToList();
if (removedUserCities.Count() > 0)
{
foreach (var cityItem in removedUserCities)
{
cityItem.RemoveDate = DateTime.Now;
removedUserCityData.Add(cityItem);
}
_db.TblUserCities.UpdateRange(removedUserCityData);
}