我有两个实体,一个是“Profile(资料)”,另一个是“ProfileImages(资料图片)”。在获取了“Profile(资料)”之后,我想通过“Profile(资料)”删除“ProfileImages(资料图片)”,而不仅仅是将它的引用设为“null”。请问如何使用流畅API和级联删除来实现?我应该设置“HasRequired(必需属性)”属性还是“CascadeDelete(级联删除)”属性?
public class Profile
{
//other code here for entity
public virtual ICollection<ProfileImage> ProfileImages { get; set; }
}
public class ProfileImage
{
// other code here left out
[Index]
public string ProfileRefId { get; set; }
[ForeignKey("ProfileRefId")]
public virtual Profile Profile { get; set; }
}