November Happy Hour will be moved to Thursday December 5th.

Club where I am member

Vote:
 

Hello,

This is probably very easy, but I can't get my club query to work! What I want is to simply get all clubs where a given user is member.

My current, not-working, query looks like this:

// Create a club query
ClubQuery clubQuery = new ClubQuery();

// Initialize criterions
clubQuery.Members = new MembershipCollectionCriterion();
clubQuery.Members.Containing = new MembershipCriterion();
clubQuery.Members.Containing.User = new UserCriterion();
clubQuery.Members.Containing.User.ID = new IntegerCriterion();
clubQuery.Members.Containing.MembershipType = new MembershipTypeCriterion();

// Set values to filter on
clubQuery.Members.Containing.User.ID.Value = ProfileMenuUser.ID;
clubQuery.Members.Containing.MembershipType.Value = MembershipType.Member;

// Add group
CriteriaGroup cg = new CriteriaGroup();
cg.AddCriterion(clubQuery.Members.Containing.User);
cg.AddCriterion(LogicalOperator.And, clubQuery.Members.Containing.MembershipType);
clubQuery.Members.Containing.AddCriteriaGroup(cg);

// Get the filtered clubs
ClubCollection clubs = ClubHandler.GetQueryResult(clubQuery);

All help is _very_ appreciated!

Thanks

/ jonas 

#20537
Jun 04, 2008 13:00
Vote:
 

Hi Jonas,

If you leave out the part saying

// Add group
CriteriaGroup cg = new CriteriaGroup();
cg.AddCriterion(clubQuery.Members.Containing.User);
cg.AddCriterion(LogicalOperator.And, clubQuery.Members.Containing.MembershipType);
clubQuery.Members.Containing.AddCriteriaGroup(cg);

 

it should be enough to give you the result you seek. But also with grouping it returns the correct result according to my tests.

For your convenience there is already a method for this, ClubHandler.GetMyClubs(...), it will also perform better and give you automatic cache invalidation than a dynamically created query would. 

/Mattias 

#20557
Edited, Jun 04, 2008 16:15
Vote:
 

Brilliant! Thanks a lot.

 

/ jonas 

#20558
Jun 04, 2008 16:28
This thread is locked and should be used for reference only. Please use the Legacy add-ons forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.