Sreekanth Reddy

Sreekanth Reddy

  • 353
  • 4.9k
  • 423.3k

Primary Key for model in code first approach

Nov 21 2014 8:27 AM
Hai friends, I am doing code first approach:
Here is my model class:
public class RegUsers1
{
[KEY]  //but not coming. Its assigning 0 to Uid & throwing unable to save 
public int Uid { set; get; }
public string FullName { set; get; }
public string Email { set; get; }
public string Password { set; get; }
public string Gender { set; get; }
public string Qualification { set; get; }
}
 
For this class How to set primary key to Uid? I have used the [KEY] attribute. But I am unable to trace it is throwing an error by assigning 0 to uid while inserting. Is there any other option to [KEY]? Simply my question is how to set primary key to Uid in code first approach? Thank you

Answers (2)