Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1041485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:21:36+00:00 2026-05-16T15:21:36+00:00

I am using SL 4, WCF RIA Services against Entity Framework 4.0. I have

  • 0

I am using SL 4, WCF RIA Services against Entity Framework 4.0. I have an Entity, Visit, that has a string Status field. I have a search screen where I need to display results that have StatusA or StatusB. I am struggling to find a way to specify a client-side query that specifies a collection of statuses that should be matched. If I was to write what I want in SQL it would look something like:

select * from Visit where Status in ('StatusA', 'StatusB');

Client side, it appears to be straightforward to chain Where methods for a WhereAnd effect:

        var query = this.PqContext.GetVisitsQuery();

        if (!string.IsNullOrEmpty(this.PracticeName))
        {
            query = query.Where(v => v.PracticeName.ToUpper().Contains(this.PracticeName.ToUpper()));
        }

        if (this.VisitDateAfter.HasValue)
        {
            query = query.Where(v => v.VisitDate > this.VisitDateAfter);
        }

        if (this.VisitDateBefore.HasValue)
        {
            query = query.Where(v => v.VisitDate < this.VisitDateBefore);
        }

However, I can’t seem to find a straightforward way to do a WhereOr style operation. I have tried this:

        var statuses = new List<string>();

        if (this.ShowStatusA)
        {
            statuses.Add("StatusA");
        }

        if (this.ShowStatusB)
        {
            statuses.Add("StatusB");
        }

        if (statuses.Any())
        {
            query = query.Where(BuildContainsExpression<Visit, string>(e => e.Status, statuses));
        }

Where BuildContainsExpression looks like:

        private static Expression<Func<TElement, bool>> BuildContainsExpression<TElement, TValue>(Expression<Func<TElement, TValue>> valueSelector, IEnumerable<TValue> values)
    {

        if (null == valueSelector)
        {
            throw new ArgumentNullException("valueSelector");
        }

        if (null == values)
        {
            throw new ArgumentNullException("values");
        }

        ParameterExpression p = valueSelector.Parameters.Single();
        if (!values.Any())
        {
            return e => false;
        }

        var equals =
            values.Select(
                value =>
                (Expression)Expression.Equal(valueSelector.Body, Expression.Constant(value, typeof(TValue))));

        var body = equals.Aggregate<Expression>(Expression.Or);

        return Expression.Lambda<Func<TElement, bool>>(body, p);
    }

But this throws a “Bitwise operators are not supported in queries.” exception. Any clues? Is there an alternative way to build an expression tree that works here or do I need to pass all the parameters over to the server and use the BuildContainsExpression there?

Your time and your guidance are much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:21:36+00:00Added an answer on May 16, 2026 at 3:21 pm

    You can create a query method such as the following in your domain service:

    GetVisitsByStatus(string[] statusList) {
      // create the LINQ where clause here
    }
    

    And then from the client, call context.GetVistsByStatusQuery(string[]).

    Not all of LINQ is (or even can) be exposed over the URL, so there are always cases where you need to use simple parameters, and have the middle tier construct the LINQ expressions that eventually define the query that goes to the back-end data store.

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.