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

  • Home
  • SEARCH
  • 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 7162769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:47:22+00:00 2026-05-28T13:47:22+00:00

I have a situation where I would like to create a 1-to-1 relationship in

  • 0

I have a situation where I would like to create a 1-to-1 relationship in Entity Framework (4.2) using code first fluent configuration API, the twist is that I need to use a link/map table to do it.

Here is a diagram of my table layout.

1-to-1 relationship with link table

This is what I am after …

HasOptional(x => x.FieldPerson)
    .WithOptionalPrincipal()
    .Map(map =>
             {
                 map.ToTable("user_account__field_person");
                 map.MapLeftKey("user_account_id");
                 map.MapRightKey("field_person_id");
             });

… but there doesn’t seem to be a way to do it.

The alternative is to create my 3 entities and manage them myself using joins where appropriate.

Is this even possible or is it a scenario that EF fluent API doesn’t handle?

  • 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-28T13:47:24+00:00Added an answer on May 28, 2026 at 1:47 pm

    I’m going to answer my own question again!

    I don’t think EF code first deals with this situation because the whole concept of a link/map table suggests a many-to-many relationship.

    For my particular case this is a database-first situation and I “have” to deal with these tables as I cannot change the database as this stage.

    What I’ve done is use a Many-to-Many code first configuration …

    HasMany(t=>t.FieldPersons)
        .WithMany(t=>t.UserAccounts)
        .Map(map =>
                 {
                     map.ToTable("user_account__field_person");
                     map.MapLeftKey("user_account_id");
                     map.MapRightKey("field_person_id");
                 });
    

    … as there is nothing in my database schema to prevent me from creating a many to many relationship. If I did want that behaviour then I would simply need to add a unique constraint on each field (which EF code first doesn’t support anyway)

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

Sidebar

Related Questions

I'm trying to map an existing database using Entity Framework Code First Fluent API.
I have a situation where I would like to dynamically create an object through
I'm using Devise on my application and would like to create a global API
I have a situation in which the ideal relationship, I believe, would involve Value
I would like create a service to do something when some hot situation occurs,
My situation: I would like to create a hobby project for improving my C++
I have had several situations when i would like to do that. This could
How would I setup my controls for the following situation?: I have a parent-container
I am curious how others would handle this situation. I have a domain layer
Here is the situation, I have UIViewController class with a UITableView outlet. I would

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.