title: Entity Framework Code First : Setting up One-To-One foreign key association using Annotations
body: <p>I have following two Entities that I am trying to relate (one to one) using foreign key associations.</p>
  
  <pre><code>public class StandardRack {
      public int Id {get;set}
      public StandardRelay StandardRelay {get;set} 
  }
  
  public class StandardRelay {
      public int Id {get;set} 
  
      public int StandardRack_Id {get;set;}
      [Required][ForeignKey("StandardRack_Id")]
      public StandardRack StandardRack { get; set; }
  }
  </code></pre>
  
  <p>This throws ModelValidationException. Any ideas why such a seemingly simple one-to-one bidirectional relationship cannot be configured.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Here is the Exception:</p>
  
  <blockquote>
    <p>System.Data.Entity.ModelConfiguration.ModelValidationException was caught
          Message=One or more validation errors were detected during model generation:</p>
    
    <p>System.Data.Edm.EdmAssociationEnd: : Multiplicity is not valid in Role 'StandardRelay_StandardRack_Source' in relationship 'StandardRelay_StandardRack'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be �*�.</p>
    
    <p>Source=EntityFramework
          StackTrace:
               at System.Data.Entity.ModelConfiguration.Edm.EdmModelExtensions.ValidateAndSerializeCsdl(EdmModel model, XmlWriter writer)
               at System.Data.Entity.ModelConfiguration.Edm.EdmModelExtensions.ValidateCsdl(EdmModel model)
               at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
               at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
               at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
               at System.Data.Entity.Internal.RetryLazy<code>2.GetValue(TInput input)
               at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
               at System.Data.Entity.Internal.InternalContext.Initialize()
               at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
               at System.Data.Entity.Internal.Linq.InternalSet</code>1.Initialize()
               at System.Data.Entity.Internal.Linq.InternalSet<code>1.GetEnumerator()
               at System.Data.Entity.Infrastructure.DbQuery</code>1.System.Collections.Generic.IEnumerable.GetEnumerator()
               at System.Collections.Generic.List<code>1..ctor(IEnumerable</code>1 collection)
               at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
               at TestApplication.MainWindow.Window_Loaded(Object sender, RoutedEventArgs e) in D:\RailwayProjects\RelayAnalysis\TestApplication\MainWindow.xaml.cs:line 33
          InnerException: </p>
  </blockquote>