Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

how to structure a linq query based on different checkbox and conditions

$
0
0

Hi, I have search functionality that displays the result in the datagrid. As you can see the below, I have 3 conditions, two of them comes with "contains, start with, exact with", and each section is enabled by the checkbox, so that use could do the search. I am wondering how I can run the linq query to have them all included or section by section, so far I am thinking to use if condition, but any better suggestions?

 private bool _casenumberisSelected;
        public bool CaseIsSelected
        {
            get { return _casenumberisSelected; }
            set { _casenumberisSelected = value; NoticeMe(""); }
        }

        private bool _dateisSelected;
        public bool DateIsSelected
        {
            get { return _dateisSelected; }
            set { _dateisSelected = value; NoticeMe(""); }
        }

        private bool _sessionisSelected;
        public bool SessionIsSelected
        {
            get { return _sessionisSelected; }
            set { _sessionisSelected = value; NoticeMe(""); }
        }

  public void Search()
        {
            if (CaseIsSelected == true)
            {
                using (var context = new CourtFLOWEntities())
                {
                    switch (combotext)
                    {
                        case "Contains...":
                            var result = from tran in context.TRANDEFs
                                         where tran.COURTCASENUMBER.Contains(text)
                                         select tran;
                            Collection.Source = result.ToList();
                            break;
                        case "Starts With...":
                            var result2 = from tran in context.TRANDEFs
                                          where tran.COURTCASENUMBER.StartsWith(text)
                                          select tran;
                            Collection.Source = result2.ToList();
                            break;
                        case "Exact Match...":
                            var result3 = from tran in context.TRANDEFs
                                          where tran.COURTCASENUMBER == text
                                          select tran;
                            Collection.Source = result3.ToList();
                            break;
                    }
                }

            }

        }


Viewing all articles
Browse latest Browse all 18858

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>