Ejemplo n.º 1
0
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            // Override the name of the table because of a RC2 change
            builder.Entity <Posts>().ToTable("Posts");
            builder.Entity <Tags>().ToTable("Tags");
            builder.Entity <Categories>().ToTable("Categories");
            builder.Entity <PostsInCategories>().ToTable("PostsInCategories");
            builder.Entity <TagsInPosts>().ToTable("TagsInPosts");
            builder.Entity <Comments>().ToTable("Comments");
            builder.Entity <StoreApp>().ToTable("StoreApp");
            builder.Entity <StoreCategories>().ToTable("StoreCategories");

            var typesToRegister = typeof(ApplicationDbContext).GetTypeInfo().Assembly.GetTypes()
                                  .Where(type => !string.IsNullOrEmpty(type.Namespace))
                                  .Where(type => type.FullName.Contains("OneBlog.Data.Mapping"));

            foreach (var type in typesToRegister)
            {
                IEntityMapping mapping = (IEntityMapping)Activator.CreateInstance(type);
                mapping.Execute(builder);
            }
        }