有没有办法将存储过程名称作为字符串传递给函数然后使用反射来实际获取sp在linq to sql查询中使用?
答案 0 :(得分:4)
试试这个
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
答案 1 :(得分:3)
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