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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:44:28+00:00 2026-05-26T11:44:28+00:00

I have been tasked with porting an old app to MVC 3, and want

  • 0

I have been tasked with porting an old app to MVC 3, and want to use EF’s code first to replicate its existing database schema. The current code base is littered with hard coded SQL commands, and so the model I come up with has to be “compatible” with what the current system expects. I know I could use EF’s Database First to do this, but the existing schema is so simple that I see no reason not to use code first, as I want a solid foundation to build on as we migrate away from our old hard-coded database interactions.

What I need the POCOs to look like:

public class Owner
{
    [Key]
    public Guid Owner_Id { get; set; }

    // Properties
    public string ContactName { get; set; }
    public string PhoneNumber { get; set; }
    public string Email { get; set; }

    // Navigational properties
    public virtual ICollection<Plant> Plants { get; set; }
}

public class Plant
{
    [Key]
    public Guid Plant_Id { get; set; }

    // Properties
    public string Address { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string Zip { get; set; }

    // Foreign Keys
    public Guid Owner_Id { get; set; }

    // Navigational properties
    public virtual Owner Owner { get; set; }
    public virtual License License { get; set; }
}

public class License
{
    [Key] public Guid License_Id { get; set; }

    // Properties
    public int Total { get; set; }
    public int Users { get; set; }
    public string Key { get; set; }

    // Foreign Keys
    public Guid Plant_Id { get; set; }

    // Navigational properties
    public virtual Plant Plant { get; set; }
}

It’s giving me this error on attempting to create the context:

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

I realize that Plant should have a nullable FK reference to a License_Id, and that License shouldn’t have a FK for Plant_Id. But these are the cards I have been dealt. Is what I’m trying to do possible in EF?

  • 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-26T11:44:28+00:00Added an answer on May 26, 2026 at 11:44 am
    public class Plant
    {
        public Guid PlantID { get; set; }
        public virtual License License { get; set; }
    } 
    
    public class License
    {
         // No need to have a PlantID foreign key since the foreign key.
         public Guid LicenseID { get; set; }
         public virtual Plant Plant { get; set; }
    }
    

    In fluent-api (in your context class):

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Plant>().HasOptional(p => p.License).WithRequired(l => l.Plant);  
    

    The only downgrade is that you actually defined one to zero or one. (which can be handled in code. but still…) For more info about One-to-One relationship please check out Entity Framework Code First One to One Relationship

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

Sidebar

Related Questions

I have been tasked with designing my web services client code to use the
I have been tasked with finding a good fit for a database to use
I have been tasked with porting a large Java codebase to the Android platform.
I've been tasked with porting/refactoring a Web Application Platform that we have from ASP.NET
I have a large codebase that I've been tasked with porting to 64 bits.
I have been tasked to replace the hardware an existing Apache/Tomcat/MySQL application is running.
I have been tasked with converting an old VB6 program to to C#. One
I've been tasked with the incremental porting of a legacy VB6 app (using MS
I have been tasked with making an existing Java program available via a web
I have been tasked with developing a solution that tracks changes to a database.

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.