UserQuery - Filter on club-membership

Vote:
 

I'm trying to get a list of all users who are members of some specified of clubs, but I keep getting a null-reference exception when I execute the query.

The code I'm using:
------------------------------------------------------------------------------------------------------------------------------
MembershipCriterion crit = newMembershipCriterion();
crit.Club = newClubCriterion();
crit.Club.ID = newIntegerCriterion();
crit.Club.ID.Includes = newIntegerInCriterion();
foreach (ListItem item in clubs.Items.OfType<ListItem>().Where( t => t.Selected ).ToList())
{
    crit.Club.ID.Includes.Values.Add( Convert.ToInt32( item.Value ) );
}
query.Criteria.Add( "Clubs", crit );
------------------------------------------------------------------------------------------------------------------------------

Any idea what could be wrong with this code?

 

#51379
Jun 06, 2011 16:54
Vote:
 

Well, you're not checking null references in your code... I have done some similar stuff (but the code is buried deep), but look at this post by Karoline

http://karolikl.blogspot.com/2009/09/using-query-system-in-episerver.html

Maybe that can give you some help

#51510
Jun 10, 2011 15:31
Vote:
 

Since the clubs are retrieved from a dropdownlist, which is previously filled from a club-query, I see no points where a null-reference could occur. Where should I check for null-recerences then?

#51551
Jun 14, 2011 16:17
Vote:
 

crit.Club.ID.Includes.Values.Add( Convert.ToInt32( item.Value ) ); - item.Value, I think Convert will fail if there is no data in item.Value. Haven't tested the code, but it could happen, maybe =)

#51552
Jun 14, 2011 16:44
Vote:
 

But item.Value has  a value. The error also occurs on the execution of the query, not on converting the value of the item.

#51557
Jun 15, 2011 9:19
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.