title: EF6 and MVC5: Using two fields as a combined key
body: <p>I have several objects (Product, Rule, PriceDetail, etc.) that manage and store information in a CRUD application.  I want a way to keep a log of when the data is updated, and to that end I've created an Update class, referenced as <code>ICollection&lt;Update&gt; Updates</code> within each data class.</p>
  
  <p>When the tables are all generated, EF creates a FK for each class in the Updates table (Product_ID, Rule_ID, etc.).  This seems horribly inefficient.  Could I use a two-field key, such as <code>enum ObjectType</code> and <code>long ID</code>?  Alternately, can I use <code>string ID</code> and force a pattern where the first N characters of the string identify the referencing object?  If the latter, can the database auto-increment the string value?</p>
  
  <p>Here's some example code, trimmed for placement here:</p>
  
  <pre><code>public class Update
  {
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public long ID { get; set; }
      public string Reason { get; set; }
      public DateTime TimeOfUpdate { get; set; }
      public long Product_ID { get; set; }
      public long Rule_ID { get; set; }
  }
  
  public class Product
  {
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public long ID { get; set; }
      public string Name { get; set; }
      public PriceDetail Price { get; set; }
      public ICollection&lt;Update&gt; Updates { get; set; }
  }
  
  public class Rule
  {
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public long ID { get; set; }
      public string Name { get; set; }
      public ICollection&lt;Condition&gt; Conditions { get; set; }
      public ICollection&lt;Update&gt; Updates { get; set; }
  }
  </code></pre>