private void Seed() { using (var context = new BlogPostsContext(_contextOptions)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); int count = 3; for (int i = 0; i < count; i++) { int id = i + 1; var blogPost = new BlogPost { PostId = id, Title = $"Title {id}", Body = $"Body {id}", Creator = $"Creator {id}", Dt = DateTime.Now }; context.Set <BlogPost>().Add(blogPost); } context.SaveChanges(); } }
public void Add(T entity) { _context.Set <T>().Add(entity); }