简体   繁体   English

将转储应用到结果时,LINQPad 抛出异常“TruncateTime(System.Nullable`1[System.DateTime])' has no supported translation to SQL”

[英]LINQPad is throwing exception “TruncateTime(System.Nullable`1[System.DateTime])' has no supported translation to SQL” when applying Dump to results

I have a Linq query done in LINQPad.我在 LINQPad 中完成了 Linq 查询。 This query has some froms, joins and a where clause (neither group by nor order by are used).这个查询有一些 froms、joins 和 where 子句(既不使用 group by 也不使用 order by)。

In where clause I am using below function to remove time from a DateTime field:在 where 子句中,我使用 function 从 DateTime 字段中删除时间:

System.Data.Entity.DbFunctions.TruncateTime(myField)

This query return the results into a:此查询将结果返回到:

IQueryable<MyCustomClass>

When I execute query from LINQPad it is executed correctly without errors, but If I perform results.Dump() or results.ToList().Dump() in order to view the results in LINQPad I get below error:当我从 LINQPad 执行查询时,它可以正确执行而没有错误,但是如果我执行 results.Dump() 或 results.ToList().Dump() 以在 LINQPad 中查看结果,则会出现以下错误:

TruncateTime(System.Nullable`1[System.DateTime])' has no supported translation to SQL.' TruncateTime(System.Nullable`1[System.DateTime])' 不支持转换为 SQL。'

This is not LinqPad specific.这不是 LinqPad 特定的。

This basically means that the Where clause contains some conditions that can not be successfully translated from Linq to SQL.这基本上意味着Where子句包含一些条件,无法从 Linq 成功转换为 SQL。

In order to get around this you can split the where clause:为了解决这个问题,您可以拆分 where 子句:

First part of the where clause contains all the SQL compatible operations, then add a .ToList() which will retrieve the data from the database, then finish with the non-SQL, but Linq to Object compatible part of the where clause. where 子句的第一部分包含所有 SQL 兼容操作,然后添加一个.ToList()它将从数据库中检索数据,然后以非 SQL 结束,但 Linq 与 where 子句的 Z497031794414A552435ACB0 部分兼容。5

I realize this will cause a greater pull from the database, but that is the limitation.我意识到这将导致从数据库中获得更大的拉动,但这就是限制。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 &#39;TruncateTime(System.Nullable`1 [System.DateTime])&#39;不支持对SQL的转换。 - TruncateTime(System.Nullable`1[System.DateTime])' has no supported translation to SQL.' [System.DateTime])'没有支持的SQL转换 - [System.DateTime])' has no supported translation to SQL “没有为类型‘System.Nullable`1[System.DateTime]’(参数‘property’)定义属性‘System.DateTime Date’”异常 - “Property 'System.DateTime Date' is not defined for type 'System.Nullable`1[System.DateTime]' (Parameter 'property')” exception 序列化复杂类型System.Nullable <System.DateTime> - Serialize Complex Type System.Nullable<System.DateTime> C# asp.net 核心 webapi 抛出“JSON 值无法转换为 System.Nullable`1[System.DateTime] - C# asp.net core webapi throwing "The JSON value could not be converted to System.Nullable`1[System.DateTime] &#39;System.String&#39; 和 &#39;System.Nullable`1[System.DateTime]&#39; 类型之间没有定义强制运算符 - No coercion operator is defined between types 'System.String' and 'System.Nullable`1[System.DateTime]' EF AsNoTracking导致错误。 类型&#39;System.DateTime&#39;的表达式不能用于赋值类型&#39;System.Nullable`1 [System.DateTime]&#39; - EF AsNoTracking Causes error. Expression of type 'System.DateTime' cannot be used for assignment to type 'System.Nullable`1[System.DateTime]' ExecuteMethodCall:类型&#39;System.Nullable`1 [System.DateTime]&#39;必须声明一个默认(无参数)构造函数 - ExecuteMethodCall: The type 'System.Nullable`1[System.DateTime]' must declare a default (parameterless) constructor 不可为空的System.DateTime的值 - Value for Non-Nullable System.DateTime 错误System.Nullable&#39;1自动映射器 - Error System.Nullable'1 automapper
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM