我需要删除/更新一个表的给定行数.
其中一个我是这样解决的:
await context.MyItems
.Where(x => itemsIds.Contains(x.Id))
.ExecuteUpdateAsync(f => f.SetProperty(x => x.State, state));
这允许我在给定的id列表中更新项目(1,2,5,7,...)
但我不确定如何在需要按多个属性的列表而不是ID列表进行筛选的表中进行同样的操作:
var itemsToUpdate = new List<Identifier>(){ ....}
标识符是
public class Identifier
{
DateTime date {get;set;}
string code {get;set;}
string owner {get;set;}
}
有什么 idea 如何在EF Core中有效地做到这一点吗?因为我认为我没有其他解决方案,而是一个存储过程:—(
为了更清晰,原始功能:
public async Task UpdateItemsAsync(IList<long> Ids, ItemStatus state)
{
await context.myItems
.Where(x => Ids.Contains(x.Id))
.ExecuteUpdateAsync(f => f.SetProperty(x => x.State, state));
}
新增功能:
public async Task UpdateItemsAsync(IList<Identifier> Ids, ItemStatus state)
{
//can´t figure out how to apply filter here
}