Пример #1
0
        private static ParameterInfo[] CreateParameters(IEntityDataReader reader, SqliteCommand command)
        {
            var parameters = new ParameterInfo[reader.Properties.Count];

            for (var i = 0; i < reader.Properties.Count; i++)
            {
                var property = reader.Properties[i];
                var index    = reader.GetPropertyIndex(property);

                var parameter = command.CreateParameter();
                parameter.ParameterName = $"$p{index}";
                parameters[i]           = new ParameterInfo(parameter, property.IsAutoIncrement());
                command.Parameters.Add(parameter);
            }

            return(parameters);
        }
Пример #2
0
        private static string SetColumnMappings(SqlBulkCopy bulkCopy, IEntityDataReader reader)
        {
            var columnsSb = new StringBuilder();

            for (var i = 0; i < reader.Properties.Count; i++)
            {
                var property   = reader.Properties[i];
                var index      = reader.GetPropertyIndex(property);
                var columnName = property.GetColumnBaseName();

                bulkCopy.ColumnMappings.Add(new SqlBulkCopyColumnMapping(index, columnName));

                if (columnsSb.Length > 0)
                {
                    columnsSb.Append(", ");
                }

                columnsSb.Append(columnName).Append(' ').Append(property.GetColumnType());
            }

            return(columnsSb.ToString());
        }
Пример #3
0
        private string GetInsertStatement(IEntityDataReader reader,
                                          string tableIdentifier)
        {
            var sb = new StringBuilder();

            sb.Append("INSERT INTO ").Append(tableIdentifier).Append('(');

            for (var i = 0; i < reader.Properties.Count; i++)
            {
                var column = reader.Properties[i];

                if (i > 0)
                {
                    sb.Append(", ");
                }

                sb.Append(_sqlGenerationHelper.DelimitIdentifier(column.GetColumnBaseName()));
            }

            sb.Append(") VALUES (");

            for (var i = 0; i < reader.Properties.Count; i++)
            {
                var property = reader.Properties[i];
                var index    = reader.GetPropertyIndex(property);

                if (i > 0)
                {
                    sb.Append(", ");
                }

                sb.Append("$p").Append(index);
            }

            sb.Append(");");

            return(sb.ToString());
        }