ef where 动态添加多个Lambda表达式

            ParameterExpression c = Expression.Parameter(typeof(Pic), "c");
            Expression condition = Expression.Constant(false);
            Expression<Func<Pic, bool>> end;
            if (search != "" && search != null)
            {
                string[] b = search.Split('^');
                foreach (string s in b)
                {
                    if (s != null && s != "")
                    {
                        string[] e = s.Split('&');
                        if (e[1] != null && e[1] != "")
                        {
                            Expression con = Expression.Call(
                                Expression.Property(c, typeof(Pic).GetProperty(e[0].ToString())),
                                typeof(string).GetMethod("Equals", new Type[] { typeof(string) }),
                                Expression.Constant(e[1].ToString()));
                            condition = Expression.Or(con, condition);
                        }
                    }
                }
                end =
                   Expression.Lambda<Func<Pic, bool>>(condition, new ParameterExpression[] { c });
            }
            else
            {
                end = s => 1 == 1;
            }

 

posted @ 2013-12-06 19:33  zhushang  阅读(1480)  评论(0)    收藏  举报