public override int GetHashCode() { unchecked { var hashCode = ResultLocation.GetHashCode(); hashCode = (hashCode * 397) ^ Dimension.GetHashCode(); hashCode = (hashCode * 397) ^ Layout.Item1.GetHashCode(); hashCode = (hashCode * 397) ^ Layout.Item2.GetHashCode(); hashCode = (hashCode * 397) ^ BatchSize.GetHashCode(); hashCode = (hashCode * 397) ^ PlanDistanceIn.GetHashCode(); hashCode = (hashCode * 397) ^ PlanDistanceOut.GetHashCode(); hashCode = (hashCode * 397) ^ Size[0].GetHashCode(); hashCode = (hashCode * 397) ^ ScaleForward.GetHashCode(); hashCode = (hashCode * 397) ^ ScaleBackward.GetHashCode(); if (Size.GetLength(0) > 1) { hashCode = (hashCode * 397) ^ Size[1].GetHashCode(); } if (Size.GetLength(0) > 2) { hashCode = (hashCode * 397) ^ Size[2].GetHashCode(); } return(hashCode); } }
public override int GetHashCode() { var hash = 1; if (signatureInfo_ != null) { hash ^= SignatureInfo.GetHashCode(); } if (HasBatchNum) { hash ^= BatchNum.GetHashCode(); } if (HasBatchSize) { hash ^= BatchSize.GetHashCode(); } if (HasSignature) { hash ^= Signature.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public void ReportReceivedBatch( string contentType, string contentEncoding, int contentLength, int batchSize, int[] logEventSizes) { if (Start == null) { Start = _clock.Now; } // Request ContentType = contentType; ContentEncoding = contentEncoding; ContentLength.Update(contentLength); // Batch BatchSize.Update(batchSize); _batchDistribution.AddOrUpdate( SizeBucketConverter.From(batchSize), 1, (key, oldValue) => oldValue + 1); // Log events LogEventsPerBatch.Update(logEventSizes.Length); foreach (var logEventSize in logEventSizes) { LogEventSize.Update(logEventSize); var sizeBucket = SizeBucketConverter.From(logEventSize); _logEventDistribution.AddOrUpdate(sizeBucket, 1, (key, oldValue) => oldValue + 1); } }
public void ProduceOrderWithAmount_ShouldReturnCombinationWithSeveralQuantity() { var orderService = new OrderService(); var product = new Product("P1", "Name", 1.22m); var batchSizes = new BatchSize[] { new BatchSize("BS1", 60), new BatchSize("BS2", 100), new BatchSize("BS3", 120), new BatchSize("BS4", 30), new BatchSize("BS5", 20) }; var productBatchSizes = new ProductBatchSize[] { new ProductBatchSize("P1", "BS1"), new ProductBatchSize("P1", "BS2"), new ProductBatchSize("P1", "BS3"), new ProductBatchSize("P1", "BS4"), new ProductBatchSize("P1", "BS5") }; var result = orderService.ProduceOrders(product, batchSizes, productBatchSizes, 70).ToList(); Assert.Equal(2, result.Count); Assert.NotNull(result.SingleOrDefault(r => r.BatchSize == 30)); Assert.NotNull(result.SingleOrDefault(r => r.BatchSize == 20)); Assert.Equal(2, result.SingleOrDefault(r => r.BatchSize == 20).BatchQuantity); }
public void ProduceOrderWithAmount_ShouldReturnClosestBatchSizeFromBiggerBatches() { var orderService = new OrderService(); var product = new Product("P1", "Name", 1.22m); var batchSizes = new BatchSize[] { new BatchSize("BS1", 120), new BatchSize("BS2", 300), new BatchSize("BS3", 500), new BatchSize("BS4", 600), new BatchSize("BS5", 80), new BatchSize("BS6", 100) }; var productBatchSizes = new ProductBatchSize[] { new ProductBatchSize("P1", "BS1"), new ProductBatchSize("P1", "BS2"), new ProductBatchSize("P1", "BS3"), new ProductBatchSize("P1", "BS4"), new ProductBatchSize("P1", "BS5"), new ProductBatchSize("P1", "BS6") }; var result = orderService.ProduceOrders(product, batchSizes, productBatchSizes, 70).ToList(); Assert.Single(result); Assert.NotNull(result.SingleOrDefault(r => r.BatchSize == 80)); }
public override int GetHashCode() { int hash = 1; if (algorithmCase_ == AlgorithmOneofCase.SelectedAlgorithm) { hash ^= SelectedAlgorithm.GetHashCode(); } if (AlphaReal != 0D) { hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(AlphaReal); } if (AlphaImag != 0D) { hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(AlphaImag); } if (Beta != 0D) { hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(Beta); } if (dotDimensionNumbers_ != null) { hash ^= DotDimensionNumbers.GetHashCode(); } if (BatchSize != 0L) { hash ^= BatchSize.GetHashCode(); } hash ^= (int)algorithmCase_; if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
/// <summary> /// Returns the hashcode for this <see cref="InsertAllRequest"/>. /// </summary> /// <returns>The hashcode value.</returns> public override int GetHashCode() { // Make sure to return if it is already provided if (m_hashCode != null) { return(m_hashCode.Value); } // Get first the entity hash code var hashCode = string.Concat(Name, ".InsertAll").GetHashCode(); // Get the qualifier <see cref="Field"/> objects if (Fields != null) { foreach (var field in Fields) { hashCode += field.GetHashCode(); } } // Get the batch size if (BatchSize > 0) { hashCode += BatchSize.GetHashCode(); } // Add the hints if (!string.IsNullOrEmpty(Hints)) { hashCode += Hints.GetHashCode(); } // Set and return the hashcode return((m_hashCode = hashCode).Value); }
public override int GetHashCode() { int hash = 1; if (HasStartTimestamp) { hash ^= StartTimestamp.GetHashCode(); } if (HasEndTimestamp) { hash ^= EndTimestamp.GetHashCode(); } if (HasRegion) { hash ^= Region.GetHashCode(); } if (HasBatchNum) { hash ^= BatchNum.GetHashCode(); } if (HasBatchSize) { hash ^= BatchSize.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
/// <summary> /// Saves the Settings /// </summary> public static void Save() { XmlWriter xmlWriter = new XmlWriter(); if (!xmlWriter.Load(SettingsFile)) { if (File.Exists(SettingsFile)) { try { File.Delete(SettingsFile); } catch (Exception) { return; } } // create it and reload xmlWriter.CreateXmlSettings(SettingsFile); xmlWriter.Load(SettingsFile); } xmlWriter.WriteSetting(cTraktUsername, TraktUsername); xmlWriter.WriteSetting(cTraktPassword, TraktPassword); xmlWriter.WriteSetting(cTraktOAuthToken, TraktOAuthToken); xmlWriter.WriteSetting(cTraktOAuth, TraktOAuth.ToString()); xmlWriter.WriteSetting(cTVDbAccountId, TVDbAccountIdentifier); xmlWriter.WriteSetting(cTMDbSessionId, TMDbSessionId); xmlWriter.WriteSetting(cTMDBSyncWatchlist, TMDbSyncWatchlist.ToString()); xmlWriter.WriteSetting(cIMDbRatingsFilename, IMDbRatingsFilename); xmlWriter.WriteSetting(cIMDbWatchlistFilename, IMDbWatchlistFilename); xmlWriter.WriteSetting(cIMDbUsername, IMDbUsername); xmlWriter.WriteSetting(cIMDBSyncWatchlist, IMDbSyncWatchlist.ToString()); xmlWriter.WriteSetting(cIMDbCustomLists, IMDbCustomLists.ToJSON()); xmlWriter.WriteSetting(cListalSyncWatchlist, ListalSyncWatchlist.ToString()); xmlWriter.WriteSetting(cListalMovieFilename, ListalMovieFilename); xmlWriter.WriteSetting(cListalShowFilename, ListalShowFilename); xmlWriter.WriteSetting(cCritickerMovieFilename, CritickerMovieFilename); xmlWriter.WriteSetting(cLetterboxdRatingsFilename, LetterboxdRatingsFilename); xmlWriter.WriteSetting(cLetterboxdWatchedFilename, LetterboxdWatchedFilename); xmlWriter.WriteSetting(cLetterboxdDiaryFilename, LetterboxdDiaryFilename); xmlWriter.WriteSetting(cFlixsterUserId, FlixsterUserId); xmlWriter.WriteSetting(cFlixsterSyncWantToSee, FlixsterSyncWantToSee.ToString()); xmlWriter.WriteSetting(cMarkAsWatched, MarkAsWatched.ToString()); xmlWriter.WriteSetting(cIgnoreWatchedForWatchlist, IgnoreWatchedForWatchlist.ToString()); xmlWriter.WriteSetting(cEnableIMDb, EnableIMDb.ToString()); xmlWriter.WriteSetting(cEnableTMDb, EnableTMDb.ToString()); xmlWriter.WriteSetting(cEnableTVDb, EnableTVDb.ToString()); xmlWriter.WriteSetting(cEnableListal, EnableListal.ToString()); xmlWriter.WriteSetting(cEnableCriticker, EnableCriticker.ToString()); xmlWriter.WriteSetting(cEnableLetterboxd, EnableLetterboxd.ToString()); xmlWriter.WriteSetting(cEnableFlixster, EnableFlixster.ToString()); xmlWriter.WriteSetting(cLogLevel, ((int)LogSeverityLevel).ToString()); xmlWriter.WriteSetting(cBatchSize, BatchSize.ToString()); xmlWriter.WriteSetting(cWatchedOnReleaseDay, WatchedOnReleaseDay.ToString()); // save file xmlWriter.Save(SettingsFile); }
public IReprocessScopeDescriptor ReprocessWithPeriodicCommit(BatchSize batchSize) { var listBlockDescriptor = new FluentBlockSettingsDescriptor(BlockType.List); listBlockDescriptor.ListUpdateMode = ListUpdateMode.PeriodicBatchCommit; return(listBlockDescriptor); }
public void DisplayOptions() { var lines = new List <Tuple <string, string> > { new Tuple <string, string>("Operations", Operation.ToString()), new Tuple <string, string>("Batch size", BatchSize.ToString()), new Tuple <string, string>("Client count", ClientCount.ToString()), new Tuple <string, string>("Time limit", TimeLimit?.ToString() ?? "<not set>"), }; lines.ForEach(x => Console.WriteLine($"{x.Item1,-12}: {x.Item2}")); Console.WriteLine(); }
private void ProcessBatchSizesWithSeveralQuantity(BatchSize batchSize, int amount, List <BatchSize[]> allCombinations, Product product, ref List <Order> potentialOrdersWithDesiredAmount, ref List <Order> potentialOrdersWithClosestAmount) { // more quantity var sizeWithSeveralQuantity = batchSize.Size; var quantity = 1; while (sizeWithSeveralQuantity < amount) { quantity++; sizeWithSeveralQuantity += batchSize.Size; if (sizeWithSeveralQuantity < amount) { // check with combinations CheckBatchSizeWithCombination(batchSize, allCombinations, amount, out var desiredBatchSizes); if (desiredBatchSizes != null) { var desiredOrder = new List <Order>(); foreach (var batchGroup in desiredBatchSizes.GroupBy(b => b)) { desiredOrder.Add(new Order(product, batchGroup.Key, batchGroup.Count())); } if (IsBetterOrder(potentialOrdersWithDesiredAmount, desiredOrder)) { potentialOrdersWithDesiredAmount = desiredOrder; } } } } if (sizeWithSeveralQuantity == amount) { var desiredOrder = new List <Order> { new Order(product, batchSize, quantity) }; if (IsBetterOrder(potentialOrdersWithDesiredAmount, desiredOrder)) { potentialOrdersWithDesiredAmount = desiredOrder; } } var order = new List <Order> { new Order(product, batchSize, quantity) }; if (IsCloserOrder(potentialOrdersWithClosestAmount, order)) { potentialOrdersWithClosestAmount = order; } }
public override int GetHashCode() { int hashcode = 157; unchecked { if (__isset.startRow) { hashcode = (hashcode * 397) + StartRow.GetHashCode(); } if (__isset.stopRow) { hashcode = (hashcode * 397) + StopRow.GetHashCode(); } if (__isset.timestamp) { hashcode = (hashcode * 397) + Timestamp.GetHashCode(); } if (__isset.columns) { hashcode = (hashcode * 397) + TCollections.GetHashCode(Columns); } if (__isset.caching) { hashcode = (hashcode * 397) + Caching.GetHashCode(); } if (__isset.filterString) { hashcode = (hashcode * 397) + FilterString.GetHashCode(); } if (__isset.batchSize) { hashcode = (hashcode * 397) + BatchSize.GetHashCode(); } if (__isset.sortColumns) { hashcode = (hashcode * 397) + SortColumns.GetHashCode(); } if (__isset.reversed) { hashcode = (hashcode * 397) + Reversed.GetHashCode(); } if (__isset.cacheBlocks) { hashcode = (hashcode * 397) + CacheBlocks.GetHashCode(); } } return(hashcode); }
public override int GetHashCode() { int hash = 1; if (Engine.Length != 0) { hash ^= Engine.GetHashCode(); } if (Normalization.Length != 0) { hash ^= Normalization.GetHashCode(); } if (NInput != 0) { hash ^= NInput.GetHashCode(); } if (NOutput != 0) { hash ^= NOutput.GetHashCode(); } if (LearningRate != 0D) { hash ^= LearningRate.GetHashCode(); } if (BatchSize != 0) { hash ^= BatchSize.GetHashCode(); } if (EpochSize != 0) { hash ^= EpochSize.GetHashCode(); } if (Optimizer.Length != 0) { hash ^= Optimizer.GetHashCode(); } if (LossFunc.Length != 0) { hash ^= LossFunc.GetHashCode(); } hash ^= maxV_.GetHashCode(); hash ^= minV_.GetHashCode(); hash ^= meanV_.GetHashCode(); hash ^= stdV_.GetHashCode(); hash ^= layers_.GetHashCode(); return(hash); }
public void ProduceOrderWithAmount_ShouldReturnDesiredBatchSize() { var orderService = new OrderService(); var product = new Product("P1", "Name", 1.22m); var batchSizes = new BatchSize[] { new BatchSize("BS1", 70), new BatchSize("BS2", 30), new BatchSize("BS3", 40) }; var productBatchSizes = new ProductBatchSize[] { new ProductBatchSize("P1", "BS1"), new ProductBatchSize("P1", "BS2"), new ProductBatchSize("P1", "BS3") }; var result = orderService.ProduceOrders(product, batchSizes, productBatchSizes, 70).ToList(); Assert.Single(result); Assert.NotNull(result.SingleOrDefault(r => r.BatchSize == 70)); }
public void ProduceOrderWithIncorrectDataShouldThrowException(int quantity, string productCode, int batchSize) { var batchQuantities = new BatchQuantity[] { new BatchQuantity(productCode, quantity) }; var products = new Product[] { new Product(productCode, "name", 5.33m) }; var batchSizes = new BatchSize[] { new BatchSize("BS123", batchSize) }; var productBatchSizes = new ProductBatchSize[] { new ProductBatchSize(productCode, "BS123") }; var orderService = new OrderService(); Assert.Throws <ArgumentException>(() => orderService.ProduceOrders(products, batchSizes, productBatchSizes, batchQuantities, false)); }
/// <summary> /// Returns the hashcode for this <see cref="MergeAllRequest"/>. /// </summary> /// <returns>The hashcode value.</returns> public override int GetHashCode() { // Make sure to return if it is already provided if (this.hashCode != null) { return(this.hashCode.Value); } // Get first the entity hash code var hashCode = string.Concat(Name, ".MergeAll").GetHashCode(); // Get the qualifier <see cref="Field"/> objects if (Fields != null) { foreach (var field in Fields) { hashCode += field.GetHashCode(); } } // Get the qualifier <see cref="Field"/> objects if (Qualifiers != null) // Much faster than Qualifiers?.<Methods|Properties> { foreach (var field in Qualifiers) { hashCode += field.GetHashCode(); } } // Get the batch size if (BatchSize > 0) { hashCode += BatchSize.GetHashCode(); } // Add the hints if (!string.IsNullOrWhiteSpace(Hints)) { hashCode += Hints.GetHashCode(); } // Set and return the hashcode return((this.hashCode = hashCode).Value); }
/// <summary> /// Returns the hashcode for this <see cref="UpdateAllRequest"/>. /// </summary> /// <returns>The hashcode value.</returns> public override int GetHashCode() { // Make sure to return if it is already provided if (this.hashCode != null) { return(this.hashCode.Value); } // Get first the entity hash code var hashCode = HashCode.Combine(Name, ".UpdateAll"); // Get the fields if (Fields != null) { foreach (var field in Fields) { hashCode += field.GetHashCode(); } } // Get the qualifier <see cref="Field"/> objects if (Fields != null) { foreach (var field in Qualifiers) { hashCode += field.GetHashCode(); } } // Get the batch size if (BatchSize > 0) { hashCode += BatchSize.GetHashCode(); } // Add the hints if (!string.IsNullOrWhiteSpace(Hints)) { hashCode += Hints.GetHashCode(); } // Set and return the hashcode return((this.hashCode = hashCode).Value); }
/// <summary> /// <para>Implementation of <see cref="IEquatable{T}"/> for <see cref="SQLQuery"/>.</para> /// <para>Returns true if <see cref="SQLQuery"/> references the same <see cref="object"/> or its members are equal.</para> /// </summary> /// <param name="other"></param> /// <returns></returns> public bool Equals(SQLQuery <T> other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(SQL.Equals(other.SQL) && DbTableName.Equals(other.DbTableName) && TObjects.Equals(other.TObjects) && CommandType.Equals(other.CommandType) && IsBulk.Equals(other.IsBulk) && BatchSize.Equals(other.BatchSize)); }
public override int GetHashCode() { unchecked { var hashCode = base.GetHashCode(); hashCode = (hashCode * 397) ^ (InputMappings != null ? InputMappings.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Database != null ? Database.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (TableName != null ? TableName.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Result != null ? Result.GetHashCode() : 0); hashCode = (hashCode * 397) ^ CheckConstraints.GetHashCode(); hashCode = (hashCode * 397) ^ FireTriggers.GetHashCode(); hashCode = (hashCode * 397) ^ UseInternalTransaction.GetHashCode(); hashCode = (hashCode * 397) ^ KeepIdentity.GetHashCode(); hashCode = (hashCode * 397) ^ KeepTableLock.GetHashCode(); hashCode = (hashCode * 397) ^ (Timeout != null ? Timeout.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (BatchSize != null ? BatchSize.GetHashCode() : 0); hashCode = (hashCode * 397) ^ IgnoreBlankRows.GetHashCode(); return(hashCode); } }
public IList <Order> ProduceOrders( Product[] products, BatchSize[] batchSizes, ProductBatchSize[] productBatchSizes, BatchQuantity[] batchQuantities, bool batchSizeSelection) { var orders = new List <Order>(); var productBatchSizesDict = productBatchSizes .GroupBy(pbs => pbs.ProductCode) .ToDictionary(gr => gr.Key, gr => gr.Select(pbs => pbs.BatchSizeCode).ToList()); var batchQuantitiesDict = batchQuantities.ToDictionary(bq => bq.ProductCode, bq => bq.Quantity); var batchSizesDict = batchSizes.ToDictionary(bs => bs.Code, bs => bs); foreach (var product in products) { var productBatchSizesExist = productBatchSizesDict.TryGetValue(product.Code, out var availableProductBatchSizes); BatchSize batch; if (productBatchSizesExist) { var bsizes = availableProductBatchSizes?.Select(pbs => batchSizesDict[pbs]).OrderBy(bs => bs.Size).ToList(); if (bsizes is null || !bsizes.Any()) { throw new ArgumentException($"Batch sizes for product {product.Code} not found"); } batch = batchSizeSelection ? bsizes.Last() : bsizes.First(); } else { batch = new BatchSize($"{GeneratedBatchSize}{product.Code}", 1); } var quantity = batchQuantitiesDict.ContainsKey(product.Code) ? batchQuantitiesDict[product.Code] : 1; orders.Add(new Order(product, batch, quantity)); } ; return(orders.ToList()); }
public override int GetHashCode() { int hash = 1; if (Enabled != false) { hash ^= Enabled.GetHashCode(); } if (SessionSamplingFraction != 0D) { hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(SessionSamplingFraction); } if (MaxBufferSizeKb != 0) { hash ^= MaxBufferSizeKb.GetHashCode(); } if (BatchSize != 0) { hash ^= BatchSize.GetHashCode(); } if (UpdateIntervalMs != 0L) { hash ^= UpdateIntervalMs.GetHashCode(); } if (FrameRateSampleIntervalMs != 0L) { hash ^= FrameRateSampleIntervalMs.GetHashCode(); } if (FrameRateSamplePeriodMs != 0L) { hash ^= FrameRateSamplePeriodMs.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public bool Equals(CLFFTSettings other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(ResultLocation.Equals(other.ResultLocation) && Dimension.Equals(other.Dimension) && Layout.Equals(other.Layout) && Size.SequenceEqual(other.Size) && StrideIn.SequenceEqual(other.StrideIn) && StrideOut.SequenceEqual(other.StrideOut) && BatchSize.Equals(other.BatchSize) && PlanDistanceIn.Equals(other.PlanDistanceIn) && PlanDistanceOut.Equals(other.PlanDistanceOut) && ScaleForward.Equals(other.ScaleForward) && ScaleBackward.Equals(other.ScaleBackward)); }
/// <summary>Creates a command to execute the batch operation.</summary> /// <param name="query">The query.</param> /// <param name="entity">The schema entity.</param> /// <returns>The new command to execute the batch operation.</returns> internal DbCommand CreateCommand <T>(ObjectQuery query, SchemaEntityType <T> entity) { // GET mapping var mapping = entity.Info.EntityTypeMapping.MappingFragment; var store = mapping.StoreEntitySet; var tableName = string.IsNullOrEmpty(store.Schema) ? string.Concat("[", store.Table, "]") : string.Concat("[", store.Schema, "].[", store.Table, "]"); // GET keys mappings var columnKeys = new List <string>(); foreach (var propertyKey in entity.Info.Key.PropertyRefs) { var mappingProperty = mapping.ScalarProperties.Find(x => x.Name == propertyKey.Name); if (mappingProperty == null) { throw new Exception(string.Format(ExceptionMessage.BatchOperations_PropertyNotFound, propertyKey.Name)); } columnKeys.Add(mappingProperty.ColumnName); } // GET command text template var commandTextTemplate = BatchSize > 0 ? BatchDelayInterval > 0 ? CommandTextWhileDelayTemplate : CommandTextWhileTemplate : CommandTextTemplate; // GET inner query var querySelect = query.ToTraceString(); // GET primary key join var primaryKeys = string.Join(Environment.NewLine + "AND ", columnKeys.Select(x => string.Concat("A.[", x, "] = B.[", x, "]"))); // REPLACE template commandTextTemplate = commandTextTemplate.Replace("{TableName}", tableName) .Replace("{Select}", querySelect) .Replace("{PrimaryKeys}", primaryKeys) .Replace("{Top}", BatchSize.ToString()) .Replace("{Delay}", TimeSpan.FromMilliseconds(BatchDelayInterval).ToString(@"hh\:mm\:ss\:fff")); // CREATE command var command = query.Context.CreateStoreCommand(); command.CommandText = commandTextTemplate; // ADD Parameter var parameterCollection = query.Parameters; foreach (var parameter in parameterCollection) { var param = command.CreateParameter(); param.ParameterName = parameter.Name; param.Value = parameter.Value; command.Parameters.Add(param); } return(command); }
public DbCommand CreateCommand(IQueryable query, IEntityType entity) { #if NETSTANDARD1_3 try { Assembly assembly; try { assembly = Assembly.Load(new AssemblyName("Microsoft.EntityFrameworkCore.SqlServer")); } catch (Exception ex) { throw new Exception(ExceptionMessage.BatchOperations_AssemblyNotFound); } if (assembly != null) { var type = assembly.GetType("Microsoft.EntityFrameworkCore.SqlServerMetadataExtensions"); var sqlServerEntityTypeMethod = type.GetMethod("SqlServer", new[] { typeof(IEntityType) }); var sqlServerPropertyMethod = type.GetMethod("SqlServer", new[] { typeof(IProperty) }); var sqlServer = (IRelationalEntityTypeAnnotations)sqlServerEntityTypeMethod.Invoke(null, new[] { entity }); // GET mapping var tableName = string.IsNullOrEmpty(sqlServer.Schema) ? string.Concat("[", sqlServer.TableName, "]") : string.Concat("[", sqlServer.Schema, "].[", sqlServer.TableName, "]"); // GET keys mappings var columnKeys = new List <string>(); foreach (var propertyKey in entity.GetKeys().ToList()[0].Properties) { var mappingProperty = sqlServerPropertyMethod.Invoke(null, new[] { propertyKey }); var columnNameProperty = mappingProperty.GetType().GetProperty("ColumnName", BindingFlags.Public | BindingFlags.Instance); columnKeys.Add((string)columnNameProperty.GetValue(mappingProperty)); } // GET command text template var commandTextTemplate = BatchSize > 0 ? BatchDelayInterval > 0 ? CommandTextWhileDelayTemplate : CommandTextWhileTemplate : CommandTextTemplate; // GET inner query #if EFCORE RelationalQueryContext queryContext; var relationalCommand = query.CreateCommand(out queryContext); #else var relationalCommand = query.CreateCommand(); #endif var querySelect = relationalCommand.CommandText; // GET primary key join var primaryKeys = string.Join(Environment.NewLine + "AND ", columnKeys.Select(x => string.Concat("A.[", x, "] = B.[", x, "]"))); // REPLACE template commandTextTemplate = commandTextTemplate.Replace("{TableName}", tableName) .Replace("{Select}", querySelect) .Replace("{PrimaryKeys}", primaryKeys) .Replace("{Top}", BatchSize.ToString()) .Replace("{Delay}", TimeSpan.FromMilliseconds(BatchDelayInterval).ToString(@"hh\:mm\:ss\:fff")); // CREATE command var command = query.GetDbContext().CreateStoreCommand(); command.CommandText = commandTextTemplate; #if EFCORE // ADD Parameter foreach (var relationalParameter in relationalCommand.Parameters) { var parameter = queryContext.ParameterValues[relationalParameter.InvariantName]; var param = command.CreateParameter(); param.ParameterName = relationalParameter.InvariantName; param.Value = parameter ?? DBNull.Value; command.Parameters.Add(param); } #else // ADD Parameter var parameterCollection = relationalCommand.Parameters; foreach (var parameter in parameterCollection) { var param = command.CreateParameter(); param.ParameterName = parameter.Name; param.Value = parameter.Value ?? DBNull.Value; command.Parameters.Add(param); } #endif return(command); } return(null); } catch (Exception) { return(null); } #else var assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(x => x.FullName.StartsWith("Microsoft.EntityFrameworkCore.SqlServer", StringComparison.InvariantCulture)); if (assembly != null) { var type = assembly.GetType("Microsoft.EntityFrameworkCore.SqlServerMetadataExtensions"); var sqlServerEntityTypeMethod = type.GetMethod("SqlServer", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(IEntityType) }, null); var sqlServerPropertyMethod = type.GetMethod("SqlServer", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(IProperty) }, null); var sqlServer = (IRelationalEntityTypeAnnotations)sqlServerEntityTypeMethod.Invoke(null, new[] { entity }); // GET mapping var tableName = string.IsNullOrEmpty(sqlServer.Schema) ? string.Concat("[", sqlServer.TableName, "]") : string.Concat("[", sqlServer.Schema, "].[", sqlServer.TableName, "]"); // GET keys mappings var columnKeys = new List <string>(); foreach (var propertyKey in entity.GetKeys().ToList()[0].Properties) { var mappingProperty = sqlServerPropertyMethod.Invoke(null, new[] { propertyKey }); var columnNameProperty = mappingProperty.GetType().GetProperty("ColumnName", BindingFlags.Public | BindingFlags.Instance); columnKeys.Add((string)columnNameProperty.GetValue(mappingProperty)); } // GET command text template var commandTextTemplate = BatchSize > 0 ? BatchDelayInterval > 0 ? CommandTextWhileDelayTemplate : CommandTextWhileTemplate : CommandTextTemplate; // GET inner query #if EFCORE RelationalQueryContext queryContext; var relationalCommand = query.CreateCommand(out queryContext); #else var relationalCommand = query.CreateCommand(); #endif var querySelect = relationalCommand.CommandText; // GET primary key join var primaryKeys = string.Join(Environment.NewLine + "AND ", columnKeys.Select(x => string.Concat("A.[", x, "] = B.[", x, "]"))); // REPLACE template commandTextTemplate = commandTextTemplate.Replace("{TableName}", tableName) .Replace("{Select}", querySelect) .Replace("{PrimaryKeys}", primaryKeys) .Replace("{Top}", BatchSize.ToString()) .Replace("{Delay}", TimeSpan.FromMilliseconds(BatchDelayInterval).ToString(@"hh\:mm\:ss\:fff")); // CREATE command var command = query.GetDbContext().CreateStoreCommand(); command.CommandText = commandTextTemplate; #if EFCORE // ADD Parameter foreach (var relationalParameter in relationalCommand.Parameters) { var parameter = queryContext.ParameterValues[relationalParameter.InvariantName]; var param = command.CreateParameter(); param.ParameterName = relationalParameter.InvariantName; param.Value = parameter ?? DBNull.Value; command.Parameters.Add(param); } #else // ADD Parameter var parameterCollection = relationalCommand.Parameters; foreach (var parameter in parameterCollection) { var param = command.CreateParameter(); param.ParameterName = parameter.Name; param.Value = parameter.Value ?? DBNull.Value; command.Parameters.Add(param); } #endif return(command); } return(null); #endif }
/// <summary>Creates a command to execute the batch operation.</summary> /// <exception cref="Exception">Thrown when an exception error condition occurs.</exception> /// <typeparam name="T">Generic type parameter.</typeparam> /// <param name="query">The query.</param> /// <param name="entity">The schema entity.</param> /// <param name="visitor">The visitor.</param> /// <returns>The new command to execute the batch operation.</returns> internal DbCommand CreateCommand <T>(ObjectQuery query, SchemaEntityType <T> entity) { // GET command var command = query.Context.CreateStoreCommand(); bool isMySql = command.GetType().FullName.Contains("MySql"); var isSqlCe = command.GetType().Name == "SqlCeCommand"; var isOracle = command.GetType().Namespace.Contains("Oracle"); // Oracle BindByName if (isOracle) { var bindByNameProperty = command.GetType().GetProperty("BindByName") ?? command.GetType().GetProperty("PassParametersByName"); if (bindByNameProperty != null) { bindByNameProperty.SetValue(command, true, null); } } // GET mapping var mapping = entity.Info.EntityTypeMapping.MappingFragment; var store = mapping.StoreEntitySet; string tableName; if (isMySql) { tableName = string.Concat("`", store.Table, "`"); } else if (isSqlCe) { tableName = string.Concat("[", store.Table, "]"); } else if (isOracle) { tableName = string.IsNullOrEmpty(store.Schema) || store.Schema == "dbo" ? string.Concat("\"", store.Table, "\"") : string.Concat("\"", store.Schema, "\".\"", store.Table, "\""); } else { tableName = string.IsNullOrEmpty(store.Schema) ? string.Concat("[", store.Table, "]") : string.Concat("[", store.Schema, "].[", store.Table, "]"); } // GET keys mappings var columnKeys = new List <string>(); foreach (var propertyKey in entity.Info.Key.PropertyRefs) { var mappingProperty = mapping.ScalarProperties.Find(x => x.Name == propertyKey.Name); if (mappingProperty == null) { throw new Exception(string.Format(ExceptionMessage.BatchOperations_PropertyNotFound, propertyKey.Name)); } columnKeys.Add(mappingProperty.ColumnName); } // GET command text template var commandTextTemplate = command.GetType().Name == "NpgsqlCommand" ? CommandTextPostgreSQLTemplate : isOracle ? CommandTextOracleTemplate : isMySql ? CommandTextTemplate_MySql : isSqlCe ? CommandTextSqlCeTemplate : BatchSize > 0 ? BatchDelayInterval > 0 ? CommandTextWhileDelayTemplate : CommandTextWhileTemplate : CommandTextTemplate; // GET inner query var customQuery = query.GetCommandTextAndParameters(); var querySelect = customQuery.Item1; // GET primary key join string primaryKeys; if (isSqlCe || isOracle) { primaryKeys = string.Join(Environment.NewLine + "AND ", columnKeys.Select(x => string.Concat(tableName + ".", EscapeName(x, isMySql, isOracle), " = B.", EscapeName(x, isMySql, isOracle), ""))); } else { primaryKeys = string.Join(Environment.NewLine + "AND ", columnKeys.Select(x => string.Concat("A.", EscapeName(x, isMySql, isOracle), " = B.", EscapeName(x, isMySql, isOracle), ""))); } // REPLACE template commandTextTemplate = commandTextTemplate.Replace("{TableName}", tableName) .Replace("{Select}", querySelect) .Replace("{PrimaryKeys}", primaryKeys) .Replace("{Top}", BatchSize.ToString()) .Replace("{Delay}", TimeSpan.FromMilliseconds(BatchDelayInterval).ToString(@"hh\:mm\:ss\:fff")); // CREATE command command.CommandText = commandTextTemplate; // ADD Parameter var parameterCollection = customQuery.Item2; #if EF5 foreach (ObjectParameter parameter in parameterCollection) { var param = command.CreateParameter(); param.ParameterName = parameter.Name; param.Value = parameter.Value ?? DBNull.Value; command.Parameters.Add(param); } #elif EF6 foreach (DbParameter parameter in parameterCollection) { var param = command.CreateParameter(); param.ParameterName = parameter.ParameterName; param.Value = parameter.Value ?? DBNull.Value; command.Parameters.Add(param); } #endif return(command); }
/// <summary>Creates a command to execute the batch operation.</summary> /// <exception cref="Exception">Thrown when an exception error condition occurs.</exception> /// <typeparam name="T">Generic type parameter.</typeparam> /// <param name="query">The query.</param> /// <param name="tdTableDefinition">The schema entity.</param> /// <returns>The new command to execute the batch operation.</returns> public DbCommand CreateCommand(ObjectQuery query, TableDefinition tdTableDefinition) { // GET command var command = query.Context.CreateStoreCommand(); bool isPostgreSql = command.GetType().Name == "NpgsqlCommand"; bool isMySql = command.GetType().FullName.Contains("MySql"); var isSqlCe = command.GetType().Name == "SqlCeCommand"; var isOracle = command.GetType().Namespace.Contains("Oracle"); var isSQLite = command.GetType().Namespace.Contains("SQLite"); // Oracle BindByName if (isOracle) { var bindByNameProperty = command.GetType().GetProperty("BindByName") ?? command.GetType().GetProperty("PassParametersByName"); if (bindByNameProperty != null) { bindByNameProperty.SetValue(command, true, null); } } string tableName; if (isMySql) { tableName = string.Concat("`", tdTableDefinition.Table, "`"); } else if (isSqlCe) { tableName = string.Concat("[", tdTableDefinition.Table, "]"); } else if (isSQLite) { tableName = string.Concat("\"", tdTableDefinition.Table, "\""); } else if (isOracle) { tableName = string.IsNullOrEmpty(tdTableDefinition.Schema) || tdTableDefinition.Schema == "dbo" ? string.Concat("\"", tdTableDefinition.Table, "\"") : string.Concat("\"", tdTableDefinition.Schema, "\".\"", tdTableDefinition.Table, "\""); } else { tableName = string.IsNullOrEmpty(tdTableDefinition.Schema) ? string.Concat("[", tdTableDefinition.Table, "]") : string.Concat("[", tdTableDefinition.Schema, "].[", tdTableDefinition.Table, "]"); } // GET command text template var commandTextTemplate = isPostgreSql ? CommandTextPostgreSQLTemplate : isOracle ? CommandTextOracleTemplate : isMySql ? CommandTextTemplate_MySql : isSqlCe ? CommandTextSqlCeTemplate : isSQLite ? CommandTextSQLiteTemplate : BatchSize > 0 ? BatchDelayInterval > 0 ? CommandTextWhileDelayTemplate : CommandTextWhileTemplate : CommandTextTemplate; // GET inner query var customQuery = query.GetCommandTextAndParameters(); if (customQuery.Item1.EndsWith("WHERE 1 = 0", StringComparison.InvariantCultureIgnoreCase)) { return(null); } if (isPostgreSql && customQuery.Item1.EndsWith("WHERE TRUE = FALSE", StringComparison.InvariantCultureIgnoreCase)) { return(null); } var querySelect = customQuery.Item1; // GET primary key join string primaryKeys; if (isSqlCe || isOracle || isSQLite) { primaryKeys = string.Join(Environment.NewLine + "AND ", tdTableDefinition.Keys.Select(x => string.Concat(tableName + ".", EscapeName(x.ColumnName, isMySql, isOracle), " = B.", EscapeName(x.ColumnName, isMySql, isOracle), ""))); } else { primaryKeys = string.Join(Environment.NewLine + "AND ", tdTableDefinition.Keys.Select(x => string.Concat("A.", EscapeName(x.ColumnName, isMySql, isOracle), " = B.", EscapeName(x.ColumnName, isMySql, isOracle), ""))); } // REPLACE template commandTextTemplate = commandTextTemplate.Replace("{TableName}", tableName) .Replace("{Select}", querySelect) .Replace("{PrimaryKeys}", primaryKeys) .Replace("{Top}", BatchSize.ToString()) .Replace("{Delay}", TimeSpan.FromMilliseconds(BatchDelayInterval).ToString(@"hh\:mm\:ss\:fff")) .Replace("{Hint}", UseTableLock ? "WITH ( TABLOCK )" : ""); // CREATE command command.CommandText = commandTextTemplate; // ADD Parameter var parameterCollection = customQuery.Item2; #if EF5 foreach (ObjectParameter parameter in parameterCollection) { var param = command.CreateParameter(); param.CopyFrom(parameter); command.Parameters.Add(param); } #elif EF6 foreach (DbParameter parameter in parameterCollection) { var param = command.CreateParameter(); param.CopyFrom(parameter); command.Parameters.Add(param); } #endif return(command); }
public DbCommand CreateCommand(IQueryable query, IEntityType entity) { var assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(x => x.FullName == "EntityFramework.MicrosoftSqlServer, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60"); if (assembly != null) { var type = assembly.GetType("Microsoft.Data.Entity.SqlServerMetadataExtensions"); var sqlServerEntityTypeMethod = type.GetMethod("SqlServer", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(IEntityType) }, null); var sqlServerPropertyMethod = type.GetMethod("SqlServer", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(IProperty) }, null); var sqlServer = (IRelationalEntityTypeAnnotations)sqlServerEntityTypeMethod.Invoke(null, new[] { entity }); // GET mapping var tableName = string.IsNullOrEmpty(sqlServer.Schema) ? string.Concat("[", sqlServer.TableName, "]") : string.Concat("[", sqlServer.Schema, "].[", sqlServer.TableName, "]"); // GET keys mappings var columnKeys = new List <string>(); foreach (var propertyKey in entity.GetKeys().ToList()[0].Properties) { var mappingProperty = sqlServerPropertyMethod.Invoke(null, new[] { propertyKey }); var columnNameProperty = mappingProperty.GetType().GetProperty("ColumnName", BindingFlags.Public | BindingFlags.Instance); columnKeys.Add((string)columnNameProperty.GetValue(mappingProperty)); } // GET command text template var commandTextTemplate = BatchSize > 0 ? BatchDelayInterval > 0 ? CommandTextWhileDelayTemplate : CommandTextWhileTemplate : CommandTextTemplate; // GET inner query var relationalCommand = query.CreateCommand(); var querySelect = relationalCommand.CommandText; // GET primary key join var primaryKeys = string.Join(Environment.NewLine + "AND ", columnKeys.Select(x => string.Concat("A.[", x, "] = B.[", x, "]"))); // REPLACE template commandTextTemplate = commandTextTemplate.Replace("{TableName}", tableName) .Replace("{Select}", querySelect) .Replace("{PrimaryKeys}", primaryKeys) .Replace("{Top}", BatchSize.ToString()) .Replace("{Delay}", TimeSpan.FromMilliseconds(BatchDelayInterval).ToString(@"hh\:mm\:ss\:fff")); // CREATE command var command = query.GetDbContext().CreateStoreCommand(); command.CommandText = commandTextTemplate; // ADD Parameter var parameterCollection = relationalCommand.Parameters; foreach (var parameter in parameterCollection) { var param = command.CreateParameter(); param.ParameterName = parameter.Name; param.Value = parameter.Value; command.Parameters.Add(param); } return(command); } return(null); }
public IOverrideConfigurationDescriptor WithPeriodicCommit(List <T> values, short maxBlockSize, BatchSize batchSize) { var jsonValues = Serialize(values); var listBlockDescriptor = new FluentBlockSettingsDescriptor(jsonValues, maxBlockSize); listBlockDescriptor.ListUpdateMode = ListUpdateMode.PeriodicBatchCommit; switch (batchSize) { case BatchSize.NotSet: listBlockDescriptor.UncommittedItemsThreshold = 100; break; case BatchSize.Ten: listBlockDescriptor.UncommittedItemsThreshold = 10; break; case BatchSize.Fifty: listBlockDescriptor.UncommittedItemsThreshold = 50; break; case BatchSize.Hundred: listBlockDescriptor.UncommittedItemsThreshold = 100; break; case BatchSize.FiveHundred: listBlockDescriptor.UncommittedItemsThreshold = 500; break; } return(listBlockDescriptor); }
public DbCommand CreateCommand(IQueryable query, IEntityType entity) { var context = query.GetDbContext(); var databaseCreator = context.Database.GetService <IDatabaseCreator>(); var assembly = databaseCreator.GetType().GetTypeInfo().Assembly; var assemblyName = assembly.GetName().Name; MethodInfo dynamicProviderEntityType = null; MethodInfo dynamicProviderProperty = null; bool isSqlServer = false; bool isPostgreSQL = false; bool isMySql = false; bool isMySqlPomelo = false; bool isSQLite = false; if (assemblyName == "Microsoft.EntityFrameworkCore.SqlServer") { isSqlServer = true; var type = assembly.GetType("Microsoft.EntityFrameworkCore.SqlServerMetadataExtensions"); dynamicProviderEntityType = type.GetMethod("SqlServer", new[] { typeof(IEntityType) }); dynamicProviderProperty = type.GetMethod("SqlServer", new[] { typeof(IProperty) }); } else if (assemblyName == "Npgsql.EntityFrameworkCore.PostgreSQL") { isPostgreSQL = true; var type = assembly.GetType("Microsoft.EntityFrameworkCore.NpgsqlMetadataExtensions"); dynamicProviderEntityType = type.GetMethod("Npgsql", new[] { typeof(IEntityType) }); dynamicProviderProperty = type.GetMethod("Npgsql", new[] { typeof(IProperty) }); } else if (assemblyName == "MySql.Data.EntityFrameworkCore") { isMySql = true; var type = assembly.GetType("MySQL.Data.EntityFrameworkCore.MySQLMetadataExtensions"); dynamicProviderEntityType = type.GetMethod("MySQL", new[] { typeof(IEntityType) }); dynamicProviderProperty = type.GetMethod("MySQL", new[] { typeof(IProperty) }); } else if (assemblyName == "Pomelo.EntityFrameworkCore.MySql") { isMySqlPomelo = true; var type = assembly.GetType("Microsoft.EntityFrameworkCore.MySqlMetadataExtensions"); dynamicProviderEntityType = type.GetMethod("MySql", new[] { typeof(IEntityType) }); dynamicProviderProperty = type.GetMethod("MySql", new[] { typeof(IProperty) }); } else if (assemblyName == "Microsoft.EntityFrameworkCore.Sqlite") { isSQLite = true; // CHANGE all for this one? dynamicProviderEntityType = typeof(RelationalMetadataExtensions).GetMethod("Relational", new[] { typeof(IEntityType) }); dynamicProviderProperty = typeof(RelationalMetadataExtensions).GetMethod("Relational", new[] { typeof(IProperty) }); } else { throw new Exception(string.Format(ExceptionMessage.Unsupported_Provider, assemblyName)); } string tableName = ""; var columnKeys = new List <string>(); string primaryKeys = ""; if (isSqlServer) { var sqlServer = (IRelationalEntityTypeAnnotations)dynamicProviderEntityType.Invoke(null, new[] { entity }); // GET mapping tableName = string.IsNullOrEmpty(sqlServer.Schema) ? string.Concat("[", sqlServer.TableName, "]") : string.Concat("[", sqlServer.Schema, "].[", sqlServer.TableName, "]"); // GET keys mappings foreach (var propertyKey in entity.GetKeys().ToList()[0].Properties) { var mappingProperty = dynamicProviderProperty.Invoke(null, new[] { propertyKey }); var columnNameProperty = mappingProperty.GetType().GetProperty("ColumnName", BindingFlags.Public | BindingFlags.Instance); columnKeys.Add((string)columnNameProperty.GetValue(mappingProperty)); } // GET primary key join primaryKeys = string.Join(Environment.NewLine + "AND ", columnKeys.Select(x => string.Concat("A.[", x, "] = B.[", x, "]"))); } else if (isPostgreSQL) { var sqlServer = (IRelationalEntityTypeAnnotations)dynamicProviderEntityType.Invoke(null, new[] { entity }); // GET mapping tableName = string.IsNullOrEmpty(sqlServer.Schema) ? string.Concat("\"", sqlServer.TableName, "\"") : string.Concat("\"", sqlServer.Schema, "\".\"", sqlServer.TableName, "\""); // GET keys mappings foreach (var propertyKey in entity.GetKeys().ToList()[0].Properties) { var mappingProperty = dynamicProviderProperty.Invoke(null, new[] { propertyKey }); var columnNameProperty = mappingProperty.GetType().GetProperty("ColumnName", BindingFlags.Public | BindingFlags.Instance); columnKeys.Add((string)columnNameProperty.GetValue(mappingProperty)); } primaryKeys = string.Join(Environment.NewLine + "AND ", columnKeys.Select(x => string.Concat("A.\"", x, "\" = B.\"", x, "\""))); } else if (isMySqlPomelo) { var sqlServer = (IRelationalEntityTypeAnnotations)dynamicProviderEntityType.Invoke(null, new[] { entity }); // GET mapping tableName = string.Concat("`", sqlServer.TableName, "`"); // GET keys mappings foreach (var propertyKey in entity.GetKeys().ToList()[0].Properties) { var mappingProperty = dynamicProviderProperty.Invoke(null, new[] { propertyKey }); var columnNameProperty = mappingProperty.GetType().GetProperty("ColumnName", BindingFlags.Public | BindingFlags.Instance); columnKeys.Add((string)columnNameProperty.GetValue(mappingProperty)); } primaryKeys = string.Join(Environment.NewLine + "AND ", columnKeys.Select(x => string.Concat("A.`", x, "` = B.`", x, "`"))); } else if (isMySql) { var sqlServer = (IRelationalEntityTypeAnnotations)dynamicProviderEntityType.Invoke(null, new[] { entity }); // GET mapping tableName = string.Concat("`", sqlServer.TableName, "`"); // GET keys mappings foreach (var propertyKey in entity.GetKeys().ToList()[0].Properties) { var mappingProperty = dynamicProviderProperty.Invoke(null, new[] { propertyKey }); var columnNameProperty = mappingProperty.GetType().GetProperty("ColumnName", BindingFlags.Public | BindingFlags.Instance); columnKeys.Add((string)columnNameProperty.GetValue(mappingProperty)); } primaryKeys = string.Join(Environment.NewLine + "AND ", columnKeys.Select(x => string.Concat("A.`", x, "` = B.`", x, "`"))); } else if (isSQLite) { var sqlServer = (IRelationalEntityTypeAnnotations)dynamicProviderEntityType.Invoke(null, new[] { entity }); // GET mapping tableName = string.Concat("\"", sqlServer.TableName, "\""); // GET keys mappings foreach (var propertyKey in entity.GetKeys().ToList()[0].Properties) { var mappingProperty = dynamicProviderProperty.Invoke(null, new[] { propertyKey }); var columnNameProperty = mappingProperty.GetType().GetProperty("ColumnName", BindingFlags.Public | BindingFlags.Instance); columnKeys.Add((string)columnNameProperty.GetValue(mappingProperty)); } primaryKeys = string.Join(Environment.NewLine + "AND ", columnKeys.Select(x => string.Concat(tableName + "." + "\"" + x + "\"", " = B.\"", x, "\""))); } // GET command text template var commandTextTemplate = isPostgreSQL ? CommandTextPostgreSQLTemplate : isMySql || isMySqlPomelo ? CommandTextTemplate_MySql : isSQLite ? CommandTextSQLiteTemplate : BatchSize > 0 ? BatchDelayInterval > 0 ? CommandTextWhileDelayTemplate : CommandTextWhileTemplate : CommandTextTemplate; // GET inner query #if EFCORE RelationalQueryContext queryContext; var relationalCommand = query.CreateCommand(out queryContext); #else var relationalCommand = query.CreateCommand(); #endif var querySelect = relationalCommand.CommandText; // REPLACE template commandTextTemplate = commandTextTemplate.Replace("{TableName}", tableName) .Replace("{Select}", querySelect) .Replace("{PrimaryKeys}", primaryKeys) .Replace("{Top}", BatchSize.ToString()) .Replace("{Delay}", TimeSpan.FromMilliseconds(BatchDelayInterval).ToString(@"hh\:mm\:ss\:fff")) .Replace("{Hint}", UseTableLock ? "WITH ( TABLOCK )" : ""); // CREATE command var command = query.GetDbContext().CreateStoreCommand(); command.CommandText = commandTextTemplate; #if EFCORE // ADD Parameter foreach (var relationalParameter in relationalCommand.Parameters) { var parameter = queryContext.ParameterValues[relationalParameter.InvariantName]; var param = command.CreateParameter(); param.CopyFrom(relationalParameter, parameter); command.Parameters.Add(param); } #else // ADD Parameter var parameterCollection = relationalCommand.Parameters; foreach (var parameter in parameterCollection) { var param = command.CreateParameter(); param.CopyFrom(parameter); command.Parameters.Add(param); } #endif return(command); }