Esempio n. 1
0
 private static void SetupDatabase()
 {
     using (var db = new BloggingContext())
     {
         db.Database.EnsureDeleted();
         db.Database.EnsureCreated();
     }
 }
Esempio n. 2
0
        private static void SetupDatabase()
        {
            using (var db = new BloggingContext())
            {
                Console.WriteLine("Recreating database from current model");
                Console.WriteLine(" Dropping database...");
                db.Database.EnsureDeleted();

                Console.WriteLine(" Creating database...");
                db.Database.EnsureCreated();
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            SetupDatabase();

            using (var db = new BloggingContext())
            {
                var blog = new Blog();
                blog.Name = "Rowan's Blog";
                blog.SetUrl("http://romiller.com");

                db.Blogs.Add(blog);
                db.SaveChanges();

                var blogs = db.Blogs
                    .OrderBy(b => b.Url)
                    .ToList();
            }
        }