AndAlso() 공개 정적인 메소드

Creates a BinaryExpression that represents a conditional AND operation that evaluates the second operand only if it has to.
public static AndAlso ( Expression left, Expression right ) : BinaryExpression
left Expression An to set the property equal to.
right Expression An to set the property equal to.
리턴 BinaryExpression
예제 #1
0
        /// <summary>
        /// Creates an expression that defines a logical AND function
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        public static Expression <Func <T, bool> > And <T>(this Expression <Func <T, bool> > left, Expression <Func <T, bool> > right)
        {
            var invokedExpr = XPR.Invoke(right, left.Parameters.Cast <XPR>());

            return(XPR.Lambda <Func <T, bool> >
                       (XPR.AndAlso(left.Body, invokedExpr), left.Parameters));
        }
예제 #2
0
        public static Expression <Func <T, bool> > And <T>(this Expression <Func <T, bool> > expr1,
                                                           Expression <Func <T, bool> > expr2)
        {
            var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast <Expression>());

            return(Expression.Lambda <Func <T, bool> >
                       (Expression.AndAlso(expr1.Body, invokedExpr), expr1.Parameters));
        }
        /// <inheritdoc/>
        protected override IEnumerable <Act> Query(Expression <Func <Act, bool> > query, Guid queryId, int offset, int count, out int totalResults)
        {
            var typeReference = Expression.MakeBinary(ExpressionType.Equal, Expression.Convert(Expression.MakeMemberAccess(query.Parameters[0], typeof(Act).GetProperty(nameof(Act.ClassConceptKey))), typeof(Guid)), Expression.Constant(ActClassKeys.Condition));

            var anyRef = this.CreateConceptSetFilter(ConceptSetKeys.AdverseEventActs, query.Parameters[0]);

            query = Expression.Lambda <Func <Act, bool> >(Expression.AndAlso(Expression.AndAlso(query.Body, anyRef), typeReference), query.Parameters);

            return(base.Query(query, queryId, offset, count, out totalResults));
        }
예제 #4
0
 /// <summary>
 /// 与操作表达式
 /// </summary>
 /// <param name="left">左操作数</param>
 /// <param name="right">右操作数</param>
 public static MicrosoftExpression And(this MicrosoftExpression left, MicrosoftExpression right)
 {
     if (left == null)
     {
         return(right);
     }
     if (right == null)
     {
         return(left);
     }
     return(MicrosoftExpression.AndAlso(left, right));
 }
예제 #5
0
 public void AddRestriction(Expression /*!*/ restriction)
 {
     Assert.NotNull(restriction);
     if (_treatRestrictionsAsConditions)
     {
         AddCondition(restriction);
     }
     else
     {
         _restriction = (_restriction != null) ? Ast.AndAlso(_restriction, restriction) : restriction;
     }
 }
예제 #6
0
        public void TestWhereAndOr()
        {
            var parameter = LinqExpression.Parameter(typeof(NumbersModel), "x");
            var n1        = LinqExpression.Property(parameter, "Number1");
            var n2        = LinqExpression.Property(parameter, "Number2");
            var cases     = new[] {
                Tuple.Create((LinqExpression)LinqExpression.AndAlso(LinqExpression.GreaterThan(n1, LinqExpression.Constant(3)), LinqExpression.GreaterThan(n2, LinqExpression.Constant(3))),
                             (Func <NumbersModel, object, bool>)TestWhereAndValidator, default(object), parameter),
                Tuple.Create((LinqExpression)LinqExpression.OrElse(LinqExpression.LessThan(n1, LinqExpression.Constant(3)), LinqExpression.LessThan(n2, LinqExpression.Constant(3))),
                             (Func <NumbersModel, object, bool>)TestWhereOrValidator, default(object), parameter)
            };

            LoadModelNumbers(10);
            RunTestWithNumbers(new[] { 3, 5 }, cases);
        }
        /// <summary>
        /// Query for substance administrations that aren't immunizations
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="count">The count.</param>
        /// <param name="totalResults">The total results.</param>
        /// <param name="queryId">The unique query state identifier</param>
        /// <returns>Returns the list of models which match the given parameters.</returns>
        protected override IEnumerable <SubstanceAdministration> Query(Expression <Func <SubstanceAdministration, bool> > query, Guid queryId, int offset, int count, out int totalResults)
        {
            var drugTherapy = Guid.Parse("7D84A057-1FCC-4054-A51F-B77D230FC6D1");

            var obsoletionReference = Expression.MakeBinary(ExpressionType.Equal, Expression.Convert(Expression.MakeMemberAccess(query.Parameters[0], typeof(SubstanceAdministration).GetProperty(nameof(SubstanceAdministration.StatusConceptKey))), typeof(Guid)), Expression.Constant(StatusKeys.Completed));
            var typeReference       = Expression.MakeBinary(ExpressionType.Equal, Expression.Convert(Expression.MakeMemberAccess(query.Parameters[0], typeof(SubstanceAdministration).GetProperty(nameof(SubstanceAdministration.TypeConceptKey))), typeof(Guid)), Expression.Constant(drugTherapy));

            query = Expression.Lambda <Func <SubstanceAdministration, bool> >(Expression.AndAlso(Expression.AndAlso(obsoletionReference, query.Body), typeReference), query.Parameters);

            if (queryId == Guid.Empty)
            {
                return(this.m_repository.Find(query, offset, count, out totalResults));
            }

            return((this.m_repository as IPersistableQueryRepositoryService <SubstanceAdministration>).Find(query, offset, count, out totalResults, queryId));
        }
예제 #8
0
            private static SystemExpression AndAlsoExpression(ParameterExpression parameter, IEnumerable <KendoFilter> filters)
            {
                SystemExpression body = null;

                foreach (var filter in filters)
                {
                    if (body == null)
                    {
                        body = ToExpression(parameter, filter);

                        continue;
                    }

                    body = SystemExpression.AndAlso(body, ToExpression(parameter, filter));
                }

                return(body);
            }
예제 #9
0
        private static Func <Expression, IList <ParameterExpression>, Expr> CreateCheckExprFunc(LambdaExpression checkExpr)
        {
            return
                ((valueVar, additionalParams) =>
            {
                // Prepare Length/Count expression
                var lengthExpr = Expr.Property(valueVar, valueVar.Type.HasProperty("Length") ? "Length" : "Count");

                // Use it in checkExpr
                var body = checkExpr.ReplaceParams(additionalParams).Replace(checkExpr.Parameters[0], lengthExpr);

                // Maybe add null check
                if (!valueVar.Type.IsValueType)
                {
                    body = Expr.AndAlso(Expr.ReferenceNotEqual(valueVar, Expr.Constant(null)), body);
                }

                return body;
            });
        }
예제 #10
0
 public Expression<Func<Game, bool>> Execute(Expression<Func<Game, bool>> expression)
 {
     return expression.AndAlso(g => g.Price <= _to);
 }
예제 #11
0
        // TODO: do not test runtime for runtime bound sites
        // TODO: ResolveMethod invalidates modules that were not initialized yet -> snapshot version after method resolution
        // TODO: thread safety: synchronize version snapshot and method resolution
        public void AddTargetTypeTest(object target, Expression /*!*/ targetParameter, RubyContext /*!*/ context, Expression /*!*/ contextExpression)
        {
            // singleton nil:
            if (target == null)
            {
                AddRestriction(Ast.Equal(targetParameter, Ast.Constant(null)));
                context.NilClass.AddFullVersionTest(this, contextExpression);
                return;
            }

            // singletons true, false:
            if (target is bool)
            {
                AddRestriction(Ast.AndAlso(
                                   Ast.TypeIs(targetParameter, typeof(bool)),
                                   Ast.Equal(Ast.Convert(targetParameter, typeof(bool)), Ast.Constant(target))
                                   ));

                if ((bool)target)
                {
                    context.TrueClass.AddFullVersionTest(this, contextExpression);
                }
                else
                {
                    context.FalseClass.AddFullVersionTest(this, contextExpression);
                }
                return;
            }

            RubyClass immediateClass = context.GetImmediateClassOf(target);

            // user defined instance singletons, modules, classes:
            if (immediateClass.IsSingletonClass)
            {
                AddRestriction(
                    Ast.Equal(
                        Ast.Convert(targetParameter, typeof(object)),
                        Ast.Convert(Ast.Constant(target), typeof(object))
                        )
                    );

                // we need to check for a runtime (e.g. "foo" .NET string instance could be shared accross runtimes):
                immediateClass.AddFullVersionTest(this, contextExpression);
                return;
            }

            Type type = target.GetType();

            AddTypeRestriction(type, targetParameter);

            if (typeof(IRubyObject).IsAssignableFrom(type))
            {
                // Ruby objects (get the method directly to prevent interface dispatch):
                MethodInfo classGetter = type.GetMethod("get_" + RubyObject.ClassPropertyName, BindingFlags.Public | BindingFlags.Instance);
                if (classGetter != null && classGetter.ReturnType == typeof(RubyClass))
                {
                    AddCondition(
                        // (#{type})target.Class.Version == #{immediateClass.Version}
                        Ast.Equal(
                            Ast.Call(Ast.Call(Ast.Convert(targetParameter, type), classGetter), RubyModule.VersionProperty.GetGetMethod()),
                            Ast.Constant(immediateClass.Version)
                            )
                        );
                    return;
                }

                // TODO: explicit iface-implementation
                throw new NotSupportedException("Type implementing IRubyObject should have RubyClass getter");
            }
            else
            {
                // CLR objects:
                immediateClass.AddFullVersionTest(this, contextExpression);
            }
        }
예제 #12
0
 public Expression<Func<Game, bool>> Execute(Expression<Func<Game, bool>> expression)
 {
     return expression.AndAlso(game => _publishers.Any(p => p == game.Publisher.PublisherId));
 }
예제 #13
0
 public void AddCondition(Expression /*!*/ condition)
 {
     Assert.NotNull(condition);
     _condition = (_condition != null) ? Ast.AndAlso(_condition, condition) : condition;
 }
예제 #14
0
 public Expression<Func<Game, bool>> Execute(Expression<Func<Game, bool>> expression)
 {
     return expression.AndAlso(g => g.Name.Contains(_name));
 }
예제 #15
0
 public Expression<Func<Game, bool>> Execute(Expression<Func<Game, bool>> expression)
 {
     return expression.AndAlso(g => _genres.Intersect(g.Genres.Select(x => x.GenreId)).Any());
 }
예제 #16
0
 public static Ex And(this Ex me, Ex other) => Ex.AndAlso(me, other);
예제 #17
0
 public Expression<Func<Game, bool>> Execute(Expression<Func<Game, bool>> expression)
 {
     return expression.AndAlso(game => _platformTypes.Intersect(game.PlatformTypes.Select(pt => pt.PlatformTypeId)).Any());
 }
예제 #18
0
        private void CustomersSidesForm_Shown(object sender, EventArgs e)
        {
            MiniSplash_TF sp0 = new MiniSplash_TF(Resources.load4) {Text = @"Загрузка данных абонентов"};
            sp0.WorkingFunction = () =>
            {
                sp0.StatusText = "Загрузка абонентов";
                _cachedCustomers = _dataContexts.NumEquipmentEntities.Customers.Where(cust => cust.Visible.HasValue && cust.Visible.Value).ToList();
                sp0.StatusText = "Загрузка адресов площадок";
                _cachedCustomerSides = _dataContexts.AccEquipmentV2Entities.CustomerSides.ToList();
                #region create where for phone numbers
                ParameterExpression inputType = Expression.Parameter(typeof (Teleph));
                var propertyCustomerId = Expression.Property(inputType, "Customer_Id");
                var propertyUntilDate = Expression.Property(inputType, "UntilDate");
                var propertyTelNum = Expression.Property(inputType, "TelNum");
                var currWhere = Expression.Lambda<Func<Teleph, bool>>(
                    Expression.NotEqual(
                        propertyCustomerId,
                        Expression.Constant(null, typeof (string))), inputType);
                _wherePhoneNumExpression = currWhere;
                currWhere = Expression.Lambda<Func<Teleph, bool>>(
                    Expression.NotEqual(
                        propertyUntilDate,
                        Expression.Constant(null, typeof (DateTime?))), inputType);
                _wherePhoneNumExpression = _wherePhoneNumExpression.AndAlso(currWhere);
                var trimCustomerId = Expression.Call(propertyCustomerId, typeof (string).GetMethod("Trim", Type.EmptyTypes));
                var notEmptyCustomerId = Expression.Not(Expression.Call(typeof (string), "IsNullOrEmpty", null, trimCustomerId));
                currWhere = Expression.Lambda<Func<Teleph, bool>>(notEmptyCustomerId, inputType);
                _wherePhoneNumExpression = _wherePhoneNumExpression.AndAlso(currWhere);
                var trimPhoneNumber = Expression.Call(propertyTelNum, typeof (string).GetMethod("Trim", Type.EmptyTypes));
                MethodInfo method = typeof (string).GetMethod("Contains", new[] {typeof (string)});
                var constantNumberExpression = Expression.Property(Expression.Constant(this), "NumberTextData");
                var containsPhoneNumber = Expression.Call(trimPhoneNumber, method, constantNumberExpression);
                currWhere = Expression.Lambda<Func<Teleph, bool>>(containsPhoneNumber, inputType);
                _wherePhoneNumExpression = _wherePhoneNumExpression.AndAlso(currWhere);
                #endregion
                _defaultOrder = cust => int.Parse(cust.Customer_id.Trim());
                //Expression<Func<CustomerSide, Customer, bool>>
                //    currentSideFilter = (side, customer) =>
                //        String.Equals(side.CustomerId.ToString(), customer.Customer_id.Trim()) &
                //        side.Firmid == customer.FirmId;

            };
            sp0.ShowDialog(this);
            Cursor = Cursors.WaitCursor;
            //gvCustomers.DataSource = _cachedCustomers.Where(_compiledCurrentFirmFilter).OrderBy(_defaultOrder).ToList();
            Cursor = Cursors.Default;
            //if (FocusedCustomerInfo != null)
            //{
            //    Firm custFirm = _cachedFirms.SingleOrDefault(firm => firm.FirmId == FocusedCustomerInfo.FirmId);
            //    if (custFirm == null)
            //        return;
            //    cbFirms.SelectedItem = custFirm;
            //    if (FilteredData)
            //    {
            //        gvCustomers.DataSource =
            //            _cachedCustomers.Where(_compiledCurrentFirmFilter)
            //                .Where(c => c.FirmId == FocusedCustomerInfo.FirmId & c.Customer_id.Trim() == FocusedCustomerInfo.CustomerId.ToString())
            //                .OrderBy(_defaultOrder)
            //                .ToList();
            //        gvCustomers.Rows[0].Selected = true;
            //        gvCustomers.BlinkRow(gvCustomers.Rows[0]);
            //        gvCustomers_SelectionChanged(gvCustomers, new EventArgs());
            //    }
            //    else
            //    {
            //        var selectedCustomerRow =
            //            gvCustomers.Rows.Cast<DataGridViewRow>()
            //                .SingleOrDefault(
            //                    item =>
            //                    {
            //                        Customer checkCustomer = (Customer)item.DataBoundItem;
            //                        return (Convert.ToInt32(checkCustomer.Customer_id.Trim()) == FocusedCustomerInfo.CustomerId) & (checkCustomer.FirmId == FocusedCustomerInfo.FirmId);
            //                    });
            //        if (selectedCustomerRow != null)
            //        {
            //            gvCustomers.CurrentCell = gvCustomers.Rows[selectedCustomerRow.Index].Cells[0];
            //            selectedCustomerRow.Selected = true;
            //            gvCustomers.BlinkRow(selectedCustomerRow);
            //        }
            //    }
            //    if (FocusedSide != null)
            //    {
            //        var selectedCustomerSideRow =
            //            gvSides.Rows.Cast<DataGridViewRow>()
            //                .SingleOrDefault(
            //                    item =>
            //                    {
            //                        CustomerSide checkSide = (CustomerSide)item.DataBoundItem;
            //                        return checkSide.Id == FocusedSide.Id;
            //                    });
            //        if (selectedCustomerSideRow != null)
            //        {
            //            gvSides.CurrentCell = gvSides.Rows[selectedCustomerSideRow.Index].Cells[0];
            //            selectedCustomerSideRow.Selected = true;
            //            gvSides.BlinkRow(selectedCustomerSideRow);
            //        }
            //    }
            //}
        }
예제 #19
0
 protected override BinaryExpression CreateBody(Expression left, Expression right)
 {
     return(Expression_.AndAlso(left, right));
 }
예제 #20
0
        public static Expression CreateLambdaExpression <T, TModel>(IEnumerable <FilterElement> filterElements, Type querytype, ParameterExpression arg)
        {
            Expression expression = Expression.Constant(true);

            foreach (var filterElement in filterElements)
            {
                string[]   props = filterElement.FilterSpecs.DataElement.Split('.');
                Expression propertyExpression = arg;
                var        type = typeof(T);

                Expression notNullExpression = Expression.Constant(true);

                foreach (var property in  props)
                {
                    PropertyInfo pi = type.GetProperty(property);
                    propertyExpression = Expression.Property(propertyExpression, pi);
                    var nullExpression = Expression.Constant(GetNullExpressionForType(pi.PropertyType), pi.PropertyType);
                    notNullExpression = Expression.AndAlso(notNullExpression, Expression.NotEqual(propertyExpression, nullExpression));
                    type = pi.PropertyType;
                }

                var isLiteralType = type.IsEquivalentTo(typeof(string));

                var valueExpression = Expression.Constant(filterElement.FieldValue, filterElement.Property.PropertyType);

                Expression inputExpression, variableExpression;
                if (filterElement.FilterSpecs.CaseSensitive && isLiteralType)
                {
                    variableExpression = Expression.Call(propertyExpression,
                                                         typeof(String).GetMethod("ToUpper", new Type[] { }));

                    inputExpression = Expression.Call(valueExpression,
                                                      typeof(String).GetMethod("ToUpper", new Type[] { }));
                }
                else
                {
                    // special case to handle nullable values
                    if (valueExpression.Type.IsNullable())
                    {
                        valueExpression = Expression.Constant(valueExpression.Value, filterElement.Property.PropertyType.NullableOf());
                    }


                    inputExpression    = valueExpression;
                    variableExpression = propertyExpression;
                }

                BinaryExpression conditionExpression = Expression.Equal(variableExpression, valueExpression);

                switch (filterElement.FilterSpecs.OperatorOption)
                {
                case Operator.Equal:
                    conditionExpression = Expression.Equal(variableExpression, inputExpression);
                    break;

                case Operator.GreaterThan:
                    conditionExpression = Expression.GreaterThan(variableExpression, inputExpression);
                    break;

                case Operator.GreaterThanOrEqualTo:
                    conditionExpression = Expression.GreaterThanOrEqual(variableExpression, inputExpression);
                    break;

                case Operator.LessThan:
                    conditionExpression = Expression.LessThan(variableExpression, inputExpression);
                    break;

                case Operator.LessThanOrEqualTo:
                    conditionExpression = Expression.LessThanOrEqual(variableExpression, inputExpression);
                    break;

                case Operator.Unequal:
                    conditionExpression = Expression.NotEqual(variableExpression, inputExpression);
                    break;

                case Operator.Like:
                    MethodInfo method             = typeof(string).GetMethod("Contains", new[] { typeof(string) });
                    var        containsMethodCall = Expression.Call(variableExpression, method, inputExpression);
                    conditionExpression = Expression.Equal(containsMethodCall, Expression.Constant(true));
                    break;
                }


                var clausePart = Expression.AndAlso(notNullExpression, conditionExpression);

                if (!filterElement.FieldValue.Equals(GetNullExpressionForType(filterElement.Property.PropertyType)))
                {
                    expression = Expression.AndAlso(expression, clausePart);
                }
            }

            return(expression);
        }
예제 #21
0
 public Expression<Func<Game, bool>> Execute(Expression<Func<Game, bool>> expression)
 {
     DateTime filterTime = DateTime.UtcNow.AddDays(-_days);
     return expression.AndAlso( g => g.PublicationDate >= filterTime );
 }
예제 #22
0
 public static BinaryExpression and(XPR left, XPR right)
 => XPR.AndAlso(left, right);
예제 #23
0
 public static BinaryExpression AndAlso(Expression left, Expression right) => Expression.AndAlso(left, right);
예제 #24
0
 public static BinaryExpression AndAlso(Expression left, Expression right, MethodInfo method) => Expression.AndAlso(left, right, method);
        private BinaryExpression BinaryExpression(
            ExpressionType nodeType, System.Type type, JObject obj)
        {
            var left       = this.Prop(obj, "left", this.Expression);
            var right      = this.Prop(obj, "right", this.Expression);
            var method     = this.Prop(obj, "method", this.Method);
            var conversion = this.Prop(obj, "conversion", this.LambdaExpression);
            var liftToNull = this.Prop(obj, "liftToNull").Value <bool>();

            switch (nodeType)
            {
            case ExpressionType.Add: return(Expr.Add(left, right, method));

            case ExpressionType.AddAssign: return(Expr.AddAssign(left, right, method, conversion));

            case ExpressionType.AddAssignChecked: return(Expr.AddAssignChecked(left, right, method, conversion));

            case ExpressionType.AddChecked: return(Expr.AddChecked(left, right, method));

            case ExpressionType.And: return(Expr.And(left, right, method));

            case ExpressionType.AndAlso: return(Expr.AndAlso(left, right, method));

            case ExpressionType.AndAssign: return(Expr.AndAssign(left, right, method, conversion));

            case ExpressionType.ArrayIndex: return(Expr.ArrayIndex(left, right));

            case ExpressionType.Assign: return(Expr.Assign(left, right));

            case ExpressionType.Coalesce: return(Expr.Coalesce(left, right, conversion));

            case ExpressionType.Divide: return(Expr.Divide(left, right, method));

            case ExpressionType.DivideAssign: return(Expr.DivideAssign(left, right, method, conversion));

            case ExpressionType.Equal: return(Expr.Equal(left, right, liftToNull, method));

            case ExpressionType.ExclusiveOr: return(Expr.ExclusiveOr(left, right, method));

            case ExpressionType.ExclusiveOrAssign: return(Expr.ExclusiveOrAssign(left, right, method, conversion));

            case ExpressionType.GreaterThan: return(Expr.GreaterThan(left, right, liftToNull, method));

            case ExpressionType.GreaterThanOrEqual: return(Expr.GreaterThanOrEqual(left, right, liftToNull, method));

            case ExpressionType.LeftShift: return(Expr.LeftShift(left, right, method));

            case ExpressionType.LeftShiftAssign: return(Expr.LeftShiftAssign(left, right, method, conversion));

            case ExpressionType.LessThan: return(Expr.LessThan(left, right, liftToNull, method));

            case ExpressionType.LessThanOrEqual: return(Expr.LessThanOrEqual(left, right, liftToNull, method));

            case ExpressionType.Modulo: return(Expr.Modulo(left, right, method));

            case ExpressionType.ModuloAssign: return(Expr.ModuloAssign(left, right, method, conversion));

            case ExpressionType.Multiply: return(Expr.Multiply(left, right, method));

            case ExpressionType.MultiplyAssign: return(Expr.MultiplyAssign(left, right, method, conversion));

            case ExpressionType.MultiplyAssignChecked: return(Expr.MultiplyAssignChecked(left, right, method, conversion));

            case ExpressionType.MultiplyChecked: return(Expr.MultiplyChecked(left, right, method));

            case ExpressionType.NotEqual: return(Expr.NotEqual(left, right, liftToNull, method));

            case ExpressionType.Or: return(Expr.Or(left, right, method));

            case ExpressionType.OrAssign: return(Expr.OrAssign(left, right, method, conversion));

            case ExpressionType.OrElse: return(Expr.OrElse(left, right, method));

            case ExpressionType.Power: return(Expr.Power(left, right, method));

            case ExpressionType.PowerAssign: return(Expr.PowerAssign(left, right, method, conversion));

            case ExpressionType.RightShift: return(Expr.RightShift(left, right, method));

            case ExpressionType.RightShiftAssign: return(Expr.RightShiftAssign(left, right, method, conversion));

            case ExpressionType.Subtract: return(Expr.Subtract(left, right, method));

            case ExpressionType.SubtractAssign: return(Expr.SubtractAssign(left, right, method, conversion));

            case ExpressionType.SubtractAssignChecked: return(Expr.SubtractAssignChecked(left, right, method, conversion));

            case ExpressionType.SubtractChecked: return(Expr.SubtractChecked(left, right, method));

            default: throw new NotSupportedException();
            }
        }
예제 #26
0
        private static Exp CreateSubExpression(Exp pe, Type type, string text, FullTextSearchOptions options, bool isQueriable = false)
        {
            var texts = text.Split(new string[] { "||" }, StringSplitOptions.RemoveEmptyEntries)
                        .Select(t => t.Trim().ToLower())
                        .Where(t => t.Length > 0)
                        .ToList();

            var properties = type.GetProperties().AsEnumerable();

            if (isQueriable)
            {
                properties = properties.GetMappedProperties();
            }

            Exp predicateBody = null;

            foreach (var prop in properties)
            {
                //Check if we can use this property in Search
                if (options == null || options.Filter == null || options.Filter.Invoke(prop))
                {
                    var paramExp = Exp.Property(pe, prop);

                    if (prop.PropertyType == typeof(string) || prop.PropertyType == typeof(int) ||
                        prop.PropertyType == typeof(int?))
                    {
                        Exp notNullExp = null;
                        if (prop.PropertyType == typeof(string))
                        {
                            Exp nullConst = Exp.Constant(null, typeof(string));
                            notNullExp = Exp.NotEqual(paramExp, nullConst);
                        }

                        Exp toStringExp = paramExp;
                        //Check if property has int type
                        if (prop.PropertyType == typeof(int?) || prop.PropertyType == typeof(int))
                        {
                            if (!isQueriable)
                            {
                                Exp toNullableIntExp = null;

                                //property should be nullable
                                if (prop.PropertyType == typeof(int))
                                {
                                    toNullableIntExp = Exp.TypeAs(paramExp, typeof(int?));
                                }

                                Exp valueExp = null;
                                if (toNullableIntExp != null)
                                {
                                    notNullExp = Exp.Property(toNullableIntExp, "HasValue");
                                    valueExp   = Exp.Property(toNullableIntExp, "Value");
                                }
                                else
                                {
                                    notNullExp = Exp.Property(paramExp, "HasValue");
                                    valueExp   = Exp.Property(paramExp, "Value");
                                }

                                notNullExp = Exp.Equal(notNullExp, Exp.Constant(true, typeof(bool)));

                                var convertToString = typeof(Convert).GetMethod("ToString", new[] { typeof(int) });
                                toStringExp = Exp.Call(convertToString, valueExp);
                            }
                            else
                            {
                                var convertToString = typeof(Convert).GetMethod("ToString", new[] { typeof(int) });
                                toStringExp = Exp.Call(convertToString, Exp.Convert(paramExp, typeof(int)));
                            }
                        }

                        Exp peLower = Exp.Call(toStringExp, typeof(string).GetMethod("ToLower", System.Type.EmptyTypes));

                        Exp conditionExp = null;
                        foreach (var txt in texts)
                        {
                            var constant    = Exp.Constant(txt, typeof(string));
                            Exp containsExp = Exp.Call(peLower, typeof(string).GetMethod("Contains", new[] { typeof(string) }), constant);
                            if (conditionExp != null)
                            {
                                conditionExp = Exp.OrElse(conditionExp, containsExp);
                            }
                            else
                            {
                                conditionExp = containsExp;
                            }
                        }

                        Exp andExp = (notNullExp != null) ? Exp.AndAlso(notNullExp, conditionExp) : conditionExp;
                        if (predicateBody != null)
                        {
                            predicateBody = Exp.OrElse(predicateBody, andExp);
                        }
                        else
                        {
                            predicateBody = andExp;
                        }
                    }

                    //If this property is't simple and the depth > 0
                    if (options != null && options.Depth != 0 &&
                        !prop.PropertyType.IsSimpleType() && !prop.PropertyType.IsEnumerable())
                    {
                        options.Depth -= 1;
                        var subExp = CreateSubExpression(paramExp, prop.PropertyType, text, options, isQueriable);
                        options.Depth += 1;

                        if (subExp != null)
                        {
                            Exp notNullExp = Exp.NotEqual(paramExp, Exp.Constant(null, typeof(object)));
                            subExp        = Exp.AndAlso(notNullExp, subExp);
                            predicateBody = (predicateBody != null) ? Exp.OrElse(predicateBody, subExp) : subExp;
                        }
                    }
                }
            }

            return(predicateBody);
        }