I have a page which displays the model details(in this case Franchise), but also displays a tabular list of notes about the franchise. What is the best way to delete one of the notes?
Currently i have a franchiseRepository which takes care of all the crud operati开发者_高级运维ons for the franchise Model. Would i be best to create a note repository also to add crud functionality? Or is there an easier way around it, like implementing it within the franchiseRepository(or would that be breaking some ddd rules like srp)?
public class Parent()
{
public string name{get; set;}
public IList<Note> notes{get;set;}
//And so on
}
public class Note()
{
public string content{get; set;}
//And so on
}
Your parent should have a method like RemoveNote() which will remove the note from the list. use cascade = all-delete-orphan on the on to manny relation and inverse = true on mapping. And you should not have Note repository.
public virtual void RemoveNote(Note note)
{
if (_notes.Contains(note))
{
_notes.Remove(note);
note.Parent = null;
}
}
精彩评论