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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:39:45+00:00 2026-06-11T04:39:45+00:00

I have a simple Entry class model public class Entry { public int Id

  • 0

I have a simple Entry class model

public class Entry
{
    public int Id { get; set; }
    public DateTime Modified { get; set; }
    public DateTime Created { get; set; }

    // Related entries
    public virtual ICollection<Entry> RelatedEntries { get; set; }

    // The nodes this entry contains
    public virtual ICollection<Node> Nodes { get; set; }

    // The category this entry is located in
    public virtual Category Category { get; set; }
}

I want my entry to be able to have a list of related entries, the problem is it just adds a FK Entry_id to the Entries table, I want to create a new table, which holds a many to many relationship, for example

Entry_Id | Related_Entry_Id
      01 | 02
      01 | 03
      01 | 06
      02 | 04

So that would make entry 01 related to 02, 03 and 06, and entry 02 with 04.

  • 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-11T04:39:47+00:00Added an answer on June 11, 2026 at 4:39 am

    You can specify with Fluent API that the relationship is of type many-to-many (and not a one-to-many relationship which EF assumes by default):

    public class MyContext : DbContext
    {
        //...
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Entry>()
                .HasMany(e => e.RelatedEntries)
                .WithMany()
                .Map(m =>
                {
                    m.MapLeftKey("Entry_Id");
                    m.MapRightKey("Related_Entry_Id");
                    m.ToTable("EntryRelations");
                });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this simple model: class Tag(models.Model): title = models.SlugField() created = models.datetime def
Consider this simple Model and ViewModel scenario: public class SomeModel { public virtual Company
I am currently using sorl-thumbnail and have a model. class Entry(models.Model): image = ImageWithThumbnailsField(upload_to='uploads/',
I have a Rails 3 simple scaffolded application having one model like that: class
I have a simple database table called Entries: class CreateEntries < ActiveRecord::Migration def self.up
I have a simple PostSharp logging attribute: [Serializable] public class MethodLoggingAttribute : OnMethodBoundaryAspect {
I have a simple model entity, called entry with one field content and on
I have a simple model that is defined as: class Article(models.Model): slug = models.SlugField(max_length=50,
It seems simple, in my model I have: class CustomerAccount < ActiveRecord::Base acts_as_url :name
I have a very simple entry form. After a button is pressed, I need

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.