Using Entity Framework Code First CTP5, how do I create a primary key column that are INTs and are not identity columns

ajma picture ajma · Feb 15, 2011 · Viewed 18.5k times · Source

Using Entity Framework Code First CTP5, how do I create a primary key column that are INTs and are not identity columns

Preferably not using attributes.

Answer

Jay Querido picture Jay Querido · May 13, 2011

That answer didn't work for me (in EF 4.1).

To make this work, I added DatabaseGenerated attribute to my key column:

public class FacebookUser
{
  [Key]
  [DatabaseGenerated(DatabaseGeneratedOption.None)]
  public long FacebookId { get; set; }

  // ...
}

Hope this helps someone.