locked
preprocess query help RRS feed

  • Question

  • Hello,

    This should be easy but my brain is failing me this morning.  I am building a custom filter using preprocess query so that I can filter a parent collection (Orders) by the properties of its children (LineItems).  My query has an optional string parameter (SearchTerm).  The query ultimately needs to return the results, if any, from each of these expressions.  How do I execute each one and capture its results and return them all?

    public partial class ApplicationDataService { partial void OrderSearch_PreprocessQuery(string SearchTerm, ref IQueryable<Order> query) { if (!String.IsNullOrEmpty(SearchTerm)) {

    // Need the results of each of these expressions query = query.Where(o => o.OrderNumber.Contains(SearchTerm)); query = query.Where(o => o.Customer.Contains(SearchTerm)); query = query.Where(o => o.LineItems.Any(p => p.ProjectNumber.Contains(SearchTerm))); query = query.Where(o => o.LineItems.Any(a => a.AccountNumber.Contains(SearchTerm))); } } }



    Sunday, March 2, 2014 6:02 PM

Answers

  • Amazing what a good cup of coffee can do.  Duh! 

    public partial class ApplicationDataService
        {
            partial void OrderSearch_PreprocessQuery(string SearchTerm, ref IQueryable<Order> query)
            {
                if (!String.IsNullOrEmpty(SearchTerm))
                {
                    query = query.Where(o => o.OrderNumber.Contains(SearchTerm) ||
                    (o.Customer.Contains(SearchTerm)) ||
                    (o.LineItems.Any(p => p.ProjectNumber.Contains(SearchTerm))) ||
                    (o.LineItems.Any(a => a.AccountNumber.Contains(SearchTerm))));
    
                    // LOL wake up!
    
                    //query = query.Where(o => o.OrderNumber.Contains(SearchTerm));
    
                    //query = query.Where(o => o.Customer.Contains(SearchTerm));
    
                    //query = query.Where(o => o.LineItems.Any(p => p.ProjectNumber.Contains(SearchTerm)));
    
                    //query = query.Where(o => o.LineItems.Any(a => a.AccountNumber.Contains(SearchTerm)));
    
                }
            }

    • Marked as answer by Hessc Sunday, March 2, 2014 6:54 PM
    Sunday, March 2, 2014 6:54 PM

All replies

  • Amazing what a good cup of coffee can do.  Duh! 

    public partial class ApplicationDataService
        {
            partial void OrderSearch_PreprocessQuery(string SearchTerm, ref IQueryable<Order> query)
            {
                if (!String.IsNullOrEmpty(SearchTerm))
                {
                    query = query.Where(o => o.OrderNumber.Contains(SearchTerm) ||
                    (o.Customer.Contains(SearchTerm)) ||
                    (o.LineItems.Any(p => p.ProjectNumber.Contains(SearchTerm))) ||
                    (o.LineItems.Any(a => a.AccountNumber.Contains(SearchTerm))));
    
                    // LOL wake up!
    
                    //query = query.Where(o => o.OrderNumber.Contains(SearchTerm));
    
                    //query = query.Where(o => o.Customer.Contains(SearchTerm));
    
                    //query = query.Where(o => o.LineItems.Any(p => p.ProjectNumber.Contains(SearchTerm)));
    
                    //query = query.Where(o => o.LineItems.Any(a => a.AccountNumber.Contains(SearchTerm)));
    
                }
            }

    • Marked as answer by Hessc Sunday, March 2, 2014 6:54 PM
    Sunday, March 2, 2014 6:54 PM