出于安全考虑,在后台与前台进行数据传输时,往往不会直接传输实体模型,而是使用Dto(Data transfer object 数据传输对象),这样在后台往前台传递数据时可以省略不必要的信息,只保留必要的信息,大大增强数据安全性。 下面给出两个相互对应的关系模型User、UserDto public class User { private const int NameMaxLength = 20;
private const int PassWordMaxLength = 16;
[Key] public long Id { get; }
[MaxLength(NameMaxLength)] public string Name { get; set; }
[MaxLength(PassWordMaxLength)] [DataType(DataType.Password)] public string PassWord { get; set; } }
public class UserDto { private const int NameMaxLength = 20;
private const int PassWordMaxLength = 16;
[MaxLength(NameMaxLength)] public string Name { get; set; }
[MaxLength(PassWordMaxLength)] public string PassWord { get; set; } }
|