title: How to make EF not write property matching identity column when saving to DB?
body: <p>I've got an issue with SQLite and EntityFramework.
  My entity class has an Id property which maps to an identity column that is also the PK. When I insert a new entity model object to my DB via </p>
  
  <pre><code>_dbContext.Images.Add(imageEntity);
  _dbContext.SaveChanges();
  </code></pre>
  
  <p>then it will always insert the object with <strong>imageEntity.Id = 0</strong> because 0 is default for int. There is an attribute <strong>[NotMapped]</strong> which isn't what I need, it's for when you have an additional property in your entity class that doesn't exist in the table. Mine exists in the table, I just don't want to write it, the DB should take care of this.</p>
  
  <p>I would like to make EF behind the scenes to produce a statement like this:</p>
  
  <pre><code>insert into Images (Views, Rating) values (100, 5.5)
  </code></pre>
  
  <p>instead of this:</p>
  
  <pre><code>insert into Images (Id, Views, Rating) values (0, 100, 5.5)
  </code></pre>
  
  <p>Anybody an idea how to do this?</p>
  
  <p>Also the latter insert statement works (if there's no Id = 0 entry already), but why? Shouldn't an identity column always be protected from outside value insertion?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>As a workaround I've tried to let EF create a new entity model for me like this</p>
  
  <pre><code>var temp = _dbContext.Images.Create();
  </code></pre>
  
  <p>I thought maybe then I'll be able to replace everything except for the Id value and save it to the DB, but what I get is an object with <code>temp.Id = 0</code> again. I don't know if EF or SQLite is fooling me</p>