网上说在MySQL的时间字段为NULL时,转换出现问题。
Convert Zero Datetime:,当没有设置此属性时,如果Mysql数据库中的datetime列为null的时候,.net在转换时会抛出如下异常:Unable to convert MySQL date/time value to System.DateTime at MySql.Data.Types.MySqlDateTime.GetDateTime()这是因为.net的默认最小日期和Mysql的不匹配,导致转换出错,解决办法就是以上连接串中的(设置Convert Zero Datetime=True)
而我在jnpf 3.2框架下出现了新的问题就是,时间字段抽取不出来
`var list = await _meteringDeviceRepository.AsSugarClient().Queryable( (a,b,c) => new JoinQueryInfos( JoinType.Left, a.DeviceId == b.DeviceId, JoinType.Left, a.MeteringTaskId == c.MeteringTaskId)) .Where((a, b, c) => a.EnabledMark == 0 && a.Deflag == 0 && b.EnabledMark == 0 && b.Deflag == 0 && c.EnabledMark == 0 && c.Deflag == 0) .WhereIF(!string.IsNullOrEmpty(input.keyword), a => a.MeteringCode.Contains(input.keyword)) .WhereIF(queryParam.ContainsKey("DeviceName") && !string.IsNullOrEmpty(queryParam["DeviceName"].ToString()), a => a.DeviceName.Contains(queryParam["DeviceName"].ToString())) .WhereIF(queryParam.ContainsKey("DeviceCode") && !string.IsNullOrEmpty(queryParam["DeviceCode"].ToString()), a => a.DeviceCode.Contains(queryParam["DeviceCode"].ToString())) .WhereIF(companyId != null, a => a.CompanyId.Equals(companyId)) //.Where(authorizeWhere) .Select((a,b,c) => new { MeteringDeviceId = a.MeteringDeviceId, MeteringCode = a.MeteringCode, DeviceId = b.DeviceId, DeviceCode = b.DeviceCode, DeviceName = b.DeviceName, LocationName = b.LocationName, Model = b.Model, DepartmentName = b.DepartmentName, DeviceStatus = b.Status, Accuracy = a.Accuracy, Scope = a.Scope, PermissibleError = a.PermissibleError, MeteringMode = c.MeteringMode, Cycle = a.Cycle, CycleUnit = a.CycleUnit, BeforeTime = a.BeforeTime, Status = c.Status, Responsiblename = c.Responsiblename, NextTime = a.NextTime, CertificateNo = a.CertificateNo, CertificateValid = a.CertificateValid, creatorDate = a.CreateDate }).MergeTable().OrderBy(t => t.creatorDate,OrderByType.Desc).ToPagedListAsync(input.currentPage, input.pageSize);
里面的BeforeTime 、creatorDate 等数据库内一定有时间的时间字段抽取出来也为null
是因为我在连接字符中加了这个属性
Allow Zero Datetime=True
这导致了返回的日期会是MySql.Data.Types.MySqlDateTime类型,而不是DataTime,所以在后台程序中转换不成功,成为了null。



