我如何结合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");
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句