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 7086715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:35:04+00:00 2026-05-28T07:35:04+00:00

In my Windows Phone Mango app, I have a bunch of checkboxes, each corresponding

  • 0

In my Windows Phone Mango app, I have a bunch of checkboxes, each corresponding to a day of the week. I want to filter the data I query by which checkboxes are checked. Here’s what I’ve come up with, but I feel like there’s a better solution:

Declare the checkboxes in XAML:

            <CheckBox Content="Mon" x:Name="MonCheckbox" Checked="DayCheckbox_Tap" Unchecked="DayCheckbox_Tap"/>
            <CheckBox Content="Tue" x:Name="TueCheckbox" Grid.Column="1" Checked="DayCheckbox_Tap" Unchecked="DayCheckbox_Tap" />
            <CheckBox Content="Wed" x:Name="WedCheckbox" Grid.Column="2" Checked="DayCheckbox_Tap" Unchecked="DayCheckbox_Tap" />
            <CheckBox Content="Thur" x:Name="ThurCheckbox"  Grid.Row="1" Checked="DayCheckbox_Tap" Unchecked="DayCheckbox_Tap" />
            <CheckBox Content="Fri" x:Name="FriCheckbox" Grid.Row="1" Grid.Column="1" Checked="DayCheckbox_Tap" Unchecked="DayCheckbox_Tap" />
            <CheckBox Content="Sat" x:Name="SatCheckbox" Grid.Row="1" Grid.Column="2" Checked="DayCheckbox_Tap" Unchecked="DayCheckbox_Tap" />
            <CheckBox Content="Sun" x:Name="SunCheckbox" Grid.Row="2" Grid.Column="0" Checked="DayCheckbox_Tap" Unchecked="DayCheckbox_Tap" />

Associate a day with each checkbox:

    public MainPage()
    {
        InitializeComponent();

        LayoutRoot.DataContext = this;

        // This is grossly imperative. Can it be done in XAML?
        MonCheckbox.Tag = DayOfWeek.Monday;
        TueCheckbox.Tag = DayOfWeek.Tuesday;
        WedCheckbox.Tag = DayOfWeek.Wednesday;
        ThurCheckbox.Tag = DayOfWeek.Thursday;
        FriCheckbox.Tag = DayOfWeek.Friday;
        SatCheckbox.Tag = DayOfWeek.Saturday;
        SunCheckbox.Tag = DayOfWeek.Sunday;

        // ...
    }

Maintain a collection of the currently selected days:

    ICollection<DayOfWeek> _selectedDays = new Collection<DayOfWeek>();

    private void DayCheckbox_Tap(object sender, RoutedEventArgs e)
    {
        CheckBox checkbox = (CheckBox)sender;
        if (_selectedDays.Contains((DayOfWeek)checkbox.Tag))
        {
            _selectedDays.Remove((DayOfWeek)checkbox.Tag);
        }
        else
        {
            _selectedDays.Add((DayOfWeek)checkbox.Tag);
        }

        refreshCheckinData();
    }

The problem comes when I go to refresh the data that’s displayed to the user:

    private void refreshCheckinData()
    {
        Checkins.Clear();
        Checkins.AddAll(from checkin in checkinData.Items
                        where _selectedDays.Contains(checkin.DateTime.DayOfWeek)
                        select checkin);
    }

public static class ExtensionMethods
{
    public static void AddAll<T>(this ICollection<T> dest, IEnumerable<T> source)
    {
        if (dest == null)
        {
            throw new ArgumentNullException("dest");
        }

        foreach (T t in source)
        {
            dest.Add(t);
        }
    }
}

When the code tries to iterate over source in AddAll(), the following exception occurs:

Method 'Boolean Contains(System.DayOfWeek)' has no supported translation to SQL."   System.Exception {System.NotSupportedException}

How can I get around this? Why does Contains require a SQL translation? Is there a better approach to this whole thing, using more declarative XAML and less imperative code-behind?

Update: I tried changing the query to:

where _selectedDays.Any(day => day == checkin.DateTime.DayOfWeek)

now I get the following error:

"Local sequence cannot be used in LINQ to SQL implementations of query operators except the Contains operator." System.Exception {System.NotSupportedException}

_selectedDays is defined in memory. why does it need to be translated to SQL?

  • 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-28T07:35:04+00:00Added an answer on May 28, 2026 at 7:35 am

    Your original query is close. I think the Contains() method on ICollection is getting in the way of the SQL translator — I would need to double check the code to be sure.

    You can work around this by forcing selection of the Enumerable.Contains() extension method by changing your code to this:

        private void refreshCheckinData()
    {
        Checkins.Clear();
        Checkins.AddAll(from checkin in checkinData.Items
                        where _selectedDays.AsEnumerable().Contains(checkin.DateTime.DayOfWeek)
                        select checkin);
    }
    

    Enumerable.Contains(T) extension method will translate into an IN clause in the database.

    The resulting query will be something like this:
    SELECT [t0].[Key], [t0].[Day]
    FROM [Stuff] AS [t0]
    WHERE [t0].[Day] IN (@p0, @p1)

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

Sidebar

Related Questions

I'm writing a Windows Phone Mango app. I have a hyperlink that contains email
I have a background agent and a foreground app on Windows Phone Mango. (These
For my Windows Phone Mango app, I want to make overlay a heatmap on
I have a strange problem with a Windows Phone (7.1/Mango) app. My understanding is
Windows Phone 7.1/7.5/Mango app. I have four different MediaElements on the page. One is
I have created an windows phone 7 app. I need to test it in
I want my windows phone app to communicate with a desktop app (in Windows),
I have a Windows Phone 7.5/Silverlight app. I have some code that I duplicate
Windows Phone 7.1/7.5/Mango Silverlight App. Coming from here: Need clarification on using audio on
In Windows Phone (mango) I am using Microsoft.Phone.Controls.Maps. I currently have: var _City =

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.