views:

189

answers:

2

I have a GridView bound to a table using BindingSource and Linq to SQL classes. The table structure is like this:

MainTable
----------
ID Name FormReserveId
123 asd 15

FormReserves
-----------------
ID FormId Number
15 33     some number

Forms
------
ID FormName
33 form name

MainTable.FormReserveId foreign key to FormReserves.ID

FormReserves.FormId foreign key to Forms.ID

In the grid, instead of displaying FormReserveId (e.g 15), how can I display "form name, some number"?

+1  A: 

You need to either 'join' those extra tables into the result set that you're binding to or use the Navigation properties of your L2S generated classes and shape the returning data.

Something like this:

var results = (from r in <yourSource> select new 
{
    Name = r.Name,
    FormName = r.FormReserves.Forms.FormName,
    Number = r.FormReserves.Number
});
DavidGouge