public static Advertisement GetAdvertisementForSite(int bannerId, DateTime date) { Query qry = new Query(Advertisement.TableSchema); qry.SelectAll(); qry.AddWhere(Advertisement.Columns.FromDate, WhereComparision.LessThan, date); qry.AddWhere(Advertisement.Columns.ToDate, WhereComparision.GreaterThan, date.AddDays(1)); qry.AddWhere(Advertisement.Columns.BunnerId, bannerId); var ads = new List <Advertisement>(); using (DataReaderBase reader = qry.ExecuteReader()) while (reader.Read()) { ads.Add(Advertisement.FromReader(reader)); } int num = rand.Next(0, ads.Count); return(ads[num]); }