Changing Search Filters

Mar 4, 2010 at 6:01 PM

Hi,

I am trying to change the search query filters, but am pretty new to LINQ so I am having some difficulty figuring out how to add a sub-query to it.

I basically want to be able to search by sub-groups with the same name, without selecting a group category.  So i can to search by sub_unit_name instead of ID. I'm not sure if this change should go in an overloaded GetTickets function or in the search function.  (I want the search to stay as it is not if a group is selected.)  Any thoughts or suggestions?

 

This code doesn't seem to work.  Unfornitly I have a SQL expression install right now and don't have access to SQL profiler so I can't see the SQL this is executing to know why I am getting no results.

public static IEnumerable<ticket> GetTickets(stDataContext db,string subgroup, bool? active)
        {
            var results = from p in db.tickets
                   where
                       (active == null ? true :
                       ((bool)active ? p.active : !p.active)) &&
                       p.sub_unit == db.sub_units.Where(c=>subgroup.Contains(c.sub_unit_name))
                   select p;
            return results;
        }
Coordinator
Mar 19, 2010 at 4:50 AM

I can't really tell what you are trying to do here, can you explain?

What I always do is try step by step, building one more piece until you understand what/why you are getting what you are getting.

Mar 19, 2010 at 6:30 PM

Sorry this was outdated and I never updated it.

We want to be able to create sub-groups that have the same name as other sub groups.

Say we have

Groups:

 Engineering

Operations

each with the subgroups

A

B

I want to be able to search for all tickets in the sub-groups A or B reguarless of which group they are in.  (The search page doesn't even pull back sub-groups in the release code unless you select a group.)

 I managed to figure out how to change the query.   Also notice that I removed all the ternary operation, I think your going a little too much work in this fuction.

 

 public static IEnumerable<ticket> GetTickets(stDataContext db,string subgroup, bool? active)
        {
            return from p in db.tickets
                   where
                       (active == null || p.active  == active) //What I simplifed
		&& p.sub_unit.sub_unit_name == subgroup  //Added Filter
                   select p;
        }