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); } } } } }
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); } } }
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(); }