Пример #1
0
    /// <summary>
    /// Runs a query and displays the nominated properties
    /// </summary>
    /// <param name="explanation">Text description of query being made</param>
    /// <param name="dbQuery">Function taking db and running query over it</param>
    /// <param name="propertyNamesToList">List of properties to display</param>
    public static void RunQuery(string explanation, Func<dynamic, dynamic> dbQuery, List<string> propertyNamesToList, string pocoType)
    {
      try
      {
        ShowExplanation(explanation);

        var listener = new ExampleTraceListener();
        Trace.Listeners.Add(listener);

        var db = Database.Open();
        var results = dbQuery(db);
        ListReturnedProperties(results, propertyNamesToList, pocoType);

        ShowSql(listener);

        Trace.Listeners.Remove(listener);
      }
      catch (Exception ex)
      {
        ShowException(ex);
      }

      Console.WriteLine("Press return");
      Console.ReadLine();
    }
Пример #2
0
        /// <summary>
        ///     Runs a query and displays the nominated properties
        /// </summary>
        /// <param name="explanation">Text description of query being made</param>
        /// <param name="dbQuery">Function taking db and running query over it</param>
        /// <param name="propertyNamesToList">List of properties to display</param>
        /// <param name="pocoType">Type of POCO being created</param>
        public static void RunQuery(string explanation, Func <dynamic, dynamic> dbQuery, List <string> propertyNamesToList,
                                    string pocoType)
        {
            try
            {
                ShowExplanation(explanation);

                var listener = new ExampleTraceListener();
                Trace.Listeners.Add(listener);

                dynamic db      = Database.Open();
                dynamic results = dbQuery(db);
                ListReturnedProperties(results, propertyNamesToList, pocoType);

                ShowSql(listener);

                Trace.Listeners.Remove(listener);
            }
            catch (Exception ex)
            {
                ShowException(ex);
            }

            Console.WriteLine("Press return");
            Console.ReadLine();
        }
Пример #3
0
 private static void ShowSql(ExampleTraceListener listener)
 {
   Console.WriteLine("--------");
   Console.ForegroundColor = ConsoleColor.Green;
   Console.WriteLine("SQL Sent to database was:");
   Console.WriteLine(listener.Output);
   Console.ResetColor();
 }
Пример #4
0
 private static void ShowSql(ExampleTraceListener listener)
 {
     Console.WriteLine("--------");
     Console.ForegroundColor = ConsoleColor.Green;
     Console.WriteLine("SQL Sent to database was:");
     Console.WriteLine(listener.Output);
     Console.ResetColor();
 }