Exemple #1
0
        public void CreateThread()
        {
            Database.SetInitializer(new DropCreateDatabaseIfModelChanges<ForumsContext>());
            using (var db = new ForumsContext())
            {
                // Create and save a new Thread
                var newThread = new Thread
                                    {
                                        Name = "Talk About stuff",
                                    };

                db.Threads.Add(newThread);
                db.SaveChanges();

                //// Display all Blogs from the database
                //var query = from b in db.Blogs
                //            orderby b.Name
                //            select b;

                //Console.WriteLine("All blogs in the database:");
                //foreach (var item in query)
                //{
                //    Console.WriteLine(item.Name);
                //}

                //Console.WriteLine("Press any key to exit...");
                //Console.ReadKey();
            }
        }
Exemple #2
0
        public void CreateUser()
        {
            Database.SetInitializer(new DropCreateDatabaseIfModelChanges<ForumsContext>());
            using (var db = new ForumsContext())
            {
                db.Users.Add(new ForumsUser()
                {
                    ForumsUserName = "******"
                }
                );
                db.SaveChanges();

            }
        }
Exemple #3
0
        public void CreatePostData()
        {
            Database.SetInitializer(new DropCreateDatabaseIfModelChanges<ForumsContext>());
            using (var db = new ForumsContext())
            {

                // Create and save a new Thread

                var query = from b in db.Threads
                            where b.ThreadId == 1
                            select b;

                var userQuery = db.Users.Find(1);

                db.Posts.Add(new ForumPost()
                                 {
                                     Content = "I like cheese" + DateTime.Now,
                                     Author = userQuery,
                                     Thread = query.First()
                                 }
                    );
                db.SaveChanges();
            }
        }