开发者

Dynamic stored procedure name 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 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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜