DatabaseGeneratedOption.Identity not generating an Id

asp.net-mvc c# entity-framework

Accepted Answer

ZZZ_tmp
11
2/25/2014 11:07:02 PM

Popular Answer

  1. You missed theKey attribute. and using is not necessary.virtual for the main key.
  2. Slauma noted that you can't useIdentity string datatype

Attempt this code:

public class Foo
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }

    public virtual string Name { get; set; }
}


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow