I'm new to the use of the Repository pattern, so please bear with me if I'm asking an obvious question.
I'm confused by the Silk implementation of UnitOfWork.
This is my understanding of how unit of work is implemented in Silk: The UnitOfWork implementation is a DbContext (MileageStatsDbContext). The various Repositories get the UnitOfWork instance injected via the constructor i.e. they get handed a DbContext.
In the various Create/Update/Delete methods of the Repositories, UnitOfWork.SaveChanges() is called at the end. This causes the DbContext to create a transaction and commit the changes to the database. How do you make a UnitOfWork span multiple Repository
actions and apply all the changes within a single transaction?
E.g. I don't think this code in BusinessServices.cs runs in a transaction: (from \Silk\MileageStats\MileageStats.Services\BusinessServices.cs)
if (photo != null)
DataLayer.VehiclePhoto dataPhoto = photo.ToDataModelPhoto();
vehicleToAdd.PhotoId = vehicle.PhotoId = photo.VehiclePhotoId = dataPhoto.VehiclePhotoId;
Shouldn't the SaveChanges call be made by the Services code outside a Repository? E.g. to a SaveChanges() method on one of the repositories?