Entity framework code first does not create many-to-many database table

Viewed 1487

I have code first model like shown below. Application creates table 'VideoPosts', and does not create 'ImagePosts'. Is there a problem with CoverImage and TileImage navigation properties, or am I missing something? I want to have a table for images just like table for videos.

public class Post
    {

        public int PostID { get; set; }

        [ForeignKey("TileImageID")]
        public Image TileImage { get; set; }
        [Column("TileImageID")]
        public int? TileImageID { get; set; }
        [ForeignKey("TileImageID")]
        public Image CoverImage { get; set; }
        [Column("CoverImageID")]
        public int? CoverImageID { get; set; }

        public virtual ICollection<Image> Gallery { get; set; }
        public virtual ICollection<Video> VideoGallery { get; set; }
    }

    public class Video
    {
        public int VideoID { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        [Required]
        public string Url { get; set; }
        public virtual ICollection<Post> Posts { get; set; }
    }

    public class Image
    {
        public int ImageID { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        [Required]
        public string Path { get; set; }

        public virtual ICollection<Post> Posts { get; set; }
    }

Database created

4 Answers
Related