title: Entity Framework: Wrong values in columns with allowed nulls in table without primary key
body: <p>Even though some will argue that <em>"if it doesn't have a primary key, it's not a table"</em>, sometimes You have to accept the requirements of customer. </p>
  
  <p>I have a table without primary keys and I use Entity framework Code first from existing database to access data. Entity framework has generated a model and set [Key] and [Column] annotation to all NOT NULL columns. Here is a simplified situation with 3 mandatory (NOT NULL) and one optional (NULL) column:</p>
  
  <pre><code>    [Key]
      [Column(Order = 0)]
      public int Manadatory1 { get; set; }
  
      public string Optional { get; set; }
  
      [Key]
      [Column(Order = 1)]
      public short Manadatory2 { get; set; }
  
      [Key]
      [Column(Order = 2)]
      public string Manadatory3 { get; set; }
  </code></pre>
  
  <p>When I have two rows in the table, where there is the only difference in the "Optional" column, Entity framework returns the same value for both, because it considers them to be one, because the [Key] values are equal.</p>
  
  <p>I was not able to find any solution for this without changing anything in the database. I tried to change the configuration of the model and to set the optional column as a key, but it is not allowed to have NULL in the key.</p>
  
  <p>Is there any solution in entity framework for such a problem without making any change in the database?</p>
  
  <p><strong>EDIT:</strong>
  There are some similar questions in the StackOverflow, but there is the accepted question with changing the datamodel. The other solution would be not to use entity framework. The aim of this question is to find if such a way exists also using EF. </p>
  
  <p>Thank You very much,
  Tomáš</p>