简体   繁体   中英

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. This query has some froms, joins and a where clause (neither group by nor order by are used).

In where clause I am using below function to remove time from a DateTime field:

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:

TruncateTime(System.Nullable`1[System.DateTime])' has no supported translation to SQL.'

This is not LinqPad specific.

This basically means that the Where clause contains some conditions that can not be successfully translated from Linq to SQL.

In order to get around this you can split the where clause:

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.

I realize this will cause a greater pull from the database, but that is the limitation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM