使用Entity Framework,在删除表中的任何记录之前,如何判断是否启用了删除级联?
public partial class DataContext : DbContext
{
public DbSet<Building> Buildings { get; set; }
public DbSet<Room> Rooms { get; set; }
}
DataContext context;
Building building;
// Will this start a DELETE CASCADE, removing Rooms within the Building?
context.Buildings.Remove(building);
这是一个通用函数,因此我可以使用DbSet<T>或DbContext但不是T。
需要在运行时进行测试,就在调用Remove()之前。
您能否在执行删除操作之前检测到DELETE CASCADE呢?如果可以,该怎么做?