我有一个员工模型:
public class Employee
{
public string FirstName { get; set; }
public string LastName { get; set; }
...
public DateTime TerminationDate{ get; set; }
}模型是自动填充的(由HttpResponseMessage的Content.ReadAsAsync<Employee>())
TerminationDate (当员工仍在公司工作时)的默认值是0000-00-00,它不能转换为DateTime对象,大概是因为没有第0day或month。我得到了错误:
Could not convert string to DateTime: 0000-00-00. Path 'terminationDate', line 1, position 533.
默认日期值不能更改-我是从第三方服务获取的。
我能想到的唯一变通方法是将TerminationDate设置为字符串,但是所有获取TerminationDate的对象都必须将其解析为DateTime对象。
有没有什么更优雅的我可以做的?
发布于 2015-04-15 22:46:32
我建议将终止日期设置为可空。
public DateTime? TerminationDate{ get; set; }由于当前员工没有TerminationDate,因此将其保留为null是合理的。
https://stackoverflow.com/questions/29653317
复制相似问题