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

后端 未结 3 1706
盖世英雄少女心
盖世英雄少女心 2020-12-17 08:11

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.

3条回答
  •  清酒与你
    2020-12-17 08:35

    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.

提交回复
热议问题