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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:53:52+00:00 2026-06-05T18:53:52+00:00

I am using EntityFramework 4.1. I have the following model: public class User {

  • 0

I am using EntityFramework 4.1.

I have the following model:

public class User 
{
   [Key]
   public int Id { get; set; }
   public string Username { get; set; } 
   public string Password { get; set; }

   public virtual User Creator { get; set; }
   public virtual User LastEditor { get; set; }
}

When I try to generate my database I got this error:

Unable to determine the principal end of an association between the
types ‘User’ and ‘User’. The principal end of this association must be
explicitly configured using either the relationship fluent API or data
annotations.

But I also have this class:

public class Course 
{
   [Key]
   public int Id { get; set; }
   public string Name { get; set; } 

   public virtual User Creator { get; set; }
   public virtual User LastEditor { get; set; }
}

And it works ok, I have these foreign keys generated:

Creator_Id
LastEditor_Id

Do I have anything to add in my User model to make it works?

  • 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-05T18:53:53+00:00Added an answer on June 5, 2026 at 6:53 pm

    EF tries – by convention – to create a one-to-one relationship between User.Creator and User.LastEditor because they both refer to the User class where they are themselves located in. That’s not the case for the Course class. For Course.Creator and Course.LastEditor EF creates two one-to-many relationships to the User. To achieve the same for the properties in User you will have to configure the relationships with Fluent API:

    modelBuilder.Entity<User>()
        .HasOptional(u => u.Creator)     // or HasRequired
        .WithMany();
    
    modelBuilder.Entity<User>()
        .HasOptional(u => u.LastEditor)  // or HasRequired
        .WithMany();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a code-first methodology. I have created my own user model and
I am using MVC3 with Entity Framework Code First. I have the following model.
I have a search repository for EntityFramework 4.0 using LinqKit with the following search
I have the following problem. I am using Entity Framework to connect to a
Trying to map the following schema using the Entity Framework. A Customer can have
I have an EntityFramework model which has a boolean field. To make the mapping
I have an employee class in model for ASP.NET MVC3. There is a field
I'm using Entity Framework and I have created an interface for lease transactions: public
I have the following Entity Framework model: It's a very simple model and was
Hi guys I have to model the following situation. I came up with 2

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.