Advertisement
vlad0

Untitled

Jul 24th, 2013
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Bookmarks.Data;
  7. using System.Diagnostics;
  8.  
  9. namespace BulkGenerator
  10. {
  11.     class Program
  12.     {
  13.  
  14.        
  15.         static void Main(string[] args)
  16.         {
  17.             Stopwatch myTimer = new Stopwatch();
  18.             myTimer.Start();
  19.             InsertUsers(30000);
  20.             myTimer.Stop();
  21.             Console.WriteLine(myTimer.Elapsed);
  22.            
  23.        
  24.         }
  25.  
  26.         private static void InsertUsers(int count)
  27.         {
  28.             var context = new BookmarksEntities();
  29.             context.Configuration.AutoDetectChangesEnabled = false;
  30.             context.Configuration.ValidateOnSaveEnabled = false;
  31.             var initialCount = context.Users.Count();
  32.  
  33.             for (int i = initialCount + 1; i < initialCount + count; i++)
  34.             {
  35.                 User newUser = new User { Username = "User" + i };
  36.                 context.Users.Add(newUser);
  37.  
  38.                 if (i % 100 == 0)
  39.                 {
  40.                     context.SaveChanges();
  41.                 }
  42.             }
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement