ILYAS PATEL
ILYAS PATEL

Reputation: 278

In MVC Scaffolding using EF Crud operation why required primary key for input

I made DB and Attach with Data entity Model in that I have table name Employee and primary key EMPID which autoincrement. And then I am adding Scaffolding Insert Update Delete automatic using entity framework.

So it always shows to enter EMPId also which is primary key and autoincrement too.

 public partial class ProductCategory 
{
    public int ProductId { get; set; } 
    public string ProductName { get; set; } 
    public string ProductDescription { get; set; }
    public string ProductPrice { get; set; } 
    public Nullable<int> CategoryId { get; set; }
    public virtual Category Category { get; set; } 
} 

This is my model class which automatic created by EF –

Upvotes: 1

Views: 205

Answers (1)

Komal
Komal

Reputation: 71

Add this attributes on your primary key

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

Upvotes: 1

Related Questions