是否可以使用Entity Framework Code-First从单一方式防止级联删除。
以下是示例代码:
public sealed class ZeContext : DbContext
{
static ZeContext()
{
Database.SetInitializer(new CreateDatabase());
}
public IDbSet<A> As { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<A>()
.ToTable("A")
.HasMany<B>(a => a.Bs)
.WithMany(b => b.As)
;
modelBuilder.Entity<B>()
.ToTable("B")
.HasMany<A>(b => b.As)
.WithMany(a => a.Bs)
;
base.OnModelCreating(modelBuilder);
}
}
public class A
{
public Guid Id { get; set; }
public virtual ICollection<B> Bs { get; set; }
}
public class B
{
public Guid Id { get; set; }
public virtual ICollection<A> As { get; set; }
}
我想配置以下行为: