Skip to main content

Microsoft Silverlight

Answered Question LINQ: Pass parameter to queryRSS Feed

(0)

Apples
Apples

Member

Member

4 points

21 Posts

LINQ: Pass parameter to query

I have a couple checkbox on my Page.xaml page.  I'm pulling data from the DB and I'd like it to be filtered based on what is checked.  I'm passing a list of strings containing the content of the checkboxes that were checked.  But I don't know how to pass the list to the query.  Here's what I have:

Page.xaml.cs:

        List<string> checks = new List<string>();
       
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            foreach (Control c in mainCanvas.Children)
            {
                if(c is CheckBox)
                {
                    CheckBox chk = (CheckBox)c;
                    if(chk.IsChecked == true)
                        checks.Add(chk.Content.ToString());
                }
            }

            ServiceReference1.Service1Client client =
                new SmoothFusion.ServiceReference1.Service1Client();
           
            client.GetPhotosCompleted += new EventHandler<SmoothFusion.ServiceReference1.GetPhotosCompletedEventArgs>(client_GetPhotosCompleted);
            client.GetPhotosAsync();
        }

        void client_GetPhotosCompleted(object sender, SmoothFusion.ServiceReference1.GetPhotosCompletedEventArgs e)
        {
            listBox.ItemsSource = e.Result;
        }

 

IService1.cs:

    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        List<Pic> GetPhotos(List<string> checks);
    }

 

Service1.svc.cs:

    public class Service1 : IService1
    {
        #region IService1 Members

        public List<Pic> GetPhotos(List<string> checks)
        {
            DataClasses1DataContext db = new DataClasses1DataContext();

            var query = from attr in db.Attributes
                        where checks.Contains(attr.Attribute1)
                        select attr.AttributeID;


            return query.ToList();
        }

        #endregion
    }

 

The problem is that the query to pull the data is in the Web portion of my project, and the list of checkboxes is in the other part.  So how can I pass my list?

swildermuth
swildermuth

Star

Star

8320 points

1,546 Posts

Answered Question

Re: LINQ: Pass parameter to query

You'll need to pass the state of the check(s) via the GetPhoto's Web Service (adding a parameter there that you'll use in the LINQ query).

(If this has answered your question, "Mark as Answer")

Shawn Wildermuth
C# MVP, MCSD, Speaker and Author

Silverlight 3 Workshop
Miami, FL: Oct 12-14th
Portlant, OR: Dec 2-4th
Atlanta, GA: Dec 7-9th
http://silverlight-tour.com

mchlsync
mchlsync

Star

Star

14566 points

2,730 Posts

Silverlight MVP
Answered Question

Re: LINQ: Pass parameter to query

Apples:
client.GetPhotosAsync();
 

I think this is not correct. It should be like client.GetPhotoAsync(checks); 

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Regards,
Michael Sync
Silverlight MVP

Blog : http://michaelsync.net


  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities