Linq to SQL SP Parameters

I have an SP that I want to call from linq. SP has 5 parameters, but I only want to pass them / 2 of them.

how would I call SP as if I started adding parameters to the code that it will not build, since it wants all 5.

+4
source share
3 answers

You will have something like this:

MyDbDataContext db = new MyDbDataContext(); db.MyStoredProc(customerID, "sometext", null, null, null); 

Success / failure will depend on the SQL statements inside your sproc dealing with zeros for these last 3 parameters.

+3
source

Another option is to drag the stored proc into your DBML a second time and delete the parameters that you do not want to pass.

+2
source

overload call sproc.

I do not have it in front of me, but you should get the DataAccessName.cs file and create a method name with the same signature

auto gen'd sproc method signature:

 void sp_sproc(int a, int b, int c, int d, int e); 

you will do this in the DataAccessName.cs file

 void sp_sproc(int a, int b) { this.sp_sproc(a,b,0,0,0); } 

if the parameters are null, for example

 void sp_sproc(int? a, int? b, int? c, int? d, int? e); 

then you could do

 void sp_sproc(int a, int b) { this.sp_sproc(a,b,null,null,null); } 
+1
source

All Articles