标签:use linq style i++ collect top color iss one
EF用原生的插入数据方法DbSet.ADD()和 DbSet.AddRange()都很慢。所以要做大型的批量插入只能另选它法。
using EF6._0Test.EF; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace EF6._0Test { class Program { static void Main(string[] args) { using (Jason_TestEntities db = new Jason_TestEntities()) { List<wolf_example> list = new List<wolf_example>(); for (int i = 0; i < 50000; i++) { list.Add(new wolf_example() { type = i, Name = "Name" + i.ToString(), Money = i, CTime = DateTime.Now, UserID = i, Remak = "Remak" + i.ToString(), Sex = i, IsShow = true, }); } Stopwatch watch = Stopwatch.StartNew(); db.BulkInsert(list); db.BulkSaveChanges(); watch.Stop(); Console.WriteLine(string.Format("{0} 条数据, 用时 {1} milliseconds.", list.Count(), watch.ElapsedMilliseconds)); Console.ReadLine(); } } } }
EF批量插入数据(Z.EntityFramework.Extensions)
标签:use linq style i++ collect top color iss one
原文地址:http://www.cnblogs.com/lgxlsm/p/7844833.html