private static void FetchSalesOrderHeaderHandCoded() { var frameworkName = "DbDataReader, handcoded"; var sw = new Stopwatch(); sw.Start(); var headers = new List<SalesOrderHeader>(); using(var con = new SqlConnection(ConnectionString)) { var cmd = con.CreateCommand(); cmd.CommandText = "select * from Sales.SalesOrderHeader"; con.Open(); var reader = cmd.ExecuteReader(); while(reader.Read()) { object fieldValue = null; var soh = new SalesOrderHeader(); soh.SalesOrderId = (int)reader.GetValue(0); soh.RevisionNumber = (byte)reader.GetValue(1); soh.OrderDate = (DateTime)reader.GetValue(2); soh.DueDate = (DateTime)reader.GetValue(3); fieldValue = reader.GetValue(4); soh.ShipDate = (DateTime)(fieldValue == DBNull.Value ? null : fieldValue); soh.Status = (byte)reader.GetValue(5); soh.OnlineOrderFlag = (bool)reader.GetValue(6); soh.SalesOrderNumber = (string)reader.GetValue(7); fieldValue = reader.GetValue(8); soh.PurchaseOrderNumber = (string)(fieldValue == DBNull.Value ? null : fieldValue); fieldValue = reader.GetValue(9); soh.AccountNumber = (string)(fieldValue == DBNull.Value ? null : fieldValue); soh.CustomerID = (int)reader.GetValue(10); soh.ContactID = (int)reader.GetValue(11); fieldValue = reader.GetValue(12); soh.SalesPersonID = (int?)(fieldValue == DBNull.Value ? null : fieldValue); fieldValue = reader.GetValue(13); soh.TerritoryID = (int?)(fieldValue == DBNull.Value ? null : fieldValue); soh.BillToAddressID = (int)reader.GetValue(14); soh.ShipToAddressID = (int)reader.GetValue(15); soh.ShipMethodID = (int)reader.GetValue(16); fieldValue = reader.GetValue(17); soh.CreditCardID = (int?)(fieldValue == DBNull.Value ? null : fieldValue); fieldValue = reader.GetValue(18); soh.CreditCardApprovalCode = (string)(fieldValue == DBNull.Value ? null : fieldValue); fieldValue = reader.GetValue(19); soh.CurrencyRateID = (int?)(fieldValue == DBNull.Value?null : fieldValue); soh.SubTotal = (decimal)reader.GetValue(20); soh.TaxAmt = (decimal)reader.GetValue(21); soh.Freight = (decimal)reader.GetValue(22); soh.TotalDue = (decimal)reader.GetValue(23); fieldValue = reader.GetValue(24); soh.Comment = (string)(fieldValue==DBNull.Value ? null : fieldValue); soh.Rowguid = (Guid)reader.GetValue(25); soh.ModifiedDate = (DateTime)reader.GetValue(26); headers.Add(soh); } reader.Close(); con.Close(); } sw.Stop(); ReportResult(frameworkName, sw.ElapsedMilliseconds, headers.Count); foreach(var e in headers) { if(e.SalesOrderId <= 0) { Console.WriteLine("Hand written: Data is empty"); break; } } }