title: ASP.NET MVC / EF - Manually assign an ID (PK)
body: <p>Whenver I try to insert a new row into my table manually, I get the following error:</p>
  
  <pre><code>Cannot insert the value NULL into column 'VehicleID', table 'TestServer.Vehicles'; column does not allow nulls. INSERT fails.
  The statement has been terminated.
  </code></pre>
  
  <p>Even tho I have set the VehicleID in my code, like so: </p>
  
  <pre><code>List&lt;Vehicles&gt; vehicleList = context.Vehicles.ToList();
  
  if(vehicleList.Count == 0)
  {
       vehicle.VehicleID = 1;
  }
  else 
  {
       vehicle.VehicleID = vehicleList.Last().VehicleID + 1;
  }
  
  context.Vehicles.Add(vehicle);
  context.SaveChanges();
  
  // Other code...
  </code></pre>
  
  <p>The reason I need to do this is because in this Action, I am actually updating another Model, but I also want to update my Vehicle model, based on the other model im updating</p>
  
  <p>My VehicleID property has the [Key] data annotation set, could this be a reason why?</p>