public Dictionary <int, List <BasicParticipation> > GetParticipationsForPeople(int[] personIds, int gracePeriod) { Dictionary <int, List <BasicParticipation> > result = new Dictionary <int, List <BasicParticipation> >(); if (personIds == null || personIds.Length == 0) { return(result); } // Optimization: If more than 128 personIds, build a hash table, get _all_ memberships, and return // the matching ones logic wise. We've had _queries_ that exceed 64k text in length... if (personIds.Length > 128) { return(GetParticipationsForPeopleOptimizedForLargeSets(personIds, gracePeriod)); } using (DbConnection connection = GetMySqlDbConnection()) { connection.Open(); string commandString = "SELECT " + membershipFieldSequence + " WHERE " + (gracePeriod == 0 ? "Active=1" : " (Expires > DATE_ADD(NOW(),INTERVAL -" + gracePeriod + " Day) AND (Expires < DATE_ADD(DateTimeTerminated,INTERVAL 1 Day) OR Active=1))") + " AND PersonId in (" + JoinIds(personIds) + ")"; DbCommand command = GetDbCommand(commandString, connection); command.CommandTimeout = 30; // If 30s is too short, something needs optimization. using (DbDataReader reader = command.ExecuteReader()) { while (reader.Read()) { BasicParticipation participation = ReadMembershipFromDataReader(reader); int personId = participation.PersonId; if (!result.ContainsKey(personId)) { result[personId] = new List <BasicParticipation>(); } result[personId].Add(ReadMembershipFromDataReader(reader)); // Add to this person's list of memberships } } } return(result); }
private Participation(BasicParticipation basic) : base(basic) { }
public static Participation FromBasic(BasicParticipation basic) { return(new Participation(basic)); }