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 q开发者_开发百科uery?
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
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
精彩评论