How to stop auto increment of a integer property??
I want to insert the value manually in asp.net mvc...
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Manoj BhoirPosted Jun 4, 2015, 1:00 AM
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);
}
Santhakumar MunuswamyPosted Jun 3, 2015, 2:33 PM