コード例 #1
0
 // use ordinals to speed up access to DataReader
 // links:
 //  crud definition: https://en.wikipedia.org/wiki/Create,_read,_update_and_delete
 //  docLink: http://sql2x.org/documentationLink/327451c3-64a8-4de8-b359-76742d634497
 // parameters:
 //  reader: IDataReader from SQLClient
 public void Populate(IDataReader reader, DefaultUserActivityGroupedByAddressDataOrdinals ordinals)
 {
     if (!reader.IsDBNull(ordinals.OriginatingAddress))
     {
         OriginatingAddress = reader.GetString(ordinals.OriginatingAddress);
     }
     if (!reader.IsDBNull(ordinals.Occurrences))
     {
         Occurrences = reader.GetInt32(ordinals.Occurrences);
     }
 }
コード例 #2
0
        /// <summary>User activities grouped by address</summary>
        /// <cardinality>Many</cardinality>
        public List <DefaultUserActivityGroupedByAddressData> DefaultUserActivityGroupedByAddress()
        {
            var ret = new List <DefaultUserActivityGroupedByAddressData>();

            string sql = @" 
                    select top 50
	                     ua.originating_address
	                    ,count(1) as occurrences
                    from default_user_activity as ua
                    inner join default_user_activity_type_ref as uatr on uatr.default_user_activity_type_rcd = ua.default_user_activity_type_rcd
					group by 
	                     ua.originating_address
                    order by 
						count(1) desc
                ";

            Logging log = Logging.PerformanceTimeStart("Default", "DataAccessLayer", "DefaultSearch", "DefaultUserActivityGroupedByAddress");

            try {
                using (var conn = new SqlConnection(Conn.ConnectionString)) {
                    conn.Open();
                    conn.BeginTransaction(IsolationLevel.ReadUncommitted).Commit();

                    using (var command = new SqlCommand(sql, conn)) {
                        log.PerformanceTimePrepare(command);
                        IDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult);
                        log.PerformanceTimeCheck();

                        var ordinals = new DefaultUserActivityGroupedByAddressDataOrdinals(reader);
                        while (reader.Read())
                        {
                            var data = new DefaultUserActivityGroupedByAddressData();
                            data.Populate(reader, ordinals);
                            ret.Add(data);
                        }

                        reader.Close();
                    }
                }
            } catch (Exception ex) {
                log.Error(ex);
            }
            return(ret);
        }