.NET Core MySqlBulkCopy 批量新增数据

  • .NET Core MySqlBulkCopy 批量新增数据已关闭评论
  • 201 次浏览
  • A+
所属分类:.NET技术
摘要

MySqlConnector有个MySqlBulkCopy批量新增数据方法,不过只能用DataTable,需要把list转成DataTable代码如下:

MySqlConnector有个MySqlBulkCopy批量新增数据方法,不过只能用DataTable,需要把list转成DataTable代码如下:

MySqlBulkCopy mySqlBulkCopy = new MySqlBulkCopy(conn) {   DestinationTableName = "userinfo" };  mySqlBulkCopy.ColumnMappings.AddRange(table.Columns.Cast<DataColumn>().Select(colum => new MySqlBulkCopyColumnMapping { DestinationColumn = colum.ColumnName, SourceOrdinal = colum.Ordinal }).ToList());  mySqlBulkCopy.WriteToServer(table);