Exemplo n.º 1
0
        // made to get around sql 1000
        private static string DistributeSeed(string tableName, IEnumerable <SysColumn> columns, RowCollection rows)
        {
            int rounds  = rows.Count() / 1000;
            int round   = 0;
            var builder = new StringBuilder();

            while (round <= rounds)
            {
                var set = rows.Skip(round * 1000).Take(1000);
                if (set.Count() > 0)
                {
                    builder.Append($"\tINSERT INTO {tableName} ({string.Join(", ", columns.Select(c => c.name))})\n");
                    builder.Append("\tVALUES \n");
                    builder.Append(string.Join(",\n", set.Select(row =>
                                                                 "(" + string.Join(", ", columns.Select(c => row[c.name])) + ")"
                                                                 )));
                    if (round != rounds)
                    {
                        builder.Append("\n");
                    }
                }
                round++;
            }

            return(builder.ToString());
        }