Skip to content

Instantly share code, notes, and snippets.

@PilotBob
Last active June 5, 2018 14:05
Show Gist options
  • Save PilotBob/300adc78d28b6ae2f6eb1cf7e7559240 to your computer and use it in GitHub Desktop.
Save PilotBob/300adc78d28b6ae2f6eb1cf7e7559240 to your computer and use it in GitHub Desktop.
This works:
db.Entry(target).Collection(r => r.Permissions).Load();
target.Permissions.Remove(permission);
This doesn't:
db.Entry(target).Collection(r => r.Permissions).Query().Where(p => p.ID == permission.ID).Load();
target.Permissions.Remove(permission);
In the latter case.. the Load does not load the collection with the matching record. In that case, when I call SaveChanges
after the remove, the child record isn't deleted. In the first case, load does load the collection, of course it loads
ALL the child records, the remove does remove the single record and delete it from the db when SaveChanges is called.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment