Page view counter
LINQ: Pass parameter to query Subscribe to this thread
Last post 07-05-2008 10:34 PM by mchlSync. 2 replies.
Sort Posts:
07-05-2008 3:46 PM
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?

Apples

Loading...
Joined on 01-10-2008
Posts 21
07-05-2008 7:24 PM
Marked as Answer
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 2 and 3 Workshop
Boston, MA: April 29 - May 1
Washington, DC: June 16-18th
http://silverlight-tour.com

swildermuth

Loading...
Joined on 10-13-2003
Atlanta, GA
Posts 1,538
07-05-2008 10:34 PM
Marked as Answer
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!)

Best Regards,
Michael Sync

Microsoft WPF & Silverlight Insider
Blog : http://michaelsync.net


mchlSync

Loading...
Joined on 09-16-2005
Singapore
Posts 2,478
Microsoft Communities