Linq dynamic stored procedure name for sql

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

+5
source share
2 answers

try it

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
+4
source
        AdventureWorksDataContext ad = new AdventureWorksDataContext();
        var sp1 = typeof(AdventureWorksDataContext).GetMethod("uspGetManagerEmployees");//Get the SP 
        var result1 = sp1.Invoke(ad, new object[] { 16 });

        var sp = typeof(AdventureWorksDataContext).GetMethod("GetEmployee");//Get the SP 
        var result = sp.Invoke(ad, new object[] {  });//If no parameters are passed
+3
source

All Articles