Model view controller 如何为列表中的一个元素生成GUID<;T>;在MVC中?
我在模型中创建了一个类,它将是视图中显示的数据库表Model view controller 如何为列表中的一个元素生成GUID<;T>;在MVC中?,model-view-controller,guid,Model View Controller,Guid,我在模型中创建了一个类,它将是视图中显示的数据库表 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Runtime.InteropServices; namespace showtable.Models { public class Employee { public Guid EmployeeId { get;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.InteropServices;
namespace showtable.Models
{
public class Employee
{
public Guid EmployeeId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime hiredate { get; set; }
public decimal salary { get; set; }
}
}
现在我想为主键生成一个GUID,它是EmployeeId。
如何在我的控制器中写入它 您可以这样做:
public class Employee
{
public Guid EmployeeId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime hiredate { get; set; }
public decimal salary { get; set; }
public Employee ()
{
EmployeeId = Guid.NewGuid();
}
}
然后在控制器中,当您实例化一个新的
Employee
类时,您将使用GUID
填充EmployeeId
属性 它实际上是一个列表GUID
,则为“是”。