How to set starting value for an Identity primary key in Entity Framework code first?

.net c# code-first entity-framework-6 sql-server

Question

I'm making the in my project theAppointments table initially by writing Entity Framework code. When I set my main integer key,AppointmentNo as [Key] and [Required] the table is created with a primary key that initially starts with 1.

The appointment numbers should begin at 1000, please. SQL Server is the database I use. Please assist me. I want to say thank you.

[DataContract]
public class Appointment
{
    [DataMember]
    [Key]
    [Required]
    public int AppointmentNo { get; set; }

    [DataMember]
    [Required]
    public string DoctorUN { get; set; }

    [DataMember]
    [Required]
    public string PatientUN { get; set; }
}
1
0
9/17/2018 7:11:22 PM

Accepted Answer

Ef annotations make it impossible, but you can still use the migration UP method to run SQL.

Sql("DBCC CHECKIDENT ('Appointment', RESEED, 1000)");
2
9/17/2018 7:28:54 PM

Popular Answer

Code First will by convention setup the primary key as an identity column as long as the type of the primary key attribute is numeric or GUID.

from:Identity and EF columns



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow