If I have the following setup
public class Device
{
public virtual ICollection<Folder> PresentInFolders { get; set; }
public virtual RoutingRule RoutingRule { get; set; }
}
public class Folder
{
public virtual ICollection<Device> Devices { get; set; }
}
Is the following code enough to disassociate and delete all linking rows?
foreach (var folder in device.PresentInFolders.ToList())
{
folder.Devices.Remove(device);
}
device.PresentInFolders.Clear();
As i can see you have setup a many to many relation between Device and Folder. It should not be necessary to delete from the two ends of the relation so this should do the job:
folder.Devices.Clear();
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.