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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:11:13+00:00 2026-06-02T15:11:13+00:00

Some advice on how to even properly describe these relationships would be a great

  • 0

Some advice on how to even properly describe these relationships would be a great start. Something accurately described is a problem looking for a solution. I have entities User and Login, where Login describes basically a login session for one user. So, User normally has many Login instances. This relationship is only described on the Login side with a required, single User navigation property, and there is an implied, but not declared, Login collection on the User side.

Then, for the other relationship, a User is created under authorization of a Login, so this relationship is described on the User side, with a Login navigation property, and there is an implied, but not User collection on the Login side.

I don’t do much DB modelling outside of using the DB tools, and they always just get relationships right for me, but now, I have to map these relationships for code first, using fluent mapping. How do I described these two relationships, what are the principle and dependent sides, and what are the multiplicities here?

  • 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-02T15:11:14+00:00Added an answer on June 2, 2026 at 3:11 pm

    Code First tries to link up the two sides of what are probably the same relationship. When you instead have two different unidirectional relationships, then you need to tell Code First this by explicitly telling Code First that the inverse navigation property does not exist using WithMany() with no arguments:

    public class User
    {
        public int Id { get; set; }
        public int LoginId { get; set; }
        public virtual Login Login { get; set; }
    }
    
    public class Login
    {
        public int Id { get; set; }
        public int UserId { get; set; }
        public virtual User User { get; set; }
    }
    
    public class SomeContext : DbContext
    {
        public DbSet<User> Users { get; set; }
        public DbSet<Login> Logins{ get; set; }
    
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<User>()
                .HasRequired(e => e.Login)
                .WithMany()
                .HasForeignKey(e => e.LoginId);
    
            modelBuilder.Entity<Login>()
                .HasRequired(e => e.User)
                .WithMany()
                .HasForeignKey(e => e.UserId);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

after some advice regarding a problem i am getting using a linux based piece
I would really like some advice here, to give some background info I am
I am looking for some advice in regards to getting a very quick display
I need some LINQ advice (or even general advice) on how to implement the
I’m looking for some advice. I recently wrapped up a project where I inherited
I am looking for some advice on an idea which i am unsure if
just looking for some advice, pointers, and suggestions for further reading. I have: 1
Just looking for some advice on this one, what exactly is a loading screen
I'm looking for some advice for a table structure in sql. Basically I will
Hi I'm looking for some advice I currently own a resseller package with Heart

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.