Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework 通过反射调用泛型方法导致错误_Entity Framework_Reflection - Fatal编程技术网

Entity framework 通过反射调用泛型方法导致错误

Entity framework 通过反射调用泛型方法导致错误,entity-framework,reflection,Entity Framework,Reflection,我有一个扩展方法如下 public static class ExtensionMethod { public static string GetTableName<T>(this ObjectContext context) where T : class { //Content } } static void Main(string[] args) { using (BreakAwayEntities conte

我有一个扩展方法如下

 public static class ExtensionMethod
{
    public static string GetTableName<T>(this ObjectContext context) where T : class
    {
        //Content
    }
}
static void Main(string[] args)
    {
        using (BreakAwayEntities context = new BreakAwayEntities())
        {
            Customer cus = context.Customers.First();

            ObjectStateEntry entry = context.ObjectStateManager.GetObjectStateEntry(cus);
            Type t = entry.Entity.GetType();               
            MethodInfo method = typeof(ExtensionMethod).GetMethod("GetTableName");
            MethodInfo genericMethod = method.MakeGenericMethod(t);
            genericMethod.Invoke(null, null);         
        }
    }    
但是在代码genericMethod.Invokenull的最后一行,null抛出异常参数计数不匹配。
任何人都可以提供帮助?

GetTableName方法有一个参数,但您正在调用Invoke,它将有一个null的第二个参数,指示不应传递任何参数。您需要将ObjectContext作为第二个参数传递:

genericMethod.Invoke(null, new object[] { context });