예제 #1
0
        async Task BulkInsert(IEnumerable <LogEvent> events, MySqlConnection connection)
        {
            var eventData   = events.Select(i => Core.GetColumnsAndValues(i)).ToList();
            var commandText = Core.GetBulkInsertStatement(eventData);

            using (var cmd = new MySqlCommand(commandText, connection))
            {
                var i = 0;
                eventData.ForEach(columnValues => {
                    columnValues.Where(x => x.Value != null).ToList().ForEach(x => cmd.Parameters.AddWithValue($"{x.Key}{i}", x.Value));
                    i++;
                });
                await cmd.ExecuteNonQueryAsync().ConfigureAwait(false);
            }
        }
예제 #2
0
        private async Task BulkInsert(IEnumerable <LogEvent> events, MySqlConnection connection)
        {
            var eventData   = events.Select(i => _core.GetColumnsAndValues(i)).ToList();
            var commandText = _core.GetBulkInsertStatement(eventData);

            using (var cmd = new MySqlCommand(commandText, connection))
            {
                int i = 0;
                foreach (var columnValues in eventData)
                {
                    foreach (var columnValue in columnValues)
                    {
                        if (columnValue.Value != null)
                        {
                            cmd.Parameters.AddWithValue($"{columnValue.Key}{i}", columnValue.Value);
                        }
                    }
                    i++;
                }
                await cmd.ExecuteNonQueryAsync().ConfigureAwait(false);
            }
        }