tags:

views:

20

answers:

0

I have a series of dropdown lists that contain all possible options held on my project table. Each time a dropdown is changed, I kick off a "refilter" that then updates all the other dropdowns so that the options in the boxes always reflect the results matching all the dropdowns - it's a dynamic filter basically.

Now the project table has an associated table - projectVersions - and this is a one to many link as there can be up to 6 versions. I can successfully filter on fields in the version table (a kind of "get me all projects where ANY of the versions associated with that project contain X" query) using the "any" linq function by doing this:

...
And ((lf.sizeCapacity = -1) Or (p.tblProjectVersions.Any(Function(t) t.sizeCapacity = lf.sizeCapacity)))
...

but there is one more complexity where there is also an associated table to projectVersions called marketdestinations, so each version can have up to 5 destinations... I need to filter based on a dropdown for a market destination, so if I choose "Australia" for example, the project list returns all projects where any of that project's versions has one of its market destinations set to Australia.

I've tried doing this like this:
...And ((lf.marketDestination = -1) Or (p.tblProjectVersions.Any(Function(t) t.tblProjectVersionMarketShares.Any(Function(tt) tt.msID = lf.marketDestination))))

where I'm doing an "any" within an "any" but it doesn't seem to work, so I'm probably doing something wrong...

The full filter query looks like this, and works apart from the market destination filter.

        rc = (From p In pdc.tblProjects _
                             Where ((lf.liquidClass = "-1") Or (p.LiquidClass = lf.liquidClass)) _
                             And ((lf.liquidType = "-1") Or (p.LiquidType = lf.liquidType)) _
                             And ((lf.brand = "-1") Or (p.ParentBrand = lf.brand)) _
                             And ((lf.brandVariant = "-1") Or (p.brandVariant = lf.brandVariant)) _
                             And ((lf.marketDestination = -1) Or (p.tblProjectVersions.Any(Function(t) t.tblProjectVersionMarketShares.Any(Function(tt) tt.msID = lf.marketDestination)))) _
                             And ((lf.sizeCapacity = -1) Or (p.tblProjectVersions.Any(Function(t) t.sizeCapacity = lf.sizeCapacity))) _
                             And ((lf.region = -1) Or (p.tblAccounts.tblRegions.RegionID = lf.region)) _
                             And ((lf.user = Guid.Empty) Or (p.UserAccount = lf.user)) _
                             And p.isDeleted = False _
                             Select p).Count