如何制作一个结合StudentProfileID和DateToday的自定义RegNo?
StudentProfileID - 是在创建方法上自动生成的主键
今日日期- 格式:031415
创建方法的示例代码
public ActionResult Create([Bind(Include="StudentProfileID,RegNo,EnrollmentDate,LastName,FirstName,MiddleName,Address,ContactNo,MaritalStatus,Birthdate,Birthplace,Age,PositionRank,Years,PRC,SBOOK,MMAP,PPORT,SRC,TraineeType,EndorsedBy,EmergencyPerson,EmergencyAddress,EmergencyContactNo,EmergencyRelationship")] StudentProfile studentprofile)
{
if (ModelState.IsValid)
{
db.StudentProfile.Add(studentprofile);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(studentprofile);
}
我按照这篇文章创建了学生档案http://www.codeproject.com/Tips/869986/CRUD-operation-with-Entity-Framework-Code-First
我将不胜感激。谢谢。
在 db.savechanges() 之后;我们将得到 sudentProfileId,如下所示
if (ModelState.IsValid)
{
db.StudentProfile.Add(studentprofile);
db.SaveChanges();
int studentId = studentprofile.StudentId;
string custRegNo = studetId.toString()+ DateTime.Now;
return RedirectToAction("Index");
}