我正在尝试调试EF核心2如何通过CurrentValues.SetValues
来更新实体。对仓库回购的调用对大多数实体有效,但不适用于该实体,我无法确定其价值尝试进行转换,因为用于updat的属性是日期时间。用于更新的值也为日期时间var today = DateTime.UtcNow;
public virtual async Task<T> UpdateAsync(T t, object key)
{
if (t == null)
return null;
T exist = await _context.Set<T>().FindAsync(key);
if (exist != null)
{
_context.Entry(exist).CurrentValues.SetValues(t);
await _context.SaveChangesAsync();
}
return exist;
}
foreach (var detail in details)
{
detail.IsActive = isActive;
detail.ModifiedDate = today;
detail.ModifiedBy = currentUserId;
await _repository.UpdateAsync(detail, detailId);
//updates.Add(Task.Run(async () =>
//{
// await _repository.UpdateAsync(detail, detailId);
//}));
}
//prior attempt is using WaitAll but for debugging, the call
// is made in the foreach loop
// if (updates.Count > 0)
// Task.WaitAll(updates.ToArray());
这是我可以发现EF生成的输出,即更新sql:
SET NOCOUNT ON;
UPDATE [PaymentSyncDetails] SET [IsActive] = @p0, [ModifiedBy] = @p1, [ModifiedDate] = @p2
WHERE [PaymentSyncDetailID] = @p3;
SELECT @@ROWCOUNT;
我需要检查参数,尤其是@ p2