Exemple #1
0
        private static void InsertUsers(int count)
        {
            Random r = new Random();
            Stopwatch stopwatch = new Stopwatch();

            List<Tag> tags = new List<Tag>();
            for (int i = 0; i < 10000; i++)
            {
                tags.Add(new Tag()
                {
                    Name = "tag" + i
                });
            }

            stopwatch.Start();

            SessionState.db.Database.BulkInsert("Tags", tags);

            stopwatch.Stop();
            Console.WriteLine("10k Tags Inserted for: {0}", stopwatch.Elapsed);
            tags.Clear();
            tags.AddRange(SessionState.db.Tags.ToList());

            List<Bookmark> bookmarks = new List<Bookmark>();

            List<User> users = new List<User>();
            for (int i = 0; i < count; i++)
            {
                User user = new User();
                user.Username = "******" + i;
                users.Add(user);
            }

            stopwatch.Start();

            SessionState.db.Database.BulkInsert("Users", users);

            stopwatch.Stop();
            Console.WriteLine("30k Users Inserted for: {0}", stopwatch.Elapsed);

            users.Clear();
            users.AddRange(SessionState.db.Users.ToList());

            users.ForEach(user =>
            {
                for (int i = 0; i < 7; i++)
                {
                    Bookmark bookmark = new Bookmark();
                    bookmark.Title = "title" + i;
                    bookmark.URL = "http://www.google.com/" + i;
                    bookmark.UserId = user.UserId;

                    bookmarks.Add(bookmark);
                }
            });

            stopwatch.Start();

            SessionState.db.Database.BulkInsert("Bookmarks", bookmarks);

            stopwatch.Stop();
            Console.WriteLine("210k bookmarks Inserted for: {0}", stopwatch.Elapsed);

            bookmarks.Clear();
            bookmarks.AddRange(SessionState.db.Bookmarks.ToList());

            List<BookmarksInTags> bookmarksInTagses = new List<BookmarksInTags>();
            bookmarks.ForEach(bookmark =>
            {
                for (int k = 0; k < 10; k++)
                {
                    bookmarksInTagses.Add(new BookmarksInTags()
                    {
                        BookmarkId =  bookmark.BookmarkId,
                        TagId = tags[k].TagId
                    });
                }
            });

            stopwatch.Start();

            SessionState.db.Database.BulkInsert("BookmarksInTags", bookmarksInTagses);

            stopwatch.Stop();
            Console.WriteLine("2100k bookmarksInTagses Inserted for: {0}", stopwatch.Elapsed);
        }
Exemple #2
0
        private static void AddBookmark(string username, string title, string url, string tags, string notes)
        {
            var b = new Bookmark();

            var user = SessionState.db.Users.FirstOrDefault(u => u.Username == username);
            if (user == null)
            {
                user = new User();
                user.Username = username;
                SessionState.db.Users.Add(user);
            }
            b.User = user;
            b.Title = title;
            //b.Title.Split(' ').ToList().ForEach(t =>
            //{
            //    ParseTags(t.Trim(), b);
            //});
            b.URL = url;

            //tags
            if (!string.IsNullOrEmpty(tags))
            {
                tags.Split(',').ToList().ForEach(t =>
                {
                    ParseTags(t.Trim(), b);
                });
            }

            b.Notes = notes;
            SessionState.db.Bookmarks.Add(b);
            SessionState.db.SaveChanges();
        }