Stored Procedures with optional parameters
So, I am working on a database that has some massive stored procedures, which have some optional parameters.
for example this one which has about 80 parameters.
CREATE PROCEDURE [dbo].[EventCreate] @EventID INT, @OrganisationID INT, @Name VARCHAR(256), @SubTitle VARCHAR(256) = '', @SeasonID INT, @StartDate DATETIME, @EndDate DATETIME, @DateConfirmed BIT = 1, @Duration VARCHAR(128), @SaleStart DATETIME = NULL, @OnlineConfirmation VARCHAR(MAX), ....
Can I utilize LinqPad to call this procedure omitting the optional parameters?
I've tried to call it with null values, EventCreate(1, _organizationId, "Title", null, _seasonId, _eventCategory, _startDate, _endDate, null, .....
but that just passes null as values into the procedure.
Comments
Use named arguments:
This works because the method that LINQPad generates to call the stored procedure is overloaded. The second overload takes optional arguments of type
Optional<T>
.Optional<T>
is a type defined within LINQPad (with an implicit conversion from T), whose default value tells LINQPad not send that argument to the stored procedure.