views:

132

answers:

2

Hello! I have a database with two tables, ProductLine and Supplier. ProductLine contains the foreign key SupplierId, while Supplier has a field "Name".

Table ProductLine: ProductLineId(PK), Name, SupplierId(FK) etc.

Table Supplier: SupplierId(PK), Name etc.

In my program I have two classes, ProductLine and Supplier, of which ProductLine has the member "Supplier SupplierId". This member is mapped the following way in ProductLine.hbm.xml (my NHibernate-mapping for ProductLine):

<many-to-one name="SupplierId" class="Supplier"/>

In my Web-site, I want a gridview to display the names of all productlines and the associated suppliers. For this reason, I built a method GetAllProductLines() and bound it to the gridview. Furtherly, I attached the following datafields to the gridview:

<asp:BoundField DataField="Name" HeaderText="Name" />

<asp:BoundField DataField="SupplierId" HeaderText="Supplier" />

The gridview displays:

Name: xy (correct)

Supplier: [Namespace].Supplier

What´s wrong? How can I get the name of the suppliers? Please ask for more detailed information if this is not enough.

MG, J. Carl

A: 

If you are using

<many-to-one name="SupplierId" class="Supplier"/>

You want to have Supplier Id - not an entity. If you have an entity than you need to use

Supplier.SupplierId

field

Sly
Hello,could you go into more detail? How should I change the code?MG
Jan-Frederik Carl
A: 

Ok, I could solve the problem by the help of a good example.

In the Supplier class, I need to override the ToString()-property the following way:

public override string ToString()
    {
        return this.Name;
    }

This way, the GetAllProductLines-Method hands me over the name of the supplier.

Jan-Frederik Carl