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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:11:31+00:00 2026-05-27T12:11:31+00:00

I know that Code-First uses conventions for model binding, and that this is the

  • 0

I know that Code-First uses conventions for model binding, and that this is the list of conventions that are available (and active?) by default.

It seems that the selection of the junction table name for Many-to-Many relationships is a little bit random..

Which of the referenced conventions is used to determine the junction table name? What is the algorithm used to determine that name?

  • 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-27T12:11:32+00:00Added an answer on May 27, 2026 at 12:11 pm

    I think, the general rule for the many-to-many join table name is

    ClassNameOfLeftEntity + PluralizedClassNameOfRightEntity

    So, if the first entity is User and the second is Role the join table name is UserRoles.

    It is possible that this can be influenced by removing the PluralizingTableNameConvention but i am not sure.

    The bigger problem is to determine what is the “left” and what the “right” entity. I think it depends on almost random factors, like the order which EF builds the model in which in turn depends on navigation properties between entities and the order in which you have written the DbSets in your derived context. For this reason it is strongly recommended to define the join table name explicitely with Fluent API. A small change in your model or changing the order of the sets in your context can EF let think the name must be RoleUsers instead of the former UserRoles.

    Here is a reference to a similar answer.

    Edit

    Another reason to define the many-to-many mapping always explicitely with Fluent API (not that much related to the table name question but more to the question what should be the left and what the right entity) is performance.

    The join table has a compound primary key and a clustered index on that key (at least in SQL Server). Now assume the table name would be RoleUsers and the left entity is Role and the right entity is User because perhaps some developer decided to sort the sets alphabetically in the context:

    public DbSet<Role> Roles { get; set; }
    public DbSet<User> Users { get; set; }
    

    The join table entries would look like this:

    RoleId    UserId
    ----------------
    1         1
    1         2
    2         1
    2         2
    3         1
    3         2
    

    Now, possibly the majority of queries in your application are interested in getting the roles for a given user. But you are not often or never interested to get all users for a given role. The roles of a given user could be queried by an Include:

    var user = context.Users.Include(u => u.Roles).Single(u => u.UserId == 1);
    

    This would create a JOIN in SQL on the UserId in the join table: ON Users.UserId = RoleUsers.UserId. This join cannot use the index in the join table but instead results in a table scan to retrieve row 1, 3 and 5 in the table for the user’s RoleIds.

    Better for performance of queries like this is to have the User as the left entity and the Role as the right entity, resulting in a clustered index for the pair (UserId, RoleId) which is better for performance of such queries. (You could of course create a second index in the example above to improve the performance.) To achieve this you must specify the mapping with Fluent API.

    So, it makes sense to choose the left and right entity wisely and to not leave this decision to EF.

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

Sidebar

Related Questions

It seems that the Code First DbContext really uses the given ConnectionString during compile?
I have code that uses jquery.slideup and jquery.slidedown How can i know that div
In code: //I know that to get this effect (being able to use it
I just declared some code-first models for a new project that uses EntityFramework. public
I know that c++ code should be compiled and linked by g++, not gcc.
I know that GUI code in Java Swing must be put inside SwingUtilities.invokeAndWait or
You know that particular part of your code that is essential for the project
I know that the following code should show and hide a tiny circular progress
We all know that commenting our code is an important part of coding style
If you are familiar with TopCoder you know that your source-code gets a final

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.