private static void CascadingInsert() { var db = new BlogDbContex(); var post = new Post { Title = "New Post Title Боби", Date = DateTime.Now, Body = "This post have comments and tags", User = db.Users.First(), Comments = new[] { new Comment { Text = "Comment 1", Date = DateTime.Now }, new Comment { Text = "Comment 2", Date = DateTime.Now, User = db.Users.First() } }, Tags = db.Tags.Take(3).ToList() }; db.Posts.Add(post); db.SaveChanges(); }
private static void CreateNewData() { var db = new BlogDbContex(); var post = new Post { Title = "New Title", Body = "New Post Body", Date = DateTime.Now }; db.Posts.Add(post); db.SaveChanges(); Console.WriteLine("Post #{0} created.", post.Id); }