2012-04-29 29 views
2

我在嘗試從MVC實體框架中的MS SQL數據庫查詢日期範圍時收到錯誤。日期範圍查詢中的SQL/Entity Framework錯誤

Unable to cast the type 'System.Boolean' to type 'System.Data.SqlTypes.SqlBoolean'. LINQ to Entities only supports casting Entity Data Model primitive types.

這是我們的查詢:

dbWS.Where(Function(x) x.CountyCode = user.County And x.CompleteStatus.Contains("0") And x.ProgramEffort = 25 Andx.combinedDate> = prevDate而x.combinedDate < =明天)

大膽的代碼導致此錯誤。我們正在以不同的方式查詢這個問題,並且它工作正常,但是由於我們必須更改爲日期範圍,因此我們一直在收到此錯誤。

回答

0

我們解決了這個問題。我們的數據庫中有一些數據已損壞,導致我們將模型中的數據類型更改爲DateTime中的SqlDateTime。一旦我們清理了數據並將模型改回,問題就解決了。