I'm trying to write the equivalent of this SQL statement:
SELECT * FROM [Brick]
INNER JOIN [BrickTagMapping] ON [Brick].[BrickId]=[BrickTagMapping].[BrickId]
INNER JOIN [Tag] ON [Tag].[TagId]=[BrickTagMapping].[TagId])
WHERE [Tag].[Name] IN ('ParamA','ParamB')
GROUP BY [Brick].[BrickId]
HAVING COUNT( [Brick].[BrickId] )=2 /* count of number of items in IN list */
So far, I've got
//IGroupByCollection groupByClause = new GroupByCollection();
//groupByClause.Add(BrickFields.BrickId);
EntityCollection<BrickEntity> bricks = new EntityCollection<BrickEntity>();
IRelationPredicateBucket expr = new RelationPredicateBucket();
expr.Relations.Add(BrickEntity.Relations.BrickTagMappingEntityUsingBrickId);
expr.Relations.Add(BrickTagMappingEntity.Relations.TagEntityUsingTagId);
expr.PredicateExpression.Add(TagFields.Name == tags);
da.FetchEntityCollection(bricks, expr);
There's two problems I'm having though.
1) I can't specify the groupByClause (or add the Having clause) - because FetchEntityCollection doesn't seem to allow me to do this? How can I get around this, or can anyone suggest a way to write an equivalent query?
2) The SQL at the moment that LLBLGen is spitting out includes SELECT DISTINCT rather than just SELECT
Any suggestions? Thanks everyone!