// 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, DefaultTestSearchQueryDataOrdinals ordinals) { if (!reader.IsDBNull(ordinals.TestArea)) { TestArea = reader.GetString(ordinals.TestArea); } if (!reader.IsDBNull(ordinals.TestSubArea)) { TestSubArea = reader.GetString(ordinals.TestSubArea); } if (!reader.IsDBNull(ordinals.DefaultTestRunResultRcd)) { DefaultTestRunResultRcd = reader.GetString(ordinals.DefaultTestRunResultRcd); } if (!reader.IsDBNull(ordinals.ElapsedMilliseconds)) { ElapsedMilliseconds = reader.GetInt32(ordinals.ElapsedMilliseconds); } if (!reader.IsDBNull(ordinals.DateTime)) { DateTime = reader.GetDateTime(ordinals.DateTime); } if (!reader.IsDBNull(ordinals.TestAddress)) { TestAddress = reader.GetString(ordinals.TestAddress); } }
/// <summary>Get Default Test</summary> /// <cardinality>Many</cardinality> /// <template>ByServiceTableCrud</template> public List <DefaultTestSearchQueryData> DefaultTestSearchQuery() { var ret = new List <DefaultTestSearchQueryData>(); string sql = @" select dt.test_area ,dt.test_sub_area ,( select top 1 dtr.default_test_run_result_rcd from default_test_run as dtr where dtr.default_test_id = dt.default_test_id ) as default_test_run_result_rcd ,( select top 1 dtr.elapsed_milliseconds from default_test_run as dtr where dtr.default_test_id = dt.default_test_id ) as elapsed_milliseconds ,( select top 1 dtr.date_time from default_test_run as dtr where dtr.default_test_id = dt.default_test_id ) as date_time ,dt.test_address from default_test as dt --realwhere "; using (var conn = new SqlConnection(Conn.ConnectionString)) { conn.Open(); using (var command = new SqlCommand(sql, conn)) { command.CommandText = sql; Logging log = Logging.PerformanceTimeStart("DefaultTestSearchWithFilter"); IDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult); log.PerformanceTimeStop(sql, command); var ordinals = new DefaultTestSearchQueryDataOrdinals(reader); while (reader.Read()) { var data = new DefaultTestSearchQueryData(); data.Populate(reader, ordinals); ret.Add(data); } reader.Close(); } return(ret); } }