Din*_*ino 5 c# entity-framework-core
我有两个表(Device和PropertyValue),当我尝试删除 a 时,Device出现异常:
违反外键
我也尝试将级联设置为打开OnModelCreating(),但仍然不起作用。
public class Device
{
public int Id { get; set; }
public List<PropertyValue> Properties { get; set; }
}
public class PropertyValue
{
public int Id { get; set; }
public int? DeviceId { get; set; }
public Device Device { get; set; }
}
modelBuilder.Entity<PropertyValue>()
.HasOne(p => p.Device)
.WithMany(b => b.Properties)
.HasForeignKey(w => w.DeviceId)
.OnDelete(DeleteBehavior.Cascade);
Run Code Online (Sandbox Code Playgroud)
编辑:我正在使用存储库,但基本上我正在使用删除_context.Devices.Remove(entity);
| 归档时间: |
|
| 查看次数: |
11117 次 |
| 最近记录: |