T-SQL Table Valued Functions and Linq-to-SQL

I noticed that calling a T-SQL table value function that does not explicitly define the return table type causes the Linq-To-SQL code generation engine to create an incorrectly formed SQL request.

When querying the SQL functions listed at the bottom of the post with these statements, the first will not work and the second will work correctly.


foo(1).Dump();
foo2(2).Dump();


The first function (from the two listed below) will have SQL generated that looks like

-- Region Parameters
DECLARE @p0 Int = 1
-- EndRegion
SELECT [t0].@Max AS [Max]
FROM [dbo].[foo](@p0) AS [t0]

which is incorrect. If you inspect the SELECT statement closely you will see [t0].@Max and the @ symbol should not be there.

The following SQL function definitions are referenced above: