Exemple #1
0
        private static void Main(string[] args)
        {
            using (var db = new BlogContext())
            {
                var id = Convert.ToInt32(Math.Round((DateTimeOffset.UtcNow - new DateTimeOffset(2001, 1, 1, 0, 0, 0, TimeSpan.Zero)).TotalSeconds));

                var b = db.Tickets.Add(new Ticket { Id = id, Name = "Another Blog" });

                db.Posts.Add(new Post { Title = string.Format("[{0}] Another Post", DateTimeOffset.UtcNow.ToString("o")), Content = "Another Post", Ticket = b });

                db.SaveChanges();

                foreach (var ticket in db.Tickets.OrderBy(t => t.Id))
                {
                    Console.WriteLine("{0}: {1}", ticket.Id, ticket.Name);

                    if (ticket.Posts != null)
                    {
                        foreach (var post in ticket.Posts)
                        {
                            Console.WriteLine("   === {0}", post.Title);
                        }
                    }
                }
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            using (var db = new BlogContext())
            {
                db.Blogs.Add(new Blog { Name = "Another Blog " });
                db.SaveChanges();

                foreach (var blog in db.Blogs)
                {
                    Console.WriteLine(blog.Name);
                }
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            // Recreate database on change
            Database.SetInitializer<BlogContext>(new DropCreateDatabaseIfModelChanges<BlogContext>());

            using (var db = new BlogContext())
            {
                db.Blogs.Add(new Blog { Name = "Another Blog ", Test = "Hejhej"});
                db.SaveChanges();

                foreach (var blog in db.Blogs)
                {
                    Console.WriteLine(blog.Name);
                }
            }

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Exemple #4
0
        static void Main(string[] args)
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion <BlogContext, Configuration>());  //This checks for latest version anytime we migrate

            using (var db = new BlogContext())
            {
                db.Blogs.Add(new Blog {
                    Name = "Another Blog "
                });
                db.SaveChanges();

                foreach (var blog in db.Blogs)
                {
                    Console.WriteLine(blog.Name);
                }
            }

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Exemple #5
0
        static void Main(string[] args)
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion <BlogContext, Configuration>());
            ///  https://msdn.microsoft.com/en-us/data/jj591621
            using (var db = new BlogContext())
            {
                db.Blogs.Add(new Blog {
                    Name = "Another Blog ", Url = "s"
                });
                db.SaveChanges();

                foreach (var blog in db.Blogs)
                {
                    Console.WriteLine(blog.Name);
                }
            }

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }