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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:50:34+00:00 2026-06-18T23:50:34+00:00

the sample code on http://msdn.microsoft.com/en-US/data/jj591620#RequiredToRequired is it even correct? the code is asking for

  • 0

the sample code on http://msdn.microsoft.com/en-US/data/jj591620#RequiredToRequired is it even correct? the code is asking for OfficeAssignment prop on the Instructor class. it will not resolve for obvious reasons. what is the correct way of having a one-to-one relationship on ef now?

// Configure the primary key for the OfficeAssignment
modelBuilder.Entity<OfficeAssignment>()
.HasKey(t => t.InstructorID);

modelBuilder.Entity<Instructor>()
.HasRequired(t => t.OfficeAssignment)
.WithRequiredPrincipal(t => t.Instructor);


public class OfficeAssignment
{
    // Specifying InstructorID as a primary
    [Key()]
     public Int32 InstructorID { get; set; }

    public string Location { get; set; }

    // When the Entity Framework sees Timestamp attribute
    // it configures ConcurrencyCheck and DatabaseGeneratedPattern=Computed.
    [Timestamp]
    public Byte[] Timestamp { get; set; }

    // Navigation property
    public virtual Instructor Instructor { get; set; }
}

public class Instructor
{
   public Instructor()
   {
        this.Courses = new List<Course>();
   }

    // Primary key
    public int InstructorID { get; set; }
    public string LastName { get; set; }
    public string FirstName { get; set; }
    public System.DateTime HireDate { get; set; }

    // Navigation properties
    public virtual ICollection<Course> Courses { get; private 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-18T23:50:36+00:00Added an answer on June 18, 2026 at 11:50 pm

    There is mistake around the Local/office nav property. A few deliberate renames to clarify
    Perhaps this….

    using System;
    using System.Collections.Generic;
    using System.Data.Entity;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace one2one
    {
    class Program
    {
        static void Main(string[] args)
        {
            var context = new Demo();
            var instructor = new Instructor();
            instructor.FirstName = "Big";
            instructor.LastName = "Willi";
            context.Set<Instructor>().Add(instructor);
    
            var office = new OfficeAssignment();
            office.Location = "is this where the demo broke down ? See POCO ";
            office.InstructorUsingThisOffice = instructor;
    
            context.Set<OfficeAssignment>().Add(office);
    
            context.SaveChanges();
        }
    }
    public class OfficeAssignment
    {
        // Specifying InstructorID as a primary
        public Int32 InstructorID { get; set; }
        public string Location { get; set; }
    
        // Navigation property
        public virtual Instructor InstructorUsingThisOffice { get; set; }
    }
    
    public class Instructor
    {
    
        // Primary key
        public int InstructorID { get; set; }
        public string LastName { get; set; }
        public string FirstName { get; set; }
       //navigation
        //missing
        public virtual OfficeAssignment TheofficeToUse { get; set; }
    
    }
    public class Demo : DbContext
    {
    
    
        DbSet<OfficeAssignment> officeAssignments { get; set; }
        DbSet<Instructor> Instructors { get; set; }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            // Configure the primary key for the OfficeAssignment
            modelBuilder.Entity<OfficeAssignment>()
            .HasKey(t => t.InstructorID);
    
            modelBuilder.Entity<Instructor>()
                        .HasRequired(t => t.TheofficeToUse)
                        .WithRequiredPrincipal(d => d.InstructorUsingThisOffice);  //current entity is principal, the navigation back.
           // and we share the same key... MUST with EF 1:1 foreign key
    
    
        }
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this code sample from here.. http://msdn.microsoft.com/en-us/data/gg685489 [HttpPost] public ActionResult Edit(int id,
I am pretty much following the example on this MSDN page: http://code.msdn.microsoft.com/Imoprt-Data-from-Excel-to-705ecfcd with 1
I am following sample code on implementing MVVM in Silverlight (see: http://msdn.microsoft.com/en-us/magazine/dd458800.aspx ). On
The code sample How to: Define Event Accessor Methods at http://msdn.microsoft.com/en-us/library/dw1dtw0d.aspx appears to mutate
From this sample code from MSDN http://msdn.microsoft.com/en-us/library/system.string.gethashcode.aspx The hash code for abc is: 536991770
Tell me please, why this sample code doesn't work on ASP.NET MVC? http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.onselectedindexchanged.aspx Thank
I downloaded a sample code from here: http://gallery.expression.microsoft.com/ShowHideWithFlip Now my problem is that i'm
I want to understand the example from msdn ( http://msdn.microsoft.com/en-us/library/ms742521.aspx#defining_simple_datatemplate ). XAML Code: <ListBox
Here is the link to the sample code http://developer.apple.com/library/ios/#samplecode/MVCNetworking/Introduction/Intro.html Below is the code snippet
I got some sample code from the net here: http://www.javadb.com/sending-a-post-request-with-parameters-from-a-java-class That works fine. It

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.