代码首先多对多约束错误

时间:2015-05-18 13:19:46

标签: entity-framework constraints fluent

我有以下流畅的映射:

 modelBuilder.Entity<User>()
                .HasMany<Device>(user => user.Devices)
                .WithMany(sv => sv.Users)
                .Map(userDevice =>
                {
                    userDevice.MapLeftKey("UserId");
                    userDevice.MapRightKey("DeviceId");
                    userDevice.ToTable("UserDevice"));
                });

内部用户:

public virtual ICollection<Device> Devices { get; set; }

内部设备:

public virtual ICollection<User> Users { get; set; }

现在我收到以下错误:

  

{&#34;介绍FOREIGN KEY约束   &#39; FK_dbo.UserDevice_dbo.Device_DeviceId&#39;在桌面&#39; UserDevice&#39;可以   导致循环或多个级联路径。指定ON DELETE NO ACTION   或ON更新无动作,或修改其他外键   约束。\ r \ n不能创建约束。请参阅先前的错误。&#34;}

我很想设置&#34; WillCascadeOnDelete(false)&#34;但是这个选项在&#34; WithMany()&#34;

上不可用

我也找到了以下解决方案,但我不想完全禁用级联删除: Entity Framework Many to Many Cascade Delete Issue

0 个答案:

没有答案