views:

23

answers:

1

Hello all.

I have the following code that gives me a an array in an autocomplete extender:

return autocomplete.tblAutoCompletes
                    .Where(p => p.MemberId == memberid && p.LocationId == locationid && p.ACItem.Contains(prefixText))
                    .OrderBy(p => p.ACItem)
                    .Select(p => p.ACItem)
                    .Take(count)
                    .ToArray();

However, I may need to programmatically exclude certain items from the array.

How would I do that? So for example, ACItem list = Product1, Product2, Product3.

How would I amend the code so that Product2 is excluded?

+2  A: 
autocomplete.tblAutoCompletes
                .Where(p => p.MemberId == memberid && p.LocationId == locationid && p.ACItem.Contains(prefixText))
                .OrderBy(p => p.ACItem)
                .Select(p => p.ACItem)
                .Take(count)
                .Where(p => p != Product1)
                .Select(p => p)
                .ToArray();
jsmith
Hello JSmith - so I'd do this outside of the original query? Sorry, I'm having a really bad day and being very thick. Thanks for looking at this for me though.
Ricardo Deano
Seconded. Unless there are additional unstated requirements, it would seem like running the result though another WHERE filter would be the simplest.
Godeke
Is there really a need to wrap the first part of the query in parentheses? At first sight it's hard to see why there's a left parentheses at the beginning.
strager
Top, top stuff. That's great and gives me a solid foundation to work on. Really appreciate your help.
Ricardo Deano