There's two ways you can do this, either by adding to blog.Posts and having Entity Framework setup the foreign keys automatically:
Blog blog = new Blog
{
Name = name,
Posts = new List<Post>()
};
foreach (var item in posts)
{
Post p = new Post();
p.Title = item.Title;
p.Content = item.Content;
blog.Posts.Add(p);
}
db.Blogs.Add(blog);
db.SaveChanges();
or by adding to the Posts table directly:
// assuming you have a reference to the blog id in blogId
foreach (var item in posts)
{
Post p = new Post();
p.BlogId = blogId;
p.Title = item.Title;
p.Content = item.Content;
db.Posts.Add(p);
}
db.SaveChanges();
You can add as many items as you'd like, but then call SaveChanges() once, and it'll only make one trip to the database.