Having trouble creating a query

Posts   
 
    
Posts: 5
Joined: 13-Jun-2006
# Posted on: 22-Jun-2006 19:04:46   

I have two tables Article and Word, and a m:n table ArticleWord

This query does exactly what I need:

SELECT   ArticleWord.ArticleID, COUNT(ArticleWord.WordID) AS WordCount
FROM         ArticleWord INNER JOIN
                      Word ON ArticleWord.WordID = Word.WordID
WHERE    (Word.Text = N'searchword') OR
                      (Word.Text = N'anothersearchword') OR
                           (Word.Text = N'yetanothersearchword')
GROUP BY ArticleWord.ArticleID

I get a count of the search words that are in each article. But I can't seem to figure out how to do this same thing in LLBL.

Any suggestions?

Thanks, Kevin

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 23-Jun-2006 00:06:57   

Here's a quick way to do this using a dynamic list.

            ResultsetFields fields = new ResultsetFields(2);
            fields.DefineField(ArticleWordFieldIndex.ArticleId, 0, "ArticleId", "");
            fields.DefineField(ArticleWordFieldIndex.WordId, 1, "WordCount", "", AggregateFunction.Count);

            IRelationPredicateBucket bucket = new RelationPredicateBucket();
            IGroupByCollection group = new GroupByCollection();
            group.Add(ArticleWordFields.NewsId);

            bucket.Relations.Add(ArticleWordEntity.Relations.WordEntityUsingWordId);

            DataTable dynamicList = new DataTable();

            using(DataAccessAdapter adapter = new DataAccessAdapter())
            {
                 adapter.FetchTypedList(fields, dynamicList, bucket, 0, null, true, group);
            }

You can set this same query up in the designer as a typedlist that may also meet your requirements.