where x in (1121,1331,1441,1551,1661)

Posts   
 
    
tvoss avatar
tvoss
User
Posts: 192
Joined: 07-Dec-2003
# Posted on: 25-Nov-2009 18:44:31   

Hello,

I have a wierd set of data I have to retrieve at once with one filter so that I can page it to a datagrid with your easy paging.

the data after the 'in' I cannot get from a filter since it is customer input from a web form, so it will be in the form of a list or collection or string or whatever I can easily create knowing what those numbers are.

How can I do a filter with the above without the resulting list of integers being a filter?

I hope that is clear.

Thanks, Terry Voss

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-Nov-2009 04:11:03   

Hi Terry,

If I understand you you have a set of strings from the user input, then you want to use that to create a IN filter but with numbers, right?

If that is correct, you should:

  1. Convert the user input to something usable. For instance, if the user enters a comma separated string you can use some method like:
static int[] SplitStringIntoInts(string list)
{
    List<int> numbers = new List<int>();
    foreach (string stringValue in list.Split(','))
    {
        int number;
        if (int.TryParse(stringValue, out number))
        {
            numbers.Add(number);
        }
    }

    return numbers.ToArray();
}

or whatever method you use to transform such user input into usable numbers.

  1. Then you can easily create a filter that create the IN predicate. This is the easiest way:
string list = theUserInput;
int[] numbers = SplitStringIntoInts(list);

myPredicate.Add(OrderFieldsOrderId == numbers);

// fetch..., etc

Hope I understood what you really want.

David Elizondo | LLBLGen Support Team