Entity framework WhereInExtension
生活随笔
收集整理的這篇文章主要介紹了
Entity framework WhereInExtension
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
摘自 http://www.cnblogs.com/ejiyuan/archive/2009/07/20/1527224.html
public static class WhereInExtension{
private static Expression<Func<TElement, bool>> BuildWhereInExpression<TElement, TValue>(Expression<Func<TElement, TValue>> propertySelector, IEnumerable<TValue> values)
{
ParameterExpression p = propertySelector.Parameters.Single();
if (!values.Any())
return e => false;
var equals = values.Select(value => (Expression)Expression.Equal(propertySelector.Body, Expression.Constant(value, typeof(TValue))));
var body = equals.Aggregate<Expression>((accumulate, equal) => Expression.Or(accumulate, equal));
return Expression.Lambda<Func<TElement, bool>>(body, p);
}
public static IQueryable<TElement> WhereIn<TElement, TValue>(this IQueryable<TElement> source, Expression<Func<TElement, TValue>> propertySelector, params TValue[] values)
{
return source.Where(BuildWhereInExpression(propertySelector, values));
}
}
轉載于:https://www.cnblogs.com/illusion/archive/2011/04/14/2016237.html
總結
以上是生活随笔為你收集整理的Entity framework WhereInExtension的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ADT
- 下一篇: mxf格式怎么转换成mp4?