LinqDatasource one to one realtionship

usilunet used Ask the Experts™
Dear Experts,
I'm looking for a solution to diplay some data from 2 tables with a 1 to 0-1 realationship.
I created the LinqDataSource and a GridView and it displays the data of the first table, but of the second table it displays only the name of the class but not the content of the fields (see picture).

Actually I have 2 records in the first table and one of them is related to a record in the second (as you can see in the picture).

What can i do to expand the data of the second table?
<asp:LinqDataSource ID="ldsAssetHardware" runat="server" 
            ContextTypeName="DataClassesDataContext" OrderBy="Data_Acquisto" 
            Select="new (ID_Fornitore, Data_Acquisto, ID_Progetto, ID_Oggetto, Hardware)">
 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
                 <asp:BoundField DataField="ID_Fornitore" HeaderText="ID_Fornitore" 
                        ReadOnly="True" SortExpression="ID_Fornitore" />
                 <asp:BoundField DataField="Data_Acquisto" HeaderText="Data_Acquisto" 
                        ReadOnly="True" SortExpression="Data_Acquisto" />
                 <asp:BoundField DataField="ID_Progetto" HeaderText="ID_Progetto" 
                        ReadOnly="True" SortExpression="ID_Progetto" />
                 <asp:BoundField DataField="ID_Oggetto" HeaderText="ID_Oggetto" ReadOnly="True" 
                        SortExpression="ID_Oggetto" />
                 <asp:BoundField DataField="Hardware" HeaderText="Hardware" 
                        SortExpression="Hardware" />

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You need to fully qualify what you want from the hardware table. ie change line 4 to

Select="new (ID_Fornitore, Data_Acquisto, ID_Progetto, ID_Oggetto, Hardware.ID, Hardware.ID_Asset, Hardware.Serial_Number...)">


Yeah!!! Great!!
I already tried this solution, it didn't worked because in the datagrid it didn't find the fields when I put the fully qualified field names.
How can I create aliases when I have different tables with the same field names?


Alias: simple "as Description" after the field
Just as an afterthough... the reason you get the type name is that if the object passed in the list is not a string, the ToString() method is called on the object. If you override this method, you can put whatever you like into the string diplayed.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial