Collection.Count returning unexpected result

Posts   
 
    
peschkaj
User
Posts: 30
Joined: 21-Sep-2006
# Posted on: 09-May-2007 18:20:57   

I have a Team object, a team has multiple players. In order to determine the number of players who are not substitutes, I have created the following property on the TeamEntity:


/// <summary>
/// Returns a list of all regular (non-substitute) players.
/// </summary>
public RosterCollection RegularPlayers
{
    get
    {
        IPredicateExpression _filter = new PredicateExpression ();
        _filter.Add (RosterFields.IsSub == false);
        RosterCollection _players = RosterCollectionViaRosterTeam;
        _players.GetMulti (_filter);
        return _players;
    }
}

When I call team.RegularPlayers.Count, it is returning 15, which isn't correct because there are only 13 items in the RosterTeam table.

Any thoughts would be greatly appreciated.

Thanks,

jeremiah

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 09-May-2007 18:39:43   

Most probably you are referncing a collection that already contains some items. Try to use the following instead:

RosterCollection _players = new RosterCollection();

Or

RosterCollection _players = RosterCollectionViaRosterTeam;
_players.Clear();
peschkaj
User
Posts: 30
Joined: 21-Sep-2006
# Posted on: 09-May-2007 20:57:37   

Thanks! I was able to correct it after you said that. I didn't realize that would affect things that way. I just created additional AddWithAnd items in the filter.