Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6977633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:39:03+00:00 2026-05-27T17:39:03+00:00

I am working on a project in ASP.NET MVC using EF4 Code-First for the

  • 0

I am working on a project in ASP.NET MVC using EF4 Code-First for the modeling. I have the following model classes:

public class ComicBook
{
    public long ComicBookID { get; set; }
    public string IssueTitle { get; set; }
    public int IssueNumber { get; set; }
    public DateTime PublishDate { get; set; }

    public IList<ComicBookPerson> Writers { get; set; }
    public IList<ComicBookPerson> Pencillers { get; set; }

    public IList<User> CollectingUsers { get; set; }
}

public class ComicBookPerson
{
    public long ComicBookPersonID { get; set; }
    public string Name { get; set; }

    public IList<ComicBook> WorkedOnComicBooks { get; set; }
}

public class User
{
    [Key]
    public long UserID { get; set; }
    public string Email { get; set; }

    public IList<ComicBook> CollectedBooks { get; set; }
}

And the following DbContext:

public class ComicContext : DbContext
{
    public DbSet<ComicBook> ComicBooks { get; set; }
    public DbSet<ComicBookPerson> ComicBookPerson { get; set; }
    public DbSet<User> Users { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<ComicBook>()
            .HasMany(b => b.Writers)
            .WithMany(w => w.WorkedOnComicBooks)
            .Map(t => t.MapLeftKey("ComicBookID")
                .MapRightKey("WriterID")
                .ToTable("ComicBook_Writers"));

        modelBuilder.Entity<ComicBook>()
            .HasMany(b => b.Pencillers)
            .WithMany(p => p.WorkedOnComicBooks)
            .Map(t => t.MapLeftKey("ComicBookID")
                .MapRightKey("PencillerID")
                .ToTable("ComicBook_Penciller"));
    }
}

The rules that need to apply are:

  • Users can have many ComicBooks in their collection
  • ComicBooks can be in many users’ collections
  • Each ComicBook can have 1 or more Writers
  • Each ComicBook can have 1 or more Pencillers
  • A ComicBookPerson can be a Writer or a Penciller on any book
  • A ComicBookPerson can work on many books, as a Writer, Penciller, or both

The many-to-many schema between Users and ComicBooks is created fine. It is the many-to-many between ComicBooks and ComicBookPersons that is breaking. The error message I get is:

Schema specified is not valid. Errors: 
(15,6) : error 0040: Type ComicBook_Writers is not defined in namespace Comics.Models (Alias=Self).

I basically want two join tables, one called ComicBook_Writers and one called ComicBookPencillers. Both tables will contain a ComicBookID and a ComicBookPersonID. Is this possible in EF Code First?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:39:04+00:00Added an answer on May 27, 2026 at 5:39 pm

    You need two collection properties in ComicBookPerson class that relates to writers and pencillers.

    public class ComicBookPerson
    {
        public long ComicBookPersonID { get; set; }
        public string Name { get; set; }
    
        public IList<ComicBook> WroteComicBooks { get; set; }
        public IList<ComicBook> PenciledComicBooks { get; set; }
    }
    

    Model mapped as

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<ComicBook>()
            .HasMany(b => b.Writers)
            .WithMany(w => w.WroteComicBooks)
            .Map(t => t.MapLeftKey("ComicBookID")
                .MapRightKey("WriterID")
                .ToTable("ComicBook_Writers"));
    
        modelBuilder.Entity<ComicBook>()
            .HasMany(b => b.Pencillers)
            .WithMany(p => p.PenciledComicBooks)
            .Map(t => t.MapLeftKey("ComicBookID")
                .MapRightKey("PencillerID")
                .ToTable("ComicBook_Penciller"));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on asp.net MVC 3 project. I am using EF 4.1 code
I'm working on a Web project using Asp.Net MVC, which I'll have to deploy
background:Me and my coworkers are working on asp.net mvc project ... we have a
I'm working on an asp.net-mvc project. I have an Items table and a Tags
I am working on a ASP .NET mVC project & i have to change
I am using T4MVC in our ASP.NET MVC project. I have a statement like
I'm working on an ASP.NET MVC project using jQuery. I'm referencing the jQuery VSDoc
I am working a little project for myself using ASP.Net MVC 2 Preview 2
I am working on a project in ASP.NET MVC using C# 3.0. I am
I'm currently working on an ASP.NET MVC project using NHibernate and I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.