コード例 #1
0
        public Expression <Func <User, bool> > GetUserExpression(SearchUserVm templateUser)
        {
            ExpressionStarter <User> userCondition = PredicateBuilder.New <User>();

            if (!string.IsNullOrWhiteSpace(templateUser.NameFirst))
            {
                userCondition = userCondition.And(user => user.NameFirst.ToLower() == templateUser.NameFirst.ToLower());
            }
            if (!string.IsNullOrWhiteSpace(templateUser.NameSecond))
            {
                userCondition = userCondition.And(user => user.NameSecond.ToLower() == templateUser.NameSecond.ToLower());
            }
            if (!string.IsNullOrWhiteSpace(templateUser.City))
            {
                userCondition = userCondition.And(user => user.City.ToLower() == templateUser.City.ToLower());
            }
            if (!string.IsNullOrWhiteSpace(templateUser.Country))
            {
                userCondition = userCondition.And(user => user.Country.ToLower() == templateUser.Country.ToLower());
            }
            if (templateUser.Birthday != null)
            {
                userCondition = userCondition.And(user => user.Birthday == templateUser.Birthday);
            }
            if (templateUser.Tag != null)
            {
                userCondition = userCondition.And(user => user.Tag == templateUser.Tag);
            }
            return((Expression <Func <User, bool> >)userCondition.Expand());
        }
コード例 #2
0
        public Expression <Func <Channel, bool> > GetChannelExpression(string query)
        {
            ExpressionStarter <Channel> chatCondition = PredicateBuilder.New <Channel>();
            string lowerQuery = query.ToLowerInvariant();

            chatCondition = chatCondition.Or(chat => chat.SearchVector.Matches(EF.Functions.PhraseToTsQuery("simple", query)));
            return((Expression <Func <Channel, bool> >)chatCondition.Expand());
        }
コード例 #3
0
        public Expression <Func <User, bool> > GetUserExpression(string query)
        {
            ExpressionStarter <User> userCondition = PredicateBuilder.New <User>();
            string lowerQuery = query.ToLowerInvariant();

            userCondition = userCondition.Or(user =>
                                             user.Phones.Any(opt => opt.PhoneNumber == query) ||
                                             user.Emails.Any(opt => opt.EmailAddress.ToLower() == query.ToLowerInvariant()) ||
                                             user.SearchVector.Matches(EF.Functions.PhraseToTsQuery("simple", query)));
            return((Expression <Func <User, bool> >)userCondition.Expand());
        }
コード例 #4
0
        public Expression <Func <Chat, bool> > GetChatExpression(SearchChatVm templateChat)
        {
            ExpressionStarter <Chat> chatCondition = PredicateBuilder.New <Chat>();

            if (!string.IsNullOrWhiteSpace(templateChat.Name))
            {
                chatCondition = chatCondition.And(chat => chat.Name.ToLower() == templateChat.Name.ToLower());
            }
            if (templateChat.Tag != null)
            {
                chatCondition = chatCondition.And(chat => chat.Tag == templateChat.Tag);
            }
            return((Expression <Func <Chat, bool> >)chatCondition.Expand());
        }
コード例 #5
0
        public void ExpressionStarter_CanBeAssignedFromExpression()
        {
            ExpressionStarter <string> predicate = (Expression <Func <string, bool> >)(s => s == "a");

            Assert.Equal("s => (s == \"a\")", predicate.Expand().ToString());
        }
コード例 #6
0
        public void ExpressionStarter_Null()
        {
            ExpressionStarter <string> predicate = null;

            Assert.Null(predicate.Expand());
        }