Reputation: 11
Problems: Previously i called the function below.
ArchiveDeletedPatient.ID = 18
_archiveDB2.patient.Add(ArchiveDeletedPatient);
_archiveDB2.SaveChanges();
Afterward I deleted all records from patient database(delete from patient), now in my database it is empty. I called the above function again, however this time it auto increment ID to 19 and inserted into the database. I spamed the above functions and it kept incrementing. How to remove such function?? I don't need the auto increment.
Some might say it is because of database setting. I tried manually insert using Microsoft SQL Server Management Studio 17 "INSERT INTO PATIENT TABLE VALUES(18, ...). It allowed me to insert and when there is such ID in the table. It will not auto increment and will just prompt me a error. How can i remove such auto incrementing feature in c# linq.
Upvotes: 0
Views: 1543
Reputation: 2446
The auto incrementing is not the feature of Linq. It's the feature of Database. Here are complete instructions to remove auto increment from MS SQLServer:
Here it is...
Note:
If you're using Entity Framework and specifying your field with [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
remove this annotation
or
replace it with [DatabaseGenerated(DatabaseGeneratedOption.None)]
.
Upvotes: 0
Reputation: 61
Auto increment feature is not of linq c#. See the table properties and can you edit the pk to remove "identity" for remove autoincrement o add "identity". If identity is activated in bbdd, the id is calculated in database and linq return this into your entity.
Upvotes: 1