簡體   English   中英

如何訪問另一個表中的一個表的ID

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM