如何在 C# MVC5 中将 StudentProfileID 和 Date Today 组合为 Create 方法上的 customID

How to combine StudentProfileID and Date Today as a customID on Create Method in C# MVC5

如何结合 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");
        }