LinqConnect Documentation
In This Topic
    Logging
    In This Topic
    Logging
    LinqConnect Documentation
    Logging
    [email protected]

    Use the Log property of the DataContext class to output SQL statements generated by LinqConnect. Assign any TextWriter descendant to it, and SQL statement will be logged by this TextWriter. For example you may assign Console.Out or Debug.Out TextWriter to it, or StreamWriter that writes to the file.

         CrmDemoContext.CrmDemoDataContext db = new CrmDemoContext.CrmDemoDataContext();
         db.Log = Console.Out;
         
         var query = from product in db.Products
                  select new
                  {
                    Name = product.ProductName,
                    Price = product.Price,
                    Category = product.ProductCategory.CategoryName
                  };
          
          foreach (CrmDemoContext.Product product in query)
          {
             Console.WriteLine(product.ProductName);      
          }
    
    
         Dim db As New CrmDemoContext.CrmDemoDataContext()
         db.Log = Console.Out
         
         Dim query = From product in db.Products
                  Select New
                  {
                    Name = product.ProductName,
                    Price = product.Price,
                    Category = product.ProductCategory.CategoryName
                  }
          
          For Each CrmDemoContext.Product In query
            Console.WriteLine(product.ProductName)
          Next
    
    
    The console output will contain the following:
    SELECT t1."ProductName" AS "ProductName", t1."Price", t2."CategoryName" AS "CategoryName"
    FROM CRM_DEMO."Products" t1
    LEFT OUTER JOIN CRM_DEMO."ProductCategories" t2 ON t1."CategoryID" = t2."CategoryID"
    
    Borland UK CodeGear Division Alpha Bank ... Orderbase Consulting Gmbh