title: Web API Null Navigation Property
body: <p>I am getting an error when I try to expand a navigation property of an object in my model.</p>
  
  <pre><code>eg. /odata/Products?$expand=ProductDetails
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>No NavigationLink factory was found for the navigation property 'ProductDetails' from entity type 'ProductModels.Models.Product' on entity set 'Products'. Try calling HasNavigationPropertyLink on the EntitySetConfiguration.
  </code></pre>
  
  <p>Parameter name: navigationProperty</p>
  
  <p>My model looks like this:</p>
  
  <pre><code>public class Person
  {
      public int Id { get; set; }
  
      public string Name { get; set; }
      [ForeignKey("Name")]
      public PersonDetails PersonDetails { get; set; }
  }
  
  public class PersonDetails
  {
      [Key]
      public string FullName { get; set; }
  
      public int Age { get; set; }
  
  }
  </code></pre>
  
  <p>It is a one to zero/one relationship and you can see that my model is a bit odd in that PersonDetails is linked to Person by Person.Name = PersonDetails.FullName but Entity Framework 6 does handle it and generates the SQL like the following:</p>
  
  <pre><code>SELECT 
  [Extent1].[Id] AS [Id], 
  N'f4243347-5b4c-4790-a07d-e8beb80bea72' AS [C1], 
  [Extent1].[Name] AS [Name], 
  N'PersonDetails' AS [C2], 
  N'f4243347-5b4c-4790-a07d-e8beb80bea72' AS [C3], 
  [Extent2].[FullName] AS [FullName], 
  [Extent2].[Age] AS [Age], 
  CASE WHEN ([Extent1].[Name] IS NULL) THEN cast(1 as bit) ELSE cast(0 as bit) END AS [C4]
  FROM  [Persons] AS [Extent1]
  LEFT OUTER JOIN [PersonDetails] AS [Extent2] ON [Extent1].[Name] = [Extent2].[FullName]
  </code></pre>
  
  <p>And in the results, many of the ProductDetails records are null, which is ok.</p>
  
  <p>But it seems like the OData Formatter has a problem with it where Person.Name is null. I have the following set in my ProductsContext:</p>
  
  <pre><code>public System.Data.Entity.DbSet&lt;Product&gt; Products { get; set;
  </code></pre>
  
  <p>And this ODataConventionModelBuilder:</p>
  
  <pre><code>builder.EntitySet&lt;Vehicle&gt;("Products");
  </code></pre>
  
  <p>I don't have a controller for ProductDetails because I don't want to access it directly, only through the Products controller.</p>
  
  <p>If I add in a:</p>
  
  <pre><code>builder.EntitySet&lt;Vehicle&gt;("ProductDetails");
  </code></pre>
  
  <p>Then I get a:</p>
  
  <pre><code>The EDM instance of type '[ProductModels.Models.ProductDetails Nullable=True]' is missing the property 'FullName'.
  </code></pre>
  
  <p>Which makes sense because FullName may well be null on that ProductDetails record.</p>
  
  <p>The only way forward I can see is to use HasNavigationPropertyLink instead of building the ProductDetails the standard way as above.</p>
  
  <p>Can anyone give me any advice on what I should do?</p>