public void InsertLargeBatch(IList <EmployeeSimple> employees) { if (employees == null || employees.Count == 0) { throw new ArgumentException($"{nameof(employees)} is null or empty.", nameof(employees)); } using (var trans = m_DataSource.BeginTransaction()) { trans.InsertMultipleBatch((IReadOnlyList <EmployeeSimple>)employees).Execute(); trans.Commit(); } }
public int Create(EmployeeClassification classification, bool shouldRollBack) { using (var trans = m_DataSource.BeginTransaction()) { var result = trans.Insert(classification).ToInt32().Execute(); if (shouldRollBack) { trans.Rollback(); } else { trans.Commit(); } return(result); } }
public void InsertBatchWithRefresh(IList <EmployeeSimple> employees) { if (employees == null || employees.Count == 0) { throw new ArgumentException($"{nameof(employees)} is null or empty.", nameof(employees)); } //Chain does not support updating multiple rows at one time from objects //Use the WithRefresh() link to update the original object. using (var trans = m_DataSource.BeginTransaction()) { foreach (var item in employees) { trans.Insert(item).WithRefresh().Execute(); } trans.Commit(); } }
public int Create(ProductLine productLine) { if (productLine == null) { throw new ArgumentNullException(nameof(productLine), $"{nameof(productLine)} is null."); } using (var trans = m_DataSource.BeginTransaction()) { productLine.ProductLineKey = trans.Insert(productLine).ToInt32().Execute(); productLine.ApplyKeys(); trans.InsertBatch(productLine.Products).Execute(); trans.Commit(); } return(productLine.ProductLineKey); }
private static async Task UploadLangeImages(DirectoryInfo folder, SqlServerDataSource dataSource, CloudBlobContainer imageContainer, CloudBlobContainer thumbnailContainer) { foreach (var imageFile in folder.GetFiles()) { if (string.Equals(imageFile.Extension, ".png", StringComparison.InvariantCultureIgnoreCase)) { Console.Write(imageFile.Name); using (var trans = dataSource.BeginTransaction()) { var record = new { ImageName = Path.GetFileNameWithoutExtension(imageFile.Name), FileName = imageFile.Name, FileSize = imageFile.Length, CreatedByUserKey = -1, ModifiedByUserKey = -1, ImageSetKey = 1, }; Console.Write("...database"); var imageKey = await dataSource.Insert("Images.Image", record).ToInt32().ExecuteAsync(); var storageName = await dataSource.From("Images.ImageDetail", new { imageKey }).ToString("StorageFileName").ExecuteAsync(); Console.Write("...storage"); using var stream = imageFile.OpenRead(); await UploadFileToStorageAsync(stream, storageName, imageContainer); Console.Write("...more storage"); using var stream2 = CreateThumbnail(imageFile); await UploadFileToStorageAsync(stream2, storageName, thumbnailContainer); trans.Commit(); //Don't commit unless we were able to also upload the file Console.WriteLine("...done!"); } } } }