How to create a cascading deletion in a self-relationship using fluent api
and enable it in entity framework
?
Code:
Public class Usuario {
public int UsuarioID { get; set; }
public int? ObjPaiID { get; set; }
public virtual Usuario ObjPai { get; set; }
public virtual IList<Usuario> ListaPartes { get; set; }
}
Context:
//Auto-relacionamento Projeto
modelBuilder.Entity<Usuario>()
.HasOptional(p => p.ObjPai)
.WithMany(p => p.ListaPartes)
.HasForeignKey(p => p.ObjPaiID);