When creating a new database entry, how would I get the primary key, in this instance, called DocumentId
as it is created and store it under another variable.
Here is my code to create the new database entry, the RevisionId
is showing up as 0
because it cannot find the DocumentId
, the primary key that is automatically incremented each time a new entry is entered. How do I get the number from the DocumentId
?
if (ModelState.IsValid)
{
documentUps.RevisionId = documentUps.DocumentId; //PROBLEM HERE SHOWS 0
documentUps.Username = User.Identity.Name;
documentUps.Attachment = file.FileName;
documentUps.creationDate = DateTime.Now;
documentUps.ActivationDate = DateTime.Now;
documentUps.RevisionNumber = 0;
documentUps.Status = StatusChoice.Draft;
db.DocumentUps.Add(documentUps);
db.SaveChanges();
return RedirectToAction("Index");
}