[英]How to access id of one table in another table
我如何訪問分配到這家商店的員工。 刪除 Store 時; 我想將員工可用性標志更改為真。 目前,我對staffId 有疑問!
public async Task<IActionResult> DeleteConfirmed(int eventId)
{
var @store= await _context.Stores.FindAsync(eventId);
_context.Stores.Remove(@store);
//make staff available
var staff = await _context.Staffs.FindAsync(staffId);
staff.IsAvailable = true;
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
你沒有定義staffId
你當然會遇到問題!
最簡單的是有這樣的東西:
var staffs = await _context.Staffs.Where(s => s.storeId == id).Select(s => s).ToListAsync();
foreach(var employee in staffs) {
employee.IsAvailable = true;
}
Select
只是為了清楚起見; 你不需要它
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.