Normally, when you want to call a stored procedure directly through Linq to Sql, you can use the ExecuteQuery method:
result = dc.ExecuteQuery<MyTable>("Exec myStoredProcedure");
And if you need to call it with parameters, you can add them through string substitution:
string query = "Exec myStoredProcedure ";
for (int i = 0; i < parameters.Count - 1; i++) {
query += " {" + i + "},";
}
query = query.TrimEnd(',');
result = dc.ExecuteQuery<MyTable>(query, parameters);
But what if one of the parameters is an output variable? Is it possible to get the value back after the procedure has been run?
Alper Ozcetin’s is right you can map StoredProcedures in *.dbml and you can use StoredProcedures as Method.
Below is demo doing this with the AdventureWorks DB and works for both vs2008 and vs2010
Wtih AdventureWorks I created the following Proc
I then added sp_test to a dbml and wrote the following program
This results in the following ouput
You’ll notice that the input into the sp_test method is a
ref