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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:01:38+00:00 2026-06-14T08:01:38+00:00

I have a User and an Organization class. They look like this public class

  • 0

I have a User and an Organization class. They look like this

public class User
{
        public int UserId { get; set; }
        public string UserName { get; set; }
        public string Email { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public virtual ICollection<Organization> Organizations { get; set; }
}

public class Organization : EntityBase
{
    public string Name { get; set; }
    public string Description { get; set; }
    public virtual ICollection<User> Users { get; set; }
}

And both inherit from an EntityBase class to get common fields like Id and created/updated tracking.

public abstract class EntityBase
{
    public int Id { get; set; }
    public DateTime Created { get; set; }
    public virtual User CreatedBy { get; set; }
    public DateTime Updated { get; set; }
    public virtual User UpdatedBy { get; set; }
}

As denoted by the ICollection properties on both, there should be a many-to-many relation. However when my database is autogenerated I get incorrect foreign keys added to my tables
Incorrect mapping of Organization and User tables

If I change the CreatedBy and UpdatedBy to be strings instead of User properties I get a join table, which is what I was looking for.
Correct database generation

Is this a matter of Entity Framework simply being confused and I need to supply many-to-many configuration in the using fluent mappings, or have I done something wrong?

  • 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-14T08:01:39+00:00Added an answer on June 14, 2026 at 8:01 am

    If you have multiple relationships you need to configure them manually by fluent API or using attributes,

    Note:If you have multiple relationships between the same types (for
    example, suppose you define the Person and Book classes, where the
    Person class contains the ReviewedBooks and AuthoredBooks navigation
    properties and the Book class contains the Author and Reviewer
    navigation properties) you need to manually configure the
    relationships by using Data Annotations or the fluent API

    Here is the article from Microsoft.

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

Sidebar

Related Questions

I have this relationship : class Organization < ActiveRecord::Base has_many :users end class User
I have the following class structure: class Organization { string Name; List<User> users; List<Organization>
I have 2 django models like this: class UserProfile(models.Model): user = models.OneToOneField(User) organisation =
I have these models: class UserProfile(models.Model): user = models.OneToOneField(User) #etc class Organization(models.Model): users =
I have a many-to-many relationship like this: A user has_many organizations through affiliations and
I have a model 'Organization' which has following fields class Organization(models.Model): members = models.ManyToManyField(User,related_name='org_members')
I have got this model: class User < ActiveRecord::Base has_and_belongs_to_many :roles before_destroy do |u|
I have 3 beans: Organization, Role, User Role - Organization relation - @ManyToOne Role
I have a user table and an organization table. When you sign up for
I have the following entities: User Company Organization Users need to be able to

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.