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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:21:40+00:00 2026-05-27T18:21:40+00:00

In .NET Entity Framework, what is the best way to have a (custom) join

  • 0

In .NET Entity Framework, what is the best way to have a (custom) join table with extra attributes (other than ids) and/or associate this join table with others via separate model? In Ruby on Rails we can have a model for the join table, like:

Item.rb (model)
:has_many => :buyers, :through=>:invoice
...

Buyers.rb (model)
:has_many => :items, :through=>:invoice
...

Invoice.rb (model)
:belongs_to :item
:belongs_to :buyer
....

Then we can use: Item.first.buyers, Buyers.first.items and Buyer.create(:items=>Item.create(:name=>'random')) etc. just like when we use automated join table without model (using has_and_belongs_to_many).

In Visual Studio 2010’s “Add Association” dialog, if we select multiplicity as *(Many) there is no option to select a join table (with model). Is there a way to do it manually?

  • 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-27T18:21:41+00:00Added an answer on May 27, 2026 at 6:21 pm

    Yes, you can get something pretty close. I’m not quite sure how to set this up in the designer since I only work with codefirst.

    Here’s an example:

    Student -> StudentFloor <- Floor

    public class Student
    {
        public int Id { get; set; }
        // ... properties ...
    
        // Navigation property to your link table
        public virtual ICollection<StudentFloor> StudentFloors { get; set; }
    
        // If you wanted to have a property direct to the floors, just add this:
        public IEnumerable<Floor> Floors
        {
            get
            {
                return StudentFloors.Select(ft => ft.Floor);
            }
        }
    }
    

    The linking table:

    public class StudentFloor
    {
        #region Composite Keys
    
        // Be sure to set the column order and key attributes.
        // Convention will link them to the navigation properties
        // below.  The database table will be created with a
        // compound key.
    
        [Key, Column(Order = 0)]
        public int StudentId { get; set; }
    
        [Key, Column(Order = 1)]
        public int FloorId { get; set; }
    
        #endregion
    
        // Here's the custom data stored in the link table
    
        [Required, StringLength(30)]
        public string Room { get; set; }
    
        [Required]
        public DateTime Checkin { get; set; }
    
        // Navigation properties to the outer tables
        [Required]
        public virtual Student Student { get; set; }
    
        [Required]
        public virtual Floor Floor { get; set; }
    
    }
    

    Finally, the other side of the many-to-many:

    public class Floor
    {
        public int Id { get; set; }
        // ... Other properties.
    
        public virtual ICollection<StudentFloor> StudentFloors { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the best way to learn data access in .net? The Entity Framework
The .NET Entity framework is giving me the following error: The table/view 'Foo.dbo.vwFoo' does
In the ADO.Net Entity Framework, I have an object which has 4 references to
I use ADO.NET Entity-Framework, I have a page that is data-bound to an entity
I have an app using the ADO.NET entity framework (the VS2008 version, not the
I am getting started with the ADO.NET Entity Framework 4.0. I have created an
General Info: ASP.NET MVC app using ADO.NET Entity Framework SQL Server 2005 I have
What is the best way to manually generate Primary Keys in Entity Framework 4.1
I have built an ASP.NET MVC web application that uses Entity Framework. To provide
I have a ASP.NET MVC 3 application, using Entity Framework 4 to handle Data

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.