Exemplo n.º 1
0
        public void Save(IEnumerable <Chunk> Chunks)
        {
            using (var conn = new SqlConnection(ConnectionString))
            {
                conn.Open();

                using (SqlTransaction tran = conn.BeginTransaction())
                {
                    using (var rdr = new SqlChunkReader(Chunks))
                    {
                        using (var inserter = new SqlBulkCopy(conn, SqlBulkCopyOptions.Default | SqlBulkCopyOptions.KeepIdentity, tran))
                        {
                            inserter.BatchSize            = rdr.RecordsAffected;
                            inserter.DestinationTableName = "Chunks";
                            inserter.NotifyAfter          = 0;

                            inserter.ColumnMappings.Clear();
                            inserter.ColumnMappings.Add("ChunkId", "ChunkId");
                            inserter.ColumnMappings.Add("List", "List");
                            inserter.ColumnMappings.Add("IsBlackList", "IsBlackList");
                            inserter.ColumnMappings.Add("IsHost", "IsHost");
                            inserter.ColumnMappings.Add("Key", "Key");

                            inserter.WriteToServer(rdr);
                            inserter.Close();

                            tran.Commit();
                        }
                    }
                }
            }
        }
        public void Save(IEnumerable<Chunk> Chunks)
        {
            using (var conn = new SqlConnection(ConnectionString))
            {
                conn.Open();

                using (SqlTransaction tran = conn.BeginTransaction())
                {
                    using (var rdr = new SqlChunkReader(Chunks))
                    {
                        using (var inserter = new SqlBulkCopy(conn, SqlBulkCopyOptions.Default | SqlBulkCopyOptions.KeepIdentity, tran))
                        {
                            inserter.BatchSize = rdr.RecordsAffected;
                            inserter.DestinationTableName = "Chunks";
                            inserter.NotifyAfter = 0;

                            inserter.ColumnMappings.Clear();
                            inserter.ColumnMappings.Add("ChunkId", "ChunkId");
                            inserter.ColumnMappings.Add("List", "List");
                            inserter.ColumnMappings.Add("IsBlackList", "IsBlackList");
                            inserter.ColumnMappings.Add("IsHost", "IsHost");
                            inserter.ColumnMappings.Add("Key", "Key");

                            inserter.WriteToServer(rdr);
                            inserter.Close();

                            tran.Commit();
                        }
                    }
                }
            }
        }