Hello Guys,
I have the following implementation ( this is just an example of the general problem)
public class Db : DbContext, IUnitOfWork
{
public DbSet<Project> Projects { get; set; }
public DbSet<ProjectItem> ProjectItems { get; set; }
void IUnitOfWork.SaveChanges()
{
base.SaveChanges();
}
}
For each of this DbSet i have a Repository class.
Base on this fundation i have some bussines logic, lets say based on the command pattern.
One of my commands creates a project template ( adds a project, and several project items in one trasaction. )
My question is what is the best way to handle this ?
1. in the ProjectRepository class add ProjectItem objects (like projecc.ProjectItems.Add( .... ). - this will work, but i see here violation of the "separation of concerns" prinicple - ProjectRepository class deals with the ProjectItem persistance which
i do not like becouse i have a separate ProjectItemRepository repository with some specific methods.
2. use TransactionScope object on the command level - this will work as well, but it seems to violate UnitOfWork pattern where the SaveChanges method shold close the transaction instead of Commit on the TransactionScope level.
Any suggestions are welcome :)
Thanks,
Motnis.