不完全知道你正在試圖做的.... 假設你要更新的整個表什麼,你可以嘗試這樣的事:
- 負載整個表到內存中
List<StcDocItems>
- 循環每個項目,看它是否有一個匹配條目 - 如果是這樣,更新
因此,這將是代碼來做到這一點:
public class StcDocItems
{
public int Id { get; set; }
public int PartRef { get; set; }
public int DocRefType { get; set; }
public int? ItemRef { get; set; }
}
using(YourDbContext ctx = new YourDbContext())
{
// get all rows from table
List<StcDocItems> allItems = ctx.StcDocItems.ToList();
// iterate over items
foreach(StcDocItems item in allItems)
{
// do we find a row which has "ItemRef = Id" and "DocTypeRef = 63" ?
StcDocItems updateToItem = allItems.FirstOrDefault(i => i.ItemRef = item.Id && i.DocTypeRef = 63);
// if we found an item
if(updateToItem != null)
{
// set the partRef to new item's partRef
item.PartRef = i.PartRef;
}
}
// save any changes back to database table
ctx.SaveChanges();
}
感謝您的幫助,如何做到這一點的TSQL –