protected virtual void Seed(DbContext context) { context.Add(CreateBlogAndPosts <BlogAuto, PostAuto>()); context.AddRange(CreatePostsAndBlog <BlogAuto, PostAuto>()); context.Add(CreateBlogAndPosts <BlogFull, PostFull>()); context.AddRange(CreatePostsAndBlog <BlogFull, PostFull>()); context.Add(CreateBlogAndPosts <BlogFullExplicit, PostFullExplicit>()); context.AddRange(CreatePostsAndBlog <BlogFullExplicit, PostFullExplicit>()); if (context.Model.GetPropertyAccessMode() != PropertyAccessMode.Property) { context.Add(CreateBlogAndPosts <BlogReadOnly, PostReadOnly>()); context.AddRange(CreatePostsAndBlog <BlogReadOnly, PostReadOnly>()); context.Add(CreateBlogAndPosts <BlogReadOnlyExplicit, PostReadOnlyExplicit>()); context.AddRange(CreatePostsAndBlog <BlogReadOnlyExplicit, PostReadOnlyExplicit>()); context.Add(CreateBlogAndPosts <BlogWriteOnly, PostWriteOnly>()); context.AddRange(CreatePostsAndBlog <BlogWriteOnly, PostWriteOnly>()); context.Add(CreateBlogAndPosts <BlogWriteOnlyExplicit, PostWriteOnlyExplicit>()); context.AddRange(CreatePostsAndBlog <BlogWriteOnlyExplicit, PostWriteOnlyExplicit>()); context.Add(CreateBlogAndPosts <BlogFields, PostFields>()); context.AddRange(CreatePostsAndBlog <BlogFields, PostFields>()); } context.SaveChanges(); }
private static Genre[] CreateTestGenres(int numberOfGenres, int numberOfAlbums, DbContext context) { var artist = new Artist { Name = "Artist1" }; var genres = Enumerable.Range(1, numberOfGenres).Select( g => new Genre { Name = "Genre " + g, Albums = Enumerable.Range(1, numberOfAlbums).Select( n => new Album { Artist = artist, Title = "Greatest Hits" }).ToList() }).ToList(); context.AddRange(genres); context.SaveChanges(); return(genres.ToArray()); }
protected override void Seed(DbContext context) { context.AddRange(Customers); context.SaveChanges(); }