I have two stored procedures. One (test_proc_outside) makes a call to a second one (test_proc_inside).
When I create a new LINQ to SQL .dbml file visually by dragging over my test_proc_outside stored proc, the generated class (test_proc_outsideResult) actually contains the modelling for the inner proc’s (test_proc_inside) result set.
Here is the code for the outside stored proc (test_proc_outside):
CREATE PROCEDURE [dbo].[test_proc_outside]
@test1 int = 1,
@test2 int = 2,
@test3 int = 3
AS
BEGIN
— SET NOCOUNT ON added to prevent extra result sets from
— interfering with SELECT statements.
SET NOCOUNT ON;
-- The result of this proc call gets modelled into DBML:
EXEC dbo.test_proc_inside @test1, @test2
-- This SELECT statement does NOT get modelled into DBML:
SELECT @test1 AS Test1,
@test2 AS Test2,
@test3 AS Test3
END
GO
Here is the code for the inside stored proc (test_proc_inside):
CREATE PROCEDURE [dbo].[test_proc_inside]
-- Add the parameters for the stored procedure here
@test1 int = 1,
@test2 int = 2
AS
BEGIN
— SET NOCOUNT ON added to prevent extra result sets from
— interfering with SELECT statements.
SET NOCOUNT ON;
-- This is the result set that gets modelled by the DBML file:
SELECT @test1 AS Test1_Inside,
@test2 AS Test2_Inside
END
GO
It appears that the DBML generation looks for the very first result set in the stored procedure (or nested stored procedures) and spits out the model for that.
If I change the nested proc call to a function instead, I get my desired model (test_proc_outside).
Is there a configuration setting to tell the DBML file to generate the class for the result set on the outside proc (test_proc_outside) and not to bother with the inner results from test_proc_inside?
Thanks in advance,
Craig
I think it’s possible to get the result you want with L2S but you also have to get all the other results as well. You can’t do it with the designer, you’ll have to map the sproc by extending the DataContext in a partial class with a method that returns an instance of the IMultipleResults interface. See this blog post:
http://blogs.msdn.com/b/dinesh.kulkarni/archive/2008/05/16/linq-to-sql-tips-7.aspx
Also, if the stored proc is returning result sets that don’t map to entity in your L2S model, you’ll need create special types to represent those results manually by defining them in code the same way L2S normally generates types for stored procedure results in its designer.cs.