public static IEnumerable <int> InserDataCollection(this IDataBaseConnector connector, DataCollection collection, string tableName = null, int batchMount = 1000) { if (tableName == null) { tableName = collection.Name; } if (connector.RefreshTableNames().FirstOrDefault(d => d.Name == tableName) == null) { connector.CreateTable(collection.ComputeData.First(), tableName); } var i = 0; var list = new List <IFreeDocument>(); while (i < collection.Count) { list.Add(collection.ComputeData[i]); if (list.Count == batchMount) { connector.BatchInsert(list, tableName); list = new List <IFreeDocument>(); yield return(i); } i++; } connector.BatchInsert(list, collection.Name); }
public static IEnumerable <IFreeDocument> InserDataCollection(this IDataBaseConnector connector, DataCollection collection, string tableName = null, int batchMount = 1000) { return(collection.ComputeData.BatchDo(data => { if (tableName == null) { tableName = collection.Name; } List <string> columns = new List <string>(); var sample = data.MergeToDocument(); columns = data.GetKeys().ToList(); if (connector.RefreshTableNames().FirstOrDefault(d => d.Name == tableName) == null) { var result = connector.CreateTable(sample, tableName); if (result == false) { throw new Exception(String.Format(GlobalHelper.Get("key_349"), tableName)); } // connector.RefreshTableNames(); } return columns; }, (list, columns) => { connector.BatchInsert(list, (List <string>)columns, collection.Name); })); }
public static IEnumerable <IFreeDocument> InserDataCollection(this IDataBaseConnector connector, DataCollection collection, string tableName = null, int batchMount = 1000) { return(collection.ComputeData.BatchDo(data => { if (tableName == null) { tableName = collection.Name; } if (connector.RefreshTableNames().FirstOrDefault(d => d.Name == tableName) == null) { connector.CreateTable(data, tableName); } return true; }, list => { connector.BatchInsert(list, collection.Name); })); }