EFsql笔记

like的语法

string[] cities = { "London", "Madrid" };
IQueryable<Customer> custs = db.Customers.Where(c => cities.Contains(c.City));

Contains(),包含,完全匹配,非Like

in的语法

EFsql笔记
public static IQueryable<TEntity> In<TEntity, TValue>(this IQueryable<TEntity> source, Expression<Func<TEntity, TValue>> valueSelector, IEnumerable<TValue> values)
         {
             if (null == valueSelector) { throw new ArgumentNullException("valueSelector"); }
             if (null == values) { throw new ArgumentNullException("values"); }
             ParameterExpression p = valueSelector.Parameters.Single();
             // p => valueSelector(p) == values[0] || valueSelector(p) == ...
             if (!values.Any())
             {
                 //return e => false;
                 return source;
             }
             var equals = values.Select(value => (Expression)Expression.Equal(valueSelector.Body, Expression.Constant(value, typeof(TValue))));
             var body = equals.Aggregate<Expression>((accumulate, equal) => Expression.Or(accumulate, equal));
             return source.Where(Expression.Lambda<Func<TEntity, bool>>(body, p));
         }
EFsql笔记

 

EFsql笔记,布布扣,bubuko.com

EFsql笔记

上一篇:1.machinelearning的好伙伴numpy


下一篇:基于easyx图形库的贪吃蛇