LINQ到SQL業務層調用SQL存儲過程,並得到:無效轉換的LINQ到SQL
Unable to cast object of type 'WhereSelectEnumerableIterator`2
[ERICustomersDataLayer.MergeCustomersResult,ERICustomersDataLayer.MergeCustomersResult]'
to type 'System.Collections.Generic.List`1[System.String]'.
存儲過程:
ALTER PROCEDURE MergeCustomers @CurrentCustomerId UNIQUEIDENTIFIER, @MergedCustomerId UNIQUEIDENTIFIER
AS
BEGIN
DECLARE @Error VARCHAR(500);
IF NOT EXISTS (SELECT * FROM Customer WHERE Id = @CurrentCustomerId)
BEGIN
SET @Error = 'Current customer ID not in customer table '
SELECT @Error [Error]
RETURN -1
END
IF NOT EXISTS (SELECT * FROM Customer WHERE Id = @MergedCustomerId)
BEGIN
SET @Error = 'Merged customer ID not in customer table '
SELECT @Error [Error]
RETURN -1
END
END
的LINQ TO- SQL代碼:
public List<string> Merge(Guid CurrentUserId, Guid MergedUserId)
{
var dc = new ERICustomersDataLayer.ERICustomersDataContext();
var rows = (
from e in dc.MergeCustomers(CurrentUserId, MergedUserId)
select e);
return (List<string>)rows;
}
在測試案例中,SP沒有返回任何東西,所以這應該與空查詢相同。但是,即使它返回錯誤消息,我也會得到相同的異常。
你的存儲過程實際上選擇了什麼?它似乎只檢查客戶的存在兩次,但在兩個實際存在的情況下,沒有發生任何事情...... – 2011-04-12 20:55:32