1
내가 가지고있는 문제를 설명하는 동안 나와 함께 숙여주십시오.새로운 기본 키를 생성하는 테이블 대신 현재 기본 키 자체를 업데이트하는 방법 Asp.net mvc
상점에서 설문지를 작성할 수있는 곳이 있습니다. 이 애플리케이션 내
난 두 테이블 이db.StoreAud(pk:AuditId) which contains all the stores information
db.storequests(pk:ReviewId) which holds the all questions information. AuditId is a foreign key in db.storequests table.
상점 데이터가 데이터베이스에 완벽하게 저장하는 설문지를 작성하는 경우 지금 여기에 문제가 그러나입니다입니다 동일한 상점에서 설문지를 다시 작성하면 db.storequests는 이전 행을 업데이트하는 대신 새 기본 키 값으로 데이터베이스에 새 행을 작성합니다.
는 두 번째 행의 데이터를 업데이트 할 내가 강조 표시된 행을 원하는, 자세한 내용은 아래의 이미지를 확인하시기 바랍니다.
질문 : 동일한 상점에서 동일한 설문지를 다시 작성하면 이전 행을 어떻게 업데이트 할 수 있습니까? 그 이후로 만들어지기를 바랍니다.
db.StoreAUD
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Key]
[Column(Order = 1)]
public int AuditId { get; set; }
public string Date { get; set; }
public int StoreNumber { get; set; }
public string StoreName { get; set; }
db.storequests
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Key]
public int ReviewId { get; set; }
public int AuditId { get; set; }
public int QuestionOne { get; set; }
public string QuestionTwo { get; set; }
public string QuestionThree { get; set; }
public string QuestionFour { get; set; }
제어기
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(StoreQuestions storequestions)
{
if (ModelState.IsValid)
{
StoreAudit findingAudit = db.StoreAudit.Find(storequestions.AuditId); // grabbing the id from th store audit table
findingAudit.ReadOnlyTickBox = true;
db.StoreQuestions.Add(storequestions);
db.SaveChanges();
return RedirectToAction("Details", "Audit", new { id = storequestions.AuditId });
}
return View(storequestions);
}
아래의 예제 예를 업데이트하거나 내가 대신 경우 storeaudit 테이블의 갱신을 시도하고 또한 그것 storequestions의 PK를 데이터베이스에 추가하고되고 찾아주세요 내가 의미하는 것을 보아라. – cedPound