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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:02:01+00:00 2026-06-09T02:02:01+00:00

Given I have two entities: Deputy and DeputyProfile : public class Deputy : IdableEntity

  • 0

Given I have two entities: Deputy and DeputyProfile:

public class Deputy : IdableEntity
{
    [Required]
    public string FirstName { get; set; }

    public string Patronimic { get; set; }

    [Required]
    public string LastName { get; set; }
}

public class DeputyProfile : IdableEntity
{
    [Required]
    public string Dosieur { get; set; }
}

is the best way to establish a one-to-one relationship between them is by placing navigation property from DeputyProfile to Deputy (childe to parent) or visa-verse?

Should it be like this?:

public class DeputyProfile : IdableEntity
{
    [Required]
    public virtual Deputy Deputy{ get; set; }

    [Required]
    public string Dosieur { get; set; }
}

What is the logical rule based on which it is best to make that decision?

P.S. Being a child of IdableEntity gives a class its own Guid Id field.

  • 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-09T02:02:04+00:00Added an answer on June 9, 2026 at 2:02 am

    You must choose a Principal (parent) end and a Dependent (child) side for any relation. You are free to choose whichever you like best. To me the Deputy seems the clear Principal as it is likely to have many more relations as your model grows.

    A one to one relation is implemented by a shared primary key; the DeputyProfile must have as its primary key the Deputy ID. That will make your code like this:

    public class Deputy
    {
    
       public int ID {get;set;}
    
       public int ProfileID {get;set;}
       public virtual DeputyProfile Profile {get;set;}
    
        [Required]
        public string FirstName { get; set; }
    
        public string Patronimic { get; set; }
    
        [Required]
        public string LastName { get; set; }
    }
    
    public class DeputyProfile
    {
        public int DeputyID {get;set}
        public virtual Deputy Deputy {get;set}
    
        [Required]
        public string Dosieur { get; set; }
    }
    

    Note: As it is implemented now every Deputy must have a profile. If the profile is optional make the ProfileID an ‘int?’.

    I can heartily recommend this excellent series of blogs about implementing relations in the Entity Framework 4.1 and higher

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

Sidebar

Related Questions

Given I have a class with two constructors: public class TestClass { ObjectOne o1;
I have two entities: Event and Comment. @Entity @Table(name = events) public class Event
Given I have two File objects I can think of the following implementation: public
I have two entities Room.php /** * @ORM\Table(name=room) * @ORM\Entity(repositoryClass=Ahsio\StackBundle\Repository\RoomRepository) */ class Room {
Consider the following Entities. public class Product{ int id; Date effectiveDate; Date expiryDate; Set<Inventory>
i have two entities Customer and Order (trivial setters and getters excluded) @Entity public
I have three entities as follows: public class EntityA { private Long id; //Getters
I have two divs one inside another. I have given some border to both
I have two table masterTbl and detailTbl which structure is given below... --PRIMARY TABLE
Given that two branches have diverged and a specific commit from one branch (and

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.