在EF上工作,需要在哪里写一个自定义
public virtual IEnumerable GetDataByID<TEntity>() where TEntity : class
{
if (this.Context == null)
Initialize<TEntity>();
TContext context = this.Context;
var result = context.CreateObjectSet<TEntity>().Where(GetExpression<TEntity>(5));
return result;
}
public Expression GetExpression<TEntity>(int id) where TEntity : class
{
ParameterExpression e = Expression.Parameter(typeof(TEntity), "e");
PropertyInfo propInfo = typeof(TEntity).GetProperty(EntityInfo<TEntity>.GetPkFieldName(this.Context));//(KeyPropertyName);
MemberExpression m = Expression.MakeMemberAccess(e, propInfo);
ConstantExpression c = Expression.Constant(id, typeof(int));
BinaryExpression b = Expression.Equal(m, c);
Expression<Func<TEntity, bool>> lambda = Expression.Lambda<Func<TEntity, bool>>(b, e);
return lambda;
}
错误:
'System.Data.Objects.ObjectQuery.Where(string, params System.Data.Objects.ObjectParameter[])' 的最佳重载方法匹配有一些无效参数
为什么我的上述语法不起作用,如何解决?