views:

33

answers:

0

I'm trying to use the PredicateBuilder for adding a list of values to a query.

I want the return Dataset to include all records where the "pkey" value matches at least one of the strings in the list.

In order to simplify the sample code, I've added a list of sample strings directly to the Domain Servie, while this will be passed from the caller in production.

In the attached code sample, the GetJiraissuesForStory return the records as expected, but when using the PredicateBuilder version, GetJiraissuesForStoriesPredicateBuilder, I'm getting an empty dataset in return. I've also tried to add one single string to the predicate, same result.

Any ideas? LarsM

    public IQueryable<jiraissue> GetJiraissuesForStoriesPredicateBuilder()
    {
        List<string> stories = new List<string> { "Story-875", "Story-815", "Story-614" };

        var pred = PredicateBuilder.False<jiraissue>();

        var res = from l in this.GetIssuelinks() 
                  where ((int)l.LINKTYPE).Equals(10003)
                  join i in this.GetJiraissues() on (int)l.SOURCE equals (int)i.ID
                  join s in this.GetJiraissues() on (int)l.DESTINATION equals (int)s.ID
                  select s;

        foreach (string keyword in stories) 
        {
            string temp = keyword;
            pred = pred.Or(p => p.pkey.Contains(temp));
        }   

        return res.AsExpandable().Where (pred);
    }

    public IQueryable<jiraissue> GetJiraissuesForStory(string story)
    {
        story = ("Story-875");

        var res = from l in this.GetIssuelinks()
                  where ((int)l.LINKTYPE).Equals(10003)
                  join i in this.GetJiraissues() on (int)l.SOURCE equals (int)i.ID
                  join s in this.GetJiraissues() on (int)l.DESTINATION equals (int)s.ID
                  where i.pkey.Contains(story)
                  select s;
        return res;
    }