title: EF Core composite primary key with nulls
body: <p>Just wondering if this is possible: I have a table from an existing database I can not modify. I am only interested in viewing the data. I will not be updating the table.</p>
  
  <p>There is no primary key. There are two keys that when combined would make the row unique. Unfortunately both of these columns allow, and have null values.</p>
  
  <p>I tried:</p>
  
  <pre><code> modelBuilder.Entity&lt;IesHrEmployee&gt;(entity =&gt; {
                  entity.HasKey(o =&gt; new { o.PERS_NO, o.POS_NO });
                  entity.ToTable("IES_HR_EMPLOYEES", "DBO");
              });
  </code></pre>
  
  <p>Unfortunately in my repository</p>
  
  <pre><code>public class IesHrEmployeesRepository : IIesHrEmployeesRepository
  {
          private DataContext context;
  
          public IesHrEmployeesRepository(DataContext ctx) =&gt; context = ctx;
  
          public IEnumerable&lt;IesHrEmployee&gt; IesHrEmployees =&gt; context.IesHrEmployees.ToArray();
  }
  </code></pre>
  
  <p>on the <code>toArray</code> call, I get this error:</p>
  
  <blockquote>
    <p>Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]<br>
    Executed action UserNavigator.Controllers.IesHrController.Index (UserNavigator) in 139.9397ms fail:<br>
    Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]</p>
    
    <p>An unhandled exception has occurred while executing the request. System.Data.SqlTypes.SqlNullValueException: Data is Null. This method or property cannot be called on Null values.    </p>
    
    <p>at System.Data.SqlClient.SqlBuffer.get_String()<br>
    at System.Data.SqlClient.SqlDataReader.GetString(Int32 i)  </p>
  </blockquote>