2

What I want to do is to create a primary key that has auto decrement:

Id BIGINT PRIMARY KEY IDENTITY(-1,-1)

I searched for it and I could only find the following DataAnnotation for setting the Identity:

[DatabaseGenerated(DatabaseGeneratedOption.Identity)]

But this not fullfill my need of setting start and increment values. And if I want to increment by 1, and starting from 1 actually the following that I always use works for me:

    [Key]
    public long Id { get; set; }
Ashkan Mobayen Khiabani
  • 33,575
  • 33
  • 102
  • 171

1 Answers1

0

Hi You can achieve this output by using the database initialization or migration

There is no direct way to implement this in Code First. So, for using any of these options, you need to

customize the DB initialization: This is done by implementing your own database initializer class and execute the desired SQL commands from the Seed methods (look for the implementation of public class MyInitializer in the linked article)

or to customize a migration: you can execute any SQL Command in the Up() or Down() method of your migration

Source: https://stackoverflow.com/a/23964887/3397630

Kindly look at the above url , the asker commented that ,By using above technique could be able to solve the problem. so hope it will be useful for you too.

Thanks

Karthik

Karthik Elumalai
  • 1,574
  • 1
  • 11
  • 12