Пример #1
0
        /// <summary>Get recent user activities with address filter</summary>
        /// <cardinality>Many</cardinality>
        public List <DefaultUserActivityOnAddressData> DefaultUserActivityOnAddress(
            string originatingAddress
            )
        {
            var ret = new List <DefaultUserActivityOnAddressData>();

            string sql = @" 
                    select top 50
	                     ua.date_time
	                    ,uatr.default_user_activity_type_name   as user_activity_type_name
	                    ,ua.originating_address
	                    ,ua.user_activity_note
					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
					--realwhere
					where ua.originating_address = @originating_address
                    order by ua.date_time desc                   
                ";

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

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

                    using (var command = new SqlCommand(sql, conn)) {
                        command.Parameters.Add("@originating_address", SqlDbType.VarChar).Value = originatingAddress;
                        log.PerformanceTimePrepare(command);
                        IDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult);
                        log.PerformanceTimeCheck();

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

                        reader.Close();
                    }
                }
            } catch (Exception ex) {
                log.Error(ex);
            }
            return(ret);
        }
Пример #2
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, DefaultUserActivityOnAddressDataOrdinals ordinals)
 {
     if (!reader.IsDBNull(ordinals.DateTime))
     {
         DateTime = reader.GetDateTime(ordinals.DateTime);
     }
     if (!reader.IsDBNull(ordinals.UserActivityTypeName))
     {
         UserActivityTypeName = reader.GetString(ordinals.UserActivityTypeName);
     }
     if (!reader.IsDBNull(ordinals.OriginatingAddress))
     {
         OriginatingAddress = reader.GetString(ordinals.OriginatingAddress);
     }
     if (!reader.IsDBNull(ordinals.UserActivityNote))
     {
         UserActivityNote = reader.GetString(ordinals.UserActivityNote);
     }
 }