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

  • SEARCH
  • Home
  • 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 8446577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:58:19+00:00 2026-06-10T09:58:19+00:00

I have these two classes set up and I want Entity Framework to automatically

  • 0

I have these two classes set up and I want Entity Framework to automatically create the resulting many-to-many relationship tables for set of entities.

public class User {
    public int Id { get; set; }

    public ICollection<Event> SignedUpEvents { get; set; }
    public ICollection<Event> CompletedEvents { get; set; }
}

and

public class Event {
    public int Id { get; set; }

    public ICollection<User> SignedUpUsers { get; set; }
    public ICollection<User> CompletedUsers { get; set; }
}

This does nothing. My guess is that since there are two relationships specified and both have the same entity-types involved EF can’t distinguish the two.

Is there a way to make this happen? Maybe some DataAnnotation to name the resulting tables or something?

  • 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-06-10T09:58:21+00:00Added an answer on June 10, 2026 at 9:58 am

    Yeah the issue is as you say that it has two collections of ‘Event’s.

    You can set up dual navigation properties using DataAnnotations however my personal preference is to use the model builder. This keeps your poco classes clean and avoids unnecessary references.

    I wrote a tutorial on how to use the model builder and how EF navigation properties work which i recommend reading as it goes int much more depth.

    From a simple point of view you want something like the following:

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                modelBuilder.Entity<User>().HasMany(e => e.SignedUpEvents)
                    .WithMany(e => e.SignedUpUsers);            
                modelBuilder.Entity<User>().HasMany(e => e.CompletedEvents)
                    .WithMany(e => e.CompletedUsers);
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes created by Entity Framework based off tables in my db
I have two tables in my database which have a one-to-one relationship. I want
I'm using ASP.NET MVC 3 with Entity Framework CodeFirst I have two classes as
I have these two classes public class Person { } public class Company {
Let's say we have these two classes: public class Base { public static int
All -- I have these two methods in one of my classes: public static
I have two classes that I would like to merge into a composite. These
Say I have two classes: Supplier, and Account. These classes are connected via has_one
I have these two tables people ============ id, name and answer_sheets ============ id, person_id,
I have two classes: public class TestClass1 { public int TestInt { get; set;

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.