public BulkInsertDataObjectsActor(IStorageBasedDataObjectAccessor <TDataObject> dataObjectAccessor, DataConnection targetDataConnection) { _dataObjectAccessorName = dataObjectAccessor.GetType().Name; _dataObjectsSource = dataObjectAccessor.GetSource(); _targetDataConnection = targetDataConnection; }
public ReplicatorImpl(IStorageBasedDataObjectAccessor <TDataType> accessor, IStore target) { _info = GetAccessorInfo(accessor.GetType(), new Lazy <Expression>(() => accessor.GetSource().Expression)); _accessor = accessor; _target = target; }
private void ExecuteBulkCopy(int timeout) { var source = _dataObjectAccessor.GetSource(); var target = _targetDataConnection.GetTable <TDataObject>(); var temp = _targetDataConnection.CreateTable <TDataObject>($"#{Guid.NewGuid():N}"); try { var options = new BulkCopyOptions { BulkCopyTimeout = timeout }; temp.BulkCopy(options, source); temp.Where(x => !target.Contains(x)).Insert(target, x => x); } catch (Exception ex) { string sqlText; try { var linq2DBQuery = source as IExpressionQuery <TDataObject>; sqlText = linq2DBQuery?.SqlText; } catch (Exception innerException) { sqlText = $"can not build sql query: {innerException.Message}"; } throw new DataException($"Error occured while bulk replacing data for dataobject of type {typeof(TDataObject).Name} using {_dataObjectAccessor.GetType().Name}{Environment.NewLine}{sqlText}{Environment.NewLine}", ex); } }