我已经开始使用实体框架,经过研究,我发现实体框架只接受DateTime格式的DateTime2。
将DateTime选择器转换为Datetime2格式的最佳方法是什么?
我目前执行以下操作
string strCastFrom = this.dtCastFrom.Value.Year.ToString("0000") + "-" + this.dtCastFrom.Value.Month.ToString("00") + "-" + this.dtCastFrom.Value.Day.ToString("00") + "T00:00:00";是否有更好的方法将日期时间转换为DateTime2?
发布于 2014-02-18 14:18:13
不要执行任何字符串转换。只管用
DateTime value = dtCastFrom.Value;让实体框架本身负责将数据发送到数据库。您不需要字符串表示,也没有理由通过字符串表示。这不仅是EF的情况,也是一个普遍的原则。
https://stackoverflow.com/questions/21856448
复制相似问题