sql server - Writing AutoIncrement for primary key in CodeFirst -
i using codefirst in project. 1 of things learning how can design tables first writing classes. question - how can classify primary key [key] id, auto increment field. when record created (or row in table) primary key auto generated. how do in codefirst while writing class definition. help.
public class newtable { //looking [autoincrement][key] id field etc... [key] public int id { get; set; } [required(errormessage = "title required")] [displayname("title")] public string title { get; set; } }
a string
auto increment? that's not gonna work.
use int
instead, , pk identity
column default. don't need [key]
attribute either; ef infer because property called id
.
Comments
Post a Comment