Monthly Archives for July 2010

One of my colleague ran into this problem when using LINQ to join two tables. The problem is that he has two tables a & b where he is joining tables on column called key on both the tables. Following is what he had in the beginning

var list = from firstTable in a

join secondTable in b

on firstTable.Key == secondTable.Key

select a;

This is a very straight forward query. On first glace there is nothing wrong with that. But when he tries to enter the above mentioned code, VS 2010 did not let him complete and was give error “The name ‘secondTable’ is not in scope on the left side of ‘equals’” Couple of things you have to remember when you are using Linq to do joins

The order of comparison matters. So always use first table first and compare it against second table.

All LINQ joins are equijoins. so instead of using == you should use equals

I ran into a situation where, based on what grid client wants to see, I need to show them that particular grid of user’s choice. The catch here is that, all the grids are different third party controls so I can not generalize and create one view, instead each grid will be separate view. Here is how I went about doing it. I have main page XAML, which has a combo box which will allow the user to select which grid they want to see. By default, we show the first grid on load. When the grid selection changes I need to replace the current grid with selected grid.

in the code behind, I load some data and data bind it to datagrid2. The interesting part of the code which replaces the default grid from the main page is as follow

FirstControl first = new FirstControl();LayoutRoot.Children.RemoveAt(1);LayoutRoot.Children.Add(first);Grid.SetRow(first, 1);

So create the first grid and remove the existing grid from row 1, add the newly created as a child to the Layout Root. Make sure you set which row the newly added grid has to go to. That’s it. Now you can switch in and out of grid as you want.