0

我从博客 scottgu 研究 Linq to sql 并收到错误消息:

“无法解析符号 ExecuteMethodCall”。

linq to sql支持Method ExecuteMethodCallis,但是为什么会出现这个错误呢?

ALTER PROCEDURE dbo.VariableShapeSample
        (
    @shape int 
    )

AS
    if(@shape=1)
    select * from products
    else if (@shape=2)
    select * from orders

public partial class NorthwindDataContext
{
    [Function(Name = "VariableShapeSample")]
    [ResultType(typeof (Product))]
    [ResultType(typeof (Order))]
    public IMultipleResults VariableShapeSample(System.Nullable<int> shape )
    {

        IExecuteResult result = this.ExecuteMethodCall(this
                                                       , ((MethodInfo) (MethodInfo.GetCurrentMethod()))
                                                       , shape);

        return (IMultipleResults) result.ReturnValue;
    }
}

4

1 回答 1

0

DataContext.ExecuteMethodCall方法是一个内部方法。你不能叫它。它只能在 System.Data.Linq 程序集中的文件中访问。好吧,如果你真的需要,你可以使用反射来调用它:

Type type = typeof(NorthwindDataContext);
var methodInfo = type.GetMethod("ExecuteMethodCall", 
                                 BindingFlags.NonPublic | BindingFlags.Instance);
var currentMethod = ((MethodInfo) (MethodInfo.GetCurrentMethod()));
var result = (IExecuteResult)methodInfo.Invoke(this, 
                                 new object[] { this, currentMethod, shape });
于 2013-01-11T21:52:50.420 回答