我正在实现一个SQL到LINQ服务,我想调用一个存储过程,定义如下:
PROCEDURE [dbo].[GetTransportationOffers]
@pickupLocID int = 0,
@destinationLocID int = 0,
@serviceDateTime dateTime,
@isAsInstructed bit = 0
AS
BEGIN
SELECT
TransportationServices.id AS ServiceID, TransportationVehicles.id AS VehicleID,
TransportationServices.ClientPrice,
TransportationServices.Currency, TransportationVehicles.Description,
TransportationVehicles.Image, TransportationVehicles.MaxPassengers,
CASE
WHEN (DATEDIFF(hour, @serviceDateTime, GETDATE()) > Suppliers.MinNoticeHours)
THEN 'auto-service'
ELSE
'no auto-service'
END
FROM
TransportationServices
INNER JOIN
TransportationVehicles ON TransportationServices.VehicleID = TransportationVehicles.id
INNER JOIN
Suppliers ON TransportationServices.SupplierID = Suppliers.id
WHERE
(TransportationServices.PickupLocationID = @pickupLocID)
AND ((TransportationServices.DropoffLocationID = @destinationLocID) OR
((TransportationServices.DropoffLocationID = NULL) AND (@isAsInstructed = 1)))
为接口函数生成的签名如下:
GetTransportationOffers (System.Int32 pickupLocID, System.Int32 destinationLocID, System.DateTime serviceDateTime, System.Boolean isAsInstructed)
调用此函数会给我以下异常:
无法转换类型为#System; Int32'的对象输入' System.String'。
存储过程或自动生成的接口函数中的所有参数都不是字符串。当我使用SQL Studio运行存储过程时,我没有异常。解释布尔参数会有问题吗?日期时间参数?是否在存储过程中发生了什么?
更多
对于记录,数据库是MS SQL Server。 添加了" printf"或者SPROC的日志条目,我可以说LINQ to SQL使用正确的参数调用SPROC。此外,SPROC现在有一个TRY / CATCH子句,它没有表明SPROC中的异常,所以我必须得出结论,问题出在回程上。在将SPROC返回的表转换为
时,搞砸了什么答案 0 :(得分:0)
如果我慢慢地向自己解释,我可以找到答案......
SELECT语句中的最后一列是没有AS子句的CASE语句,因此没有列名。添加这样一个子句有助于LINQ to SQL接口理解结果,就这样,它起作用了!