Debugging LINQ to SQL programs

Within Visual Studio 2008, when debugging a LINQ to SQL program, we can use the traditional either of the Watch or QuickWatch windows to inspect a variable. For example, after the following line is executed, we can right-click on the products variable, and select QuickWatch … or Add Watch to see the contents of this variable:

var products = from p in db.Products
where p.CategoryID == 1
select p;

The QuickWatch window will look like this:

Debugging LINQ to SQL programsLINQ to SQLvalidations, adding to entity classes

We can also hover our mouse over the products variable, and wait for the Quick Info pop-up window to appear, and then inspect it on the fly. The pop-up Quick Info window will appear as shown in the following image:

Debugging LINQ to SQL programsLINQ to SQLvalidations, adding to entity classes

In the Watch window, we can inspect the returned result of the variable, its properties, and even its children.

Note

This inspection may trigger a real query to the database. For example, if you let your mouse hover over db.Products, and then try to open Results View, the database will be queried to get all of the products. In an environment with a big database, this may cause some problems.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset