Hi i'm again
the problem is as follows:
I have a datagrid (asp.net) wich list users, users have a UserType, i can order the datagrid by any property of User class, except for the propertis linked with other tables
TipoUsuario.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Business.Data.TipoUsuario,Business" table="TipoUsuario">
<id name="IdTipoUsuario" column="idTipoUsuario" type="Int32" unsaved-value="0">
<generator class="native" />
</id>
<bag name="UsuarioList" inverse="true" lazy="true">
<key column="idTipoUsuario" />
<one-to-many class="Business.Data.Usuario,Business" />
</bag>
<property column="tipoUsuario" type="String" name="nTipoUsuario" not-null="true" length="50" />
<property column="baja" type="Boolean" name="Baja" not-null="true" />
</class>
</hibernate-mapping>
Usuario.hbm.xmlCode:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Business.Data.Usuario,Business" table="Usuario">
<id name="IdUsuario" column="idUsuario" type="Int32" unsaved-value="0">
<generator class="native" />
</id>
<property column="apellido" type="String" name="Apellido" length="50" />
<property column="nombre" type="String" name="Nombre" length="50" />
<property column="usuario" type="String" name="nUsuario" not-null="true" length="50" />
<property column="pass" type="String" name="Pass" not-null="true" length="50" />
<property column="mail" type="String" name="Mail" not-null="true" length="50" />
<many-to-one name="IdTipoUsuario" column="idTipoUsuario" class="Business.Data.TipoUsuario,Business" />
<property column="baja" type="Boolean" name="Baja" not-null="true" />
</class>
</hibernate-mapping>
the Datagrid html codeCode:
<asp:TemplateColumn SortExpression="nUsuario" HeaderText="Usuario">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "nUsuario") %>' />
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn SortExpression="idTipoUsuario" HeaderText="TipoUsuario">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "idTipoUsuario.nTipoUsuario") %>' />
</ItemTemplate>
</asp:TemplateColumn>
The problem is when sorting by
idTipoUsuario in the second TemplateColumn coz idTipoUsuario refers to an object so then I change this for "idTipoUsuario.nTipoUsuario" but nothing the Datagrid can't find the property "idTipoUsuario.
nTipoUsuario" in the TipoUsuario column.
It's possible use sorting in this way? how ?
i'm so tried putting the SortExpression like this
SortExpression="<%# DataBinder.Eval(Container.DataItem, "idTipoUsuario.nTipoUsuario") %>"
but fails too.
In this case i must use the common (System.Data ) bindigs for the grid? or convert the NHibernate objects to datatable and use this ?
Somebody with a torch?
Thanks in advance!
Antares