0

我们有以下案例:

数据库模型的图像

我们正在尝试在 EF 中使用 fluent 进行映射,以便在删除 RoleUser 时,通过级联删除所有 UserRoleCollection。EF 模型中不存在 RoleUser 类,因为它是用户和角色之间的多对多。

我们的对象模型是这样定义的:

用户 - RoleList
用户 - UserRoleConnectionList
角色 - UserList
角色 - UserRoleConnectionList
UserRoleConnection - UserList
UserRoleConnection - RoleList
UserRoleConnection - ConnectionList
Connection - UserRoleConnectionList

当我们从用户中删除角色时,应该删除 RoleUser 以及 UserRoleConnections。目前,它之所以有效,是因为数据库具有 ON CASCADE DELETE,但 EF 并未从数据上下文中删除 UserRoleConnection,而是留下已擦除的实体。

4

0 回答 0