62,047
社区成员
发帖
与我相关
我的任务
分享
#region 为IQueryable<T>类型实现Like操作
public static IQueryable<T> Like<T>(this IQueryable<T> query, Expression<Func<T, string>> lambda, string value)
{
return query.Provider.CreateQuery<T>(Expression.Call(lambda.Body,
typeof(string).GetMethod("Contains", new Type[] { typeof(string) }),
new Expression[] { Expression.Constant(value) }));
}
#endregion
只能从实现 IQueryable 接口的实例构造 LINQ to Entities 查询表达式。
参数名: expression
public static IQueryable<TSource> Where<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
{
if (source == null)
{
throw Error.ArgumentNull("source");
}
if (predicate == null)
{
throw Error.ArgumentNull("predicate");
}
return source.Provider.CreateQuery<TSource>(Expression.Call(null, ((MethodInfo) MethodBase.GetCurrentMethod()).MakeGenericMethod(new Type[] { typeof(TSource) }), new Expression[] { source.Expression, Expression.Quote(predicate) }));
}