码迷,mamicode.com
首页 > 数据库 > 详细

EFsql笔记

时间:2014-06-05 18:27:42      阅读:324      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   java   

like的语法

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

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

in的语法

bubuko.com,布布扣
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));
         }
bubuko.com,布布扣

 

EFsql笔记,布布扣,bubuko.com

EFsql笔记

标签:c   style   class   blog   code   java   

原文地址:http://www.cnblogs.com/juexin/p/3768571.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!