左连接时,右表有个DataOnly类型的数据,查询报错了 返回
SqlSugar
处理完成
7
175
娇娇欲静 发布于1个月前
悬赏:0 飞吻
var detail = SqlSugarBase.QYDB.Queryable<FInfo>().Where(e => e.Id == id) .LeftJoin<ViewWorker>((left, right) => left.Name == right.Name && right.Type.Contains("德国机")) .Select((left, right) => new { left.Id, Worker = right }).First();
报错“Error converting value 2017/2/1 0:00:00 to type 'System.Nullable`1[System.DateOnly]'. Path 'Worker.StartTime'”,把类型改成DateTime倒是不报错了,但我不需要时分秒
热忱回答(7)
-
fate sta VIP01个月前
升级最新看一下,
还有问题按模版提供一个DEMO
https://www.donet5.com/Home/Doc?typeId=2366
0 回复 -
娇娇欲静 VIP01个月前
[HttpGet] public object Get() { var db=new SqlSugarScope(new SqlSugar.ConnectionConfig() { ConnectionString = "server=.;uid=sa;pwd=sasa;database=SQLSUGAR4XTEST", DbType = DbType.SqlServer, IsAutoCloseConnection = true }); //用例代码 var detail = SqlSugarBase.QYDB.Queryable<FInfo>().Where(e => e.Id == id) .LeftJoin<ViewWorker>((left, right) => left.FactoryFreNum == right.Name && right.Type.Contains("德国机")) .Select((left, right) => new { left.Id, left.CustName, left.CustNum, ViewWorker = right }).First(); return result; } //用例实体 public class FInfo { [SugarColumn(ColumnName = "ID", ColumnDataType = "int", IsPrimaryKey = true, IsIdentity = true)] public int Id { get; set; } [SugarColumn(ColumnName = "CustName", ColumnDataType = "nvarchar", IsNullable = true)] public string? CustName { get; set; } [SugarColumn(ColumnName = "CustNum", ColumnDataType = "nvarchar", IsNullable = true)] public string? CustNum { get; set; } } //用例实体 public class ViewWorker { [SugarColumn(ColumnName = "id", ColumnDataType = "int")] // 可根据需要设置主键、自增等属性 public int Id { get; set; } [SugarColumn(ColumnName = "name", ColumnDataType = "nvarchar", IsNullable = true)] public string? Name { get; set; } [SugarColumn(ColumnName = "type", ColumnDataType = "nvarchar", IsNullable = true)] public string? Type { get; set; } [SugarColumn(ColumnName = "start_time", ColumnDataType = "date", IsNullable = true)] public DateOnly? StartTime { get; set; } [SugarColumn(ColumnName = "end_time", ColumnDataType = "date", IsNullable = true)] public DateOnly? EndTime { get; set; } [SugarColumn(ColumnName = "price", ColumnDataType = "real", IsNullable = true)] public float? Price { get; set; } }
这个可以吗?已经是最新版了(不包括预发行版)
0 回复 -
娇娇欲静 VIP01个月前
@fate sta:已经是最新版了(不包括预发行版)
0 回复 -
fate sta VIP01个月前
-
0 回复 -
fate sta VIP01个月前
-
0 回复 -
fate sta VIP01个月前
提供完整的、建表 加数据 的例子
0 回复 -
fate sta VIP01个月前0 回复