I have a SP which I want to call from linq. The SP have 5 parameters but i only want to pass/need to 2 of them.
how would I call the SP as when i go to add the parameters in code it wont build as it want all 5.
I have a SP which I want to call from linq. The SP have 5 parameters but i only want to pass/need to 2 of them.
how would I call the SP as when i go to add the parameters in code it wont build as it want all 5.
overload the sproc call.
I dont have it in front of me but you'd goto your 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'd make this in your DataAccessName.cs file
void sp_sproc(int a, int b)
{
this.sp_sproc(a,b,0,0,0);
}
if the params are nullable, like so
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);
}
You'd have something like this:
MyDbDataContext db = new MyDbDataContext();
db.MyStoredProc(customerID, "sometext", null, null, null);
Success/failure would depend on the SQL statements inside your sproc dealing with nulls on those last 3 parameters.
Another option is to drag the stored proc into your DBML a second time and delete the parameters you don't want to pass in.