C# EF SQL Server 字段类型【Time(7)】 转字符串

前景描述:

数据库表字段类型【time(7)】,在C# 中用EF,数据出来很奇怪:

C# EF SQL Server 字段类型【Time(7)】 转字符串

 C# :

C# EF SQL Server 字段类型【Time(7)】 转字符串

 解决方案:

BTime = (SqlFunctions.DatePart("HH", a.BTime) < 10 ? ("0" + SqlFunctions.DatePart("HH", a.BTime)) : SqlFunctions.DatePart("HH", a.BTime) + "") + ":" + (SqlFunctions.DatePart("mi", a.BTime) < 10 ? ("0" + SqlFunctions.DatePart("mi", a.BTime)) : SqlFunctions.DatePart("mi", a.BTime) + "")
                                  

注意:需要添加引用

using System.Data.Entity;
using System.Data.Entity.SqlServer;

得到结果:

C# EF SQL Server 字段类型【Time(7)】 转字符串

 

上一篇:查询一年12个月的数据


下一篇:Python中常用的数据类型: