Пример #1
0
        public async Task InsertAsync()
        {
            var batchInsertNum = 1000000;
            var batchTable     = new DbTable("t_test");

            batchTable.AddColumn("Name");
            batchTable.AddColumn("No");
            for (var i = 0; i < batchInsertNum; i++)
            {
                var row = batchTable.AddRow();
                row["Name"] = "SmartSql-" + Guid.NewGuid().ToString("N");
                row["No"]   = i;
            }
            using (BatchInsert batchInsert = new BatchInsert(_sqlMapper))
            {
                batchInsert.Table = batchTable;
                batchInsert.AddColumnMapping(new ColumnMapping
                {
                    Column  = "Name",
                    Mapping = "name"
                });
                batchInsert.AddColumnMapping(new ColumnMapping
                {
                    Column  = "No",
                    Mapping = "no"
                });
                await batchInsert.InsertAsync();
            }
        }
Пример #2
0
        public async Task InsertAsync()
        {
            var batchInsertNum = 1000000;
            var batchTable     = new DbTable("t_test");

            batchTable.AddColumn(new DbColumn
            {
                AutoIncrement = true,
                DataType      = typeof(long),
                Name          = "id"
            });
            batchTable.AddColumn("name", typeof(string));
            batchTable.AddColumn("no", typeof(int));
            for (var i = 0; i < batchInsertNum; i++)
            {
                var row = batchTable.AddRow();
                row["name"] = "SmartSql-" + Guid.NewGuid().ToString("N");
                row["no"]   = i;
            }
            using (BatchInsert batchInsert = new BatchInsert(_sqlMapper))
            {
                batchInsert.Table = batchTable;
                batchInsert.AddColumnMapping(new ColumnMapping
                {
                    Column  = "id",
                    Mapping = "Id"
                });
                batchInsert.AddColumnMapping(new ColumnMapping
                {
                    Column  = "name",
                    Mapping = "Name"
                });
                batchInsert.AddColumnMapping(new ColumnMapping
                {
                    Column  = "no",
                    Mapping = "No"
                });
                await batchInsert.InsertAsync();
            }
        }