Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic stored procedure name linq to sql

Tags:

linq-to-sql

Is there a way to to pass a stored procedure name as a string to a function then use reflection to actually get the sp to use in an linq to sql query?

like image 809
Dooie Avatar asked Mar 31 '11 12:03

Dooie


1 Answers

Try this

var sp = typeof(DataContext).GetMethod("GetUsersByID"); //Get the SP
var result = sp.Invoke(DbContext, new object[]{100}); //Execute the SP with 100 as the parameter
like image 60
Magnus Avatar answered Nov 08 '22 19:11

Magnus