/// <summary> /// Inserts the specified instance. /// </summary> /// <param name="instance">The instance.</param> public void Insert(T instance) { if (instance == null) { return; } if (Mapper == null) { Mapper = instance.CreateBulkInsertMapper(TargetTableSource, instance, Target); } if (CurrentTargetTable == null) { CurrentTargetTable = TargetTableSource.Clone(); } //if (instance is ICDCodedTarget) { instance.CleanBeforeSave(); } var row = CurrentTargetTable.NewRow(); row.ItemArray = Mapper.InstanceValues(instance).ToArray(); var datasetRecord = instance as DatasetRecord; if (datasetRecord != null && (row[typeof(Dataset).Name + "_Id"] == DBNull.Value || row[typeof(Dataset).Name + "_Id"] == null)) { row[typeof(Dataset).Name + "_Id"] = datasetRecord.Dataset.Id; } CurrentTargetTable.Rows.Add(row); if (CurrentTargetTable.Rows.Count == BatchSize) { Flush(); } }
/// <summary> /// Releases unmanaged and - optionally - managed resources. /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected virtual void Dispose(bool disposing) { if (!this._disposed) { if (disposing) { try { Flush(); //Task.Factory.StartNew(() => //{ // var configService = ServiceLocator.Current.GetInstance<IConfigurationService>(); // var dbCreator = ServiceLocator.Current.GetInstance<IDatabaseCreator>(CreatorNames.Sql); // dbCreator.TruncateDbLogFile(configService.ConnectionSettings.ConnectionString); //}, TaskCreationOptions.LongRunning); } finally { try { if (CurrentTargetTable != null) { CurrentTargetTable.Dispose(); CurrentTargetTable = null; } } finally { if (TargetTableSource != null) { TargetTableSource.Dispose(); TargetTableSource = null; } } } } _disposed = true; } }