【发布时间】:2016-03-09 09:29:35
【问题描述】:
我的 SELECT 中有此代码:
SELECT A.CompletedDate,
CASE
WHEN (@AdminTestId IS NULL AND @UserTestId IS NULL) THEN 0
WHEN (@AdminTestId = temp.AdminTestId AND @UserTestId = A.UserTestId) THEN 1
WHEN (@AdminTestId = temp.AdminTestId AND @UserTestId IS NULL) THEN 1
ELSE 0
END AS [Current],
在我的 ASP.NET DTO 中,我有:
public partial class GetTestsDTO
{
public bool? GradePass { get; set; }
// the following line is what is giving the error. If I remove
// the line it will not try to convert the data and there is no
// error. Note that I want to put this into a bool as web.api
// then passes it to the client as a bool
public bool Current { get; set; }
public DateTime? CompletedDate { get; set; }
}
这给了我一个错误,我希望能得到一些帮助。
错误是:
message=从物化 'System.Int32' 类型的指定转换为 'System.Boolean' 类型无效。
【问题讨论】:
-
可能是因为你返回的是一个整数?
-
CAST( 0 AS BIT)和CAST(1 AS BIT)? -
SQL Server 没有 公开的布尔数据类型,因此您不会在
SELECT中返回一个。正如小伙子建议的那样,它确实有一个bit数据类型,并且 ADO.Net 支持将 那些 转换为布尔值。 -
@lad2025 - 我试过你的建议,效果很好。如果您想将此添加为我可以接受的答案。谢谢
标签: c# asp.net sql-server