I have a domain model with an aggregate root:
public interface IAggregateRoot {
public string Id { get; }
public string Foo { get; set; }
public int Bar { get; set; }
public IList Children { get; }
}
The Children collection tends to get very large and I will be lazy loading it when an IAggregateRoot instance is retrieved through the IAggregateRootRepository. My problem is this; if I want to add an IChildEntity to an IAggregateRoot's Children collection, how can my repository allow me avoid persisting the entire aggregate?
For example, let's say my IAggregateRootRepository were to look like the following:
public interface IAggregateRootRepository {
public IAggregateRoot GetById(string id);
public void AddOrUpdate(IAggregateRoot root);
}
Then I could add to the Children collection by getting an IAggregateRoot instance through IAggregateRootRepository.GetById(), adding the child to the Children collection, then persisting it all through IAggregateRootRepository.AddOrUpdate(). That would, however, persist the entire aggregate root, along with its massive collection of children, every time I add a child entity. I guess I could get around that if my repository looked like:
public interface IAggregateRootRepository {
public IAggregateRoot GetById(string id);
public void AddOrUpdate(IAggregateRoot root);
public void AddOrUpdate(IChildEntity child);
}
But, as I have understood the repository pattern, a repository should only deal with aggregate roots and the solution above certainly breaks that requirement.
Are there other, better, ways of avoiding this problem?
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)