有效我有以下两种实体框架的包括如下的方法:获取方法的MethodInfo的 - 该操作仅在泛型类型
public static IIncludableQueryable<TEntity, TProperty> Include<TEntity, TProperty>(
[NotNullAttribute] this IQueryable<TEntity> source,
[NotNullAttribute] Expression<Func<TEntity, TProperty>> navigationPropertyPath)
where TEntity : class;
public static IQueryable<TEntity> Include<TEntity>(
[NotNullAttribute] this IQueryable<TEntity> source,
[NotNullAttribute][NotParameterized] string navigationPropertyPath)
where TEntity : class;
我需要得到MethodInfo的两种方法。这是第一个我用:
MethodInfo include1 = typeof(EntityFrameworkQueryableExtensions)
.GetMethods().First(x => x.Name == "Include" && x.GetParameters()
.Select(y => y.ParameterType.GetGenericTypeDefinition())
.SequenceEqual(new[] { typeof(IQueryable<>), typeof(Expression<>) }));
这个工作,但是当我尝试使用,以获得第二下列操作之一:
MethodInfo include2 = typeof(EntityFrameworkQueryableExtensions)
.GetMethods().First(x => x.Name == "Include" && x.GetParameters()
.Select(y => y.ParameterType.GetGenericTypeDefinition())
.SequenceEqual(new[] { typeof(IQueryable<>), typeof(String) }));
我得到的错误:
This operation is only valid on generic types
什么时我错过了?
'string navigationPropertyPath'是通用的吗? – CodeCaster
不,这只是一个字符串...我在上面添加了方法签名。 –
'ParameterType.GetGenericTypeDefinition()'如何返回'typeof(String)'? –