예제 #1
0
            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();
            }
예제 #2
0
        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());
        }
예제 #3
0
 protected override void Seed(DbContext context)
 {
     context.AddRange(Customers);
     context.SaveChanges();
 }