I have two entities. Profile
and ProfileImages
. After fetching a Profile
I want to delete ProfileImages
through Profile
without it just removing the reference to Profile
(setting it to null
). How can this be done with fluent API and Cascading Delete? Do I set the HasRequired
attribute or the CascadeDelete
attribute?
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; }
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…