Tuesday, August 26, 2008

Linq To SQL Stored Procedure returns an Int

Today I was using Linq To Sql to execute a stored procedure wicht returned results by using a temporary table and dynamic sql (not my stored procedure)
Suprisingly enough when I dropped the procedure on the dbml file,
it generated a function with the return value typed as integer.
As it turned out, linq to sql and temporary tables don't play nice.
And since the database was a sql 2000 db, using table variables was not possible.

The solution turned out to be simple enough,
replace the stored procedure with a dummy one that returns the fields your normal procedure will return (names and type).
Then drop this stored procedure on the dbml file.
This will generate the correct return type for your procedure,
then simple alter the stored procedure to the correct one.

Hurrah, we can now use linq to sql to use our difficult stored procedure.

No comments: