Jobs 表与 JobDates 表具有 PK/FK 1-1 关系。 如何更改“创建作业”后调用,以便还为具有 JobID 的 JobDates 表生成新行(提交期间未知,因为它尚不存在)
public async Task<RedirectToPageResult> OnPost()
{
var Job = new Job()
{
JobNum = AddJobRequest.JobNum,
CustomerId = AddJobRequest.CustomerId,
JobName = AddJobRequest.JobName,
JobDescription = AddJobRequest.JobDescription,
JobType = AddJobRequest.JobType,
JobStatusId = AddJobRequest.JobStatus,
JobPM = AddJobRequest.JobPM,
JobSM = AddJobRequest.JobSM,
JobQty = AddJobRequest.JobQty
};
_context.Jobs.Add(Job);
await _context.SaveChangesAsync();
CustomerList = await _context.Customers.ToListAsync();
return new RedirectToPageResult("/Index");
}
我已经查找了所有其他示例,也许我没有正确地措辞来找到答案。我觉得这一定是很常规的事情。
想通了。
public async Task<RedirectToPageResult> OnPost()
{
var Job = new Job()
{
JobNum = AddJobRequest.JobNum,
CustomerId = AddJobRequest.CustomerId,
JobName = AddJobRequest.JobName,
JobDescription = AddJobRequest.JobDescription,
JobType = AddJobRequest.JobType,
JobStatusId = AddJobRequest.JobStatus,
JobPM = AddJobRequest.JobPM,
JobSM = AddJobRequest.JobSM,
JobQty = AddJobRequest.JobQty,
**JobDate = new JobDate()**
};
_context.Jobs.Add(Job);
await _context.SaveChangesAsync();
CustomerList = await _context.Customers.ToListAsync();
return new RedirectToPageResult("/Index");
}