private SaveMap BeforeSaveEntities(SaveMap saveMap) { // Only save selected DTO types var badType = saveMap.Keys .FirstOrDefault(k => k != typeof(Customer) && k != typeof(Product)); if (badType != null) { throw new InvalidOperationException("Cannot save changes to type " + badType.Name); } // Need a new NorthwindDtoRepository for reading; // Can't use the existing one during a save because for unknown reason // EF DbContext crashes with nullref exception. var readRepo = new NorthwindDtoRepository { UserSessionId = UserSessionId }; _customerMapper = new CustomerMapper(readRepo); _productMapper = new ProductMapper(); // convert DTO types to corresponding server types saveMap.ConvertBeforeSaveMap( _contextProvider.CreateEntityInfo, _entitySaveGuard.BeforeSaveEntity, _customerMapper, _productMapper); // Now ready to apply server model validation _entitySaveGuard.BeforeSaveEntities(saveMap); return(saveMap); }
public CustomerMapper(NorthwindDtoRepository repo) { this.repo = repo; }