public virtual async Task <IList <T> > BulkInsertOrUpdateAsync(IList <T> entities, params Expression <Func <T, object> >[] updatePropertiesBy) { if (entities != null && entities.Count > 0) { var strategy = _dbContext.Database.CreateExecutionStrategy(); await strategy.ExecuteAsync(async() => { using (var transaction = _dbContext.Database.BeginTransaction()) { try { var bulkConfig = new BulkConfig() { UseTempDB = true, SetOutputIdentity = true, CalculateStats = true }; await _dbContext.BulkInsertOrUpdateAsync(entities, bulkConfig); transaction.Commit(); } catch (Exception ex) { _logger.LogError(ex.Message, ex.InnerException); transaction.Rollback(); throw; } } }); //using (var transaction = _dbContext.Database.BeginTransaction()) //{ // try // { // var bulkConfig = new BulkConfig() { UseTempDB = true, UseOnlyDataTable = true, SetOutputIdentity = true, CalculateStats = true }; // await _dbContext.BulkInsertOrUpdateAsync(entities, bulkConfig); // transaction.Commit(); // } // catch (Exception ex) // { // _logger.LogError(ex.Message, ex.InnerException); // transaction.Rollback(); // throw; // } //} //try //{ // var bulkConfig = new BulkConfig() { SetOutputIdentity = true, CalculateStats = true }; // if (updatePropertiesBy != null && updatePropertiesBy.Length > 0) // { // bulkConfig.UpdateByProperties = GetMemberNames(updatePropertiesBy); // } // await _dbContext.BulkInsertOrUpdateAsync(entities); //} //catch (Exception ex) //{ // _logger.LogError(ex.Message, ex.InnerException); // throw; //} } return(entities); }