예제 #1
0
        public OrderDAL FindOrderByID(int OrderID)
        {
            OrderDAL ProposedReturnValue = null;

            try
            {
                EnsureConnected();
                using (SqlCommand command
                           = new SqlCommand("FindOrderByID", _connection))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@OrderID", OrderID);


                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        OrderMapper m     = new OrderMapper(reader);
                        int         count = 0;
                        while (reader.Read())
                        {
                            ProposedReturnValue = m.OrderFromReader(reader);
                            count++;
                        }
                        if (count > 1)
                        {
                            throw new
                                  Exception($"Found more than 1 User with key {OrderID}");
                        }
                    }
                }
            }
            catch (Exception ex) when(Log(ex))
            {
            }
            return(ProposedReturnValue);
        }