LINQ Logging with SmartInspect 3.0

If you are a .NET, Java or Delphi developer, please take a look at our advanced logging tool SmartInspect.

LINQ and LINQ to SQL, Microsoft’s data querying language and ORM for .NET and SQL Server, allows developers to easily query databases without writing data access code or SQL statements. Although Microsoft built a great abstraction for working with data and made it a lot easier to build queries, it’s often still useful to take a look at the underlying SQL queries that LINQ generates.

We added a feature to SmartInspect’s .NET library that allows you to use LINQ’s logging capabilities with SmartInspect. By using this feature, you are able to live monitor the generated SQL queries directly in the Console or save the queries to log files for later analysis.

private IList<Order> GetOrdersByYear(int year)
{
  // Enable SmartInspect logging
  SiAuto.Si.Enabled = true;

  using (var db = new NorthwindDataContext())
  {
    // Attach SmartInspect logging
    db.Log = new SmartInspectLinqToSqlAdapter();

    var query = from o in db.Orders
      where
        o.OrderDate >= new DateTime(year, 1, 1)
        o.OrderDate <= new DateTime(year, 12, 31)
      select o;

    // Execute the query
    return query.ToList();
  }
}

When the LINQ SQL statements are viewed in the SmartInspect Console, you can easily inspect them with the built-in SQL / source viewer:

The SmartInspectLinqToSqlAdapter class is one of several adapters to make it easier to use SmartInspect with other platform and third-party logging classes. Next in our series on SmartInspect 3.0 come the new features in the SmarInspect Console.

This entry was posted in Gurock Software, SmartInspect, SmartInspect 3.0. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared.