Uncategorized

Question . I have a stored procedure whose return value is calculated by MAX(). When I drag the stored procedure to the O/R Designer surface, the return value is not correct.

A. LINQ to SQL provides two ways to return database-generated values by way of stored procedures:

By naming the output result.

By explicitly specifying an output parameter.

The following is an example of incorrect output. Because LINQ to SQL cannot map the results, it always returns 0:

create procedure proc2

as

begin

select max(i) from t where name like ‘hello’

end

The following is an example of correct output by using an output parameter:

create procedure proc2

@result int OUTPUT

as

select @result = MAX(i) from t where name like ‘hello’

go

The following is an example of correct output by naming the output result:

create procedure proc2

as

begin

select nax(i) AS MaxResult from t where name like ‘hello’

end

Categories: Uncategorized

Leave a Reply