It doesn't seem to work. I am not sure what I'm missing I see the reference is generated but at the end its not inserted:
Random r = new Random(); string jobRef = r.Next(1000, 9999).ToString(); if (ModelState.IsValid) { Job model = new Job { Name = job.Name, JobNo = job.JobNo, Description = job.Description, Location = job.Location, CustomerId = job.CustomerId, JobCategoryId = job.JobCategoryId, CreatedDate = DateTime.Now, Reference = DateTime.Now.ToString("yyyyMM") + "-" + jobRef }; _context.Add(job); await _context.SaveChangesAsync(); return RedirectToAction(nameof(Inprogress)); }
Reference its a string on my model
public string Reference { get; set; }
https://stackoverflow.com/questions/67015350/i-want-to-generate-a-unique-reference-number-for-each-record-inserted-to-databas April 09, 2021 at 01:06PM
没有评论:
发表评论