0

We have the following case:

Image of the DB model

We are trying to map with fluent in EF so that when a RoleUser is deleted, all the UserRoleCollection are deleted with cascade. The class RoleUser does not exist in the EF model, because it is a many to many between users and roles.

Our object model is defined like this:

User - RoleList
User - UserRoleConnectionList
Role - UserList
Role - UserRoleConnectionList
UserRoleConnection - UserList
UserRoleConnection - RoleList
UserRoleConnection - ConnectionList
Connection - UserRoleConnectionList

When we delete a Role from a User, the RoleUser should be deleted and also the UserRoleConnections. Currently, it works because the database has ON CASCADE DELETE, but EF is not removing UserRoleConnection from the datacontext, leaving the erased entities.

undefined
  • 33,537
  • 22
  • 129
  • 198
Ema
  • 3
  • 1
  • _Currently, it works_ What works? (and what doesn't?). – Gert Arnold Oct 16 '13 at 20:51
  • Sorry, I wrote the question too fast. The thing that works is that if I delete a Role from the User from EF, the RoleUser and UserRoleConnection values in the database are removed because this tables have ON DELETE CASCADE. But if I look at the entities in the context, the UserRoleConnection entries are still associated with the user. It's like the cascade of the cascade is not being detected by EF. Let me know if the question is clear. – Ema Oct 16 '13 at 23:47

0 Answers0