原始 Sql 查询以更新 Razor 页面中的记录

Raw Sql Query for Updating a record in Razor Pages

我需要在 where 子句中使用多个条件更新 razor 页面中的记录,

我目前正在使用此代码段

_context.SaveChanges();

更新查询将是这样的

UPDATE [StaffAssets] SET [EmpID] = p0, [IssuedDate] = p1, [IssuedQty] = p2, [LastModifiedBy] = p3, [LastModifiedTimestamp] = p4, [ReturnDate] = p5, [ReturnQty] = p6, [StaffAssetName] = p7 WHERE [StaffID] = p8

我需要的是

UPDATE [StaffAssets] SET [EmpID] = p0, [IssuedDate] = p1, [IssuedQty] = p2, [LastModifiedBy] = p3, [LastModifiedTimestamp] = p4, [ReturnDate] = p5, [ReturnQty] = p6, [StaffAssetName] = p7 **WHERE [StaffID] = p8 AND [EmpID] = p9 AND [StaffAssetsName] = p10**

有什么方法可以在 Razor Pages 中执行这个查询吗? 如何在剃刀页面中执行原始 sql 查询?

Is there any way to execute this query in Razor Pages? How to execute raw sql query in razor pages?

要执行原始 SQL 查询,您可以使用 ExecuteSqlInterpolatedAsync method.

await _context.Database.ExecuteSqlInterpolatedAsync($"UPDATE [StaffAssets] SET [EmpID] = {p0}, [IssuedDate] = {p1}, [IssuedQty] = {p2}, [LastModifiedBy] = {p3}, [LastModifiedTimestamp] = {p4}, [ReturnDate] = {p5}, [ReturnQty] = {p6}, [StaffAssetName] = {p7} WHERE [StaffID] = {p8} AND [EmpID] = {p9} AND [StaffAssetsName] = {p10}");