title: Entity Framework auto generated Id if not set
body: <p>Using EF Code First, I want to insert an entity with auto generated ID <strong>only if</strong> I haven't set its ID.</p>
  
  <p>Here is the entity I want to insert :</p>
  
  <pre><code>public class ElementEntity
  {
      [DatabaseGenerated(DatabaseGeneratedOption.None)]
      public int Id { get; set; }
  
      public int Property1{ get; set; }
      public string Property2{ get; set; }
  }
  </code></pre>
  
  <p>and the function used to insert the data : </p>
  
  <pre><code>public static void AddEntity(int id, int prop1, string prop2)
      {
          db.Contents.Add(new ElementEntity
          {
              Id = id,
              Property1 = prop1,
              Property2 = prop2
          });
          db.SaveChanges();
      }
  </code></pre>
  
  <p>I'd like to have the same function but without the id parameter. If I use a such function, the Id is set to 0 automatically and an exception is thrown.</p>
  
  <p>Does Entity Framework Code Fisrt allow mix generation Id behavior?</p>