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 5975953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:09:32+00:00 2026-05-22T21:09:32+00:00

Scenario I have a model that has the following setup: A member can be

  • 0

Scenario

I have a model that has the following setup:

A member can be member of multiple memberlists. A memberlist can have multiple members. I also defined that a memberlist can have a seperate set of optional members. Basically I have a double n-m relationship between member and memberlist. What’s more, a memberlist is always owned by a member, the one person that created the memberlist that is.

Problem

Entity framework code-first is unable to map this relationship correctly eventhough I tell it how to map the relationships. I get the following error when I try to use the DbContext the first time

Schema specified is not valid. Errors: 
(32,6) : error 0040: Type MemberList_Members is not defined in namespace NerdCooking.Models (Alias=Self).
(33,6) : error 0040: Type MemberList_OptionalMembers is not defined in namespace NerdCooking.Models (Alias=Self).

What I have tried

The first attempt to use the model in the scenario fails, because it’s clear EF doesn’t know how to map the n-m relationships. So I told the framework explicitly how to fix the situation.

// Map the relation between members of a memberlist and the memberlist
// to a Membership table
modelBuilder.Entity<MemberList>().HasMany(memberList => memberList.Members)
    .WithMany(member => member.MemberLists)
    .Map(mapping => mapping.MapLeftKey("MemberId")
        .MapRightKey("MemberListId").ToTable("Membership"));

// Map the relation between optional members of a memberlist and the memberlist
// to a separate table
modelBuilder.Entity<MemberList>().HasMany(memberList => memberList.OptionalMembers)
    .WithMany(member => member.MemberLists)
    .Map(mapping => mapping.MapLeftKey("MemberId")
        .MapRightKey("MemberListId").ToTable("OptionalMembership"));

// Map the relationship between the owner and the memberlist
modelBuilder.Entity<MemberList>().HasRequired(memberList => memberList.Owner)
    .WithMany(member => member.MemberLists).WillCascadeOnDelete(true);

My question

Is this scenario possible with Entity framework 4.1 code-first? And if so, what’s the best way to fix the mapping issue I’m experiencing?

I can always change the model so that it features a Membership entity that links a member to a memberlist. It makes the whole thing a bit more explicit and I can then add a property to that entity to mark it as optional.

I think however that this is a scenario that should have worked, so I hope someone did this before and knows what the trick is to get it working correctly.

  • 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-22T21:09:33+00:00Added an answer on May 22, 2026 at 9:09 pm

    All your mappings contain .WithMany(member => member.MemberLists). That is incorrect. You need separate navigation property for each relation = you can use each navigation property only for one relation mapping.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Anyone have any ideas on a good way to model the following scenario in
Scenario: I have a text file that has pipe (as in the | character)
Todays cause of hair loss has been the following scenario: I have a service
In this simplified scenario, I have a model called Post Each post has a
I have a model College that has a show action in its controller. So
In this scenario, I have 2 or more models: class Store(models.Model): name = models.CharField(max_length
Beginner level question Scenario: Have simple string cocantation tool, that I might expand later
Scenario: You have an ASP.Net webpage that should display the next image in a
Scenario: I have a console application that needs to access a network share with
We have the following data model: CalendarAppointment 1 <------> * AppointmentRole * <--------> 1

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.