How to stop auto increment of a integer property??
I want to insert the value manually in asp.net mvc...
Stop auto increment in mvc
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Santhakumar MunuswamyRank #128 · 17.3K reputationPosted Jun 3, 2015, 10:33 AM EDT
Manoj BhoirRank #599 · 4K reputationPosted Jun 3, 2015, 9:00 PM EDT
EF Code-First uses conventions to beautifully create identity field for us when defining int primary keys. However, there are times that we don't want the database generate the primary key values for us. Here are two ways to avoid Code-First set identity fields on int primary keys.
Using data annotation:
public class Customer{
public int CustomerID { get; set; }
}
Using fluent API:
protected override void OnModelCreating(DbModelBuilder modelBuilder)().Property(c => c.CustomerID).HasDatabaseGeneratedOption(null);
{
modelBuilder.Entity
base.OnModelCreating(modelBuilder);
}