当我首先从实体框架代码生成数据库时,会得到这个错误。
我没看到脚本有任何问题:
alter table [dbo].[Votes] add constraint [Post_Votes] foreign key ([Post_Id]) references [dbo].[Posts]([Id]) on delete cascade;
alter table [dbo].[Votes] add constraint [User_Votes] foreign key ([Voter_Id]) references [dbo].[Users]([Id]) on delete cascade;
每个引用都指向不同的表!
每个表只能删除一个级联?
Edit: I think I found the problem, the bug is EF:
如果我有三张表:用户、帖子和投票。
关系:
post.authorid->用户.id
votes.post id->发布.id
votes.user id->用户.id
SQL正确生成错误,因为如果删除日志,我将有两个投票路径:用户->投票和用户->发布->投票
但是实体框架没有检测到这一点并生成3个带有on-delete级联的外键。