EF4 - CTP4 CodeOnly [英] EF4 - CTP4 CodeOnly
问题描述
你好 - 是否可以删除或绕过级联删除 默认?
hello - Is possible to remove or circumvent the cascading delete default ?
推荐答案
您可以使用Fluent API定义关系,然后允许您明确设置级联删除行为。 例如:
You can use the fluent API to define the relationship which then allows you to explicitly set the cascade delete behavior. For example:
modelBuilder.Entity<
modelBuilder.Entity<
驱动程序 >()。HasRequired(d
=> d.Team) .WithMany(t => t.Drivers).WillCascadeOnDelete( true 跨度> );
Driver>().HasRequired(d => d.Team).WithMany(t => t.Drivers).WillCascadeOnDelete(true);
请注意,级联删除仅在某些情况下按惯例设置。 最有用的是如果您的FK可以为空,那么对于FK关系,您(通常)不会按惯例进行级联删除。
Note that cascade delete is only set by convention in certain cases. The most useful one is that for FK relationships, you (usually) won't get cascade delete by convention if your FK is nullable.
目前无法使用属性更改级联行为。
It currently isn't possible to change the cascade behavior using an attribute.
谢谢,
亚瑟
Thanks,
Arthur
这篇关于EF4 - CTP4 CodeOnly的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!