我有两张桌子
public class ServiceRendering
{
[DataMember]
public int Id { get; set; }
[DataMember]
public virtual IList<ServiceRenderingProduct> ServiceRenderingProducts { get; set; }
}
public class ServiceRenderingProduct
{
[ForeignKey("ServiceRendering")]
[DataMember]
public int ServiceRenderingId { get; set; }
[DataMember]
public virtual ServiceRendering ServiceRendering { get; set; }
[DataMember]
public int Id { get; set; }
}
并设定他们之间的关系
modelBuilder.Entity<ServiceRendering>().HasMany(x => x.ServiceRenderingProducts).WithRequired(x => x.ServiceRendering).HasForeignKey(x => x.ServiceRenderingId ).WillCascadeOnDelete(true);
但是在删除ServiceRenderingEntity时,我没有删除ServiceRenderingProduct实体。我应该在数据库中设置任何约束吗?或者还有其他原因吗?