简体   繁体   中英

EF Core Unlink / Detach Related Entity - One to Many

I am trying to unlink my entity's relation to another entity (Task).

But my entity's relation is still remain in TaskID column.

How can i delete this TaskID value.

I am using entity framework core 2.2

Thanks in advance.

1. setting task null

2. task relation still remains

WorkHour workHourRecentCreated = workHourRepo.Get(workHourDb.ID);
workHourRecentCreated.Task = null;
workHourRepo.Edit(workHourRecentCreated);
workHourRepo.Save();

You might need to eager load the task in order for the change tracker to pick up the change.

If you have a taskID field, setting that to null should update the database properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM