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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:11:24+00:00 2026-06-09T19:11:24+00:00

I want a straightforward foreign key relationship between two entities, with EF properties going

  • 0

I want a straightforward foreign key relationship between two entities, with EF properties going both ways. However, at the moment EF is generating 2 foreign keys representing each direction of the relationship. How can I make EF treat them as a single property? The below generates two database foreign key constraints named Script_ScriptRuns and ScriptRun_Script, using foreign key field Script_Id and Script_Id1 respectively

public class Script
{
    [Key]
    public Guid Id { get; set; }

    public virtual ICollection<ScriptRun> ScriptRuns { get; set; }
}


public class ScriptRun
{
    [Key]
    public Guid Id { get; set; }

    [Required]
    public virtual Script Script { get; set; }
}
  • 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-09T19:11:25+00:00Added an answer on June 9, 2026 at 7:11 pm

    Using the code you posted, it only created a single FK for me – Script_Id in the ScriptRun class.

    Are you simply wanting to rename the FK that’s getting created in that class? You can do that by mapping the column in your DbContext. This would map it to ScriptId:

            modelBuilder.Entity<Script>()
                .HasMany(s => s.ScriptRuns)
                .WithRequired(sc => sc.Script)
                .Map(x => x.MapKey("ScriptId"));
    

    If not, can you post your entire model?

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

Sidebar

Related Questions

What I want to do is pretty straightforward. I have a site powered by
It's very straightforward, but I can't find the answer online. I want to do
I want to use the System.ComponentModel.DataAnnotations assembly to validate arguments (mapped to properties) for
I want to make an web application (platform) that does pretty straightforward stuff: Users
Well, the question seems very straightforward, but it isn't. I want to set a
I want to make use of Castle.Facilities.Logging.dll, however getting the latest version from the
My goal is pretty straightforward: I want to generate an HTML table with the
Pretty straightforward, but I just want to know which is faster. I think simply
It's fairly straightforward. I want to set focus to the first enabled and not
I'm trying to retrieve the Manager (or Model) for a Django foreign key. This

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.