Linq-to-SQL business layer calls SQL stored procedure and gets:
Unable to cast object of type 'WhereSelectEnumerableIterator`2
[ERICustomersDataLayer.MergeCustomersResult,ERICustomersDataLayer.MergeCustomersResult]'
to type 'System.Collections.Generic.List`1[System.String]'.
Stored procedure:
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 Code:
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;
}
In the test case, the SP is not returning anything, so this should be the same as an empty query. However, I get the same exception even when it does return an error message.