简体   繁体   English

流利的nhibernate…将“ lookup”值映射到DataGrid

[英]fluent nhibernate … mapping 'lookup' value to DataGrid

To make this as simple as I can think to ask, if I have to classes: 为了使这一点尽可能的简单,我是否必须上课:

Order, OrderType, where an Order has 1 to 1 relationship with OrderType, how can I Bind (List) to a datagrid, and see the desired column/field from OrderType? Order,OrderType,其中一个Order与OrderType具有1到1的关系,如何将(列表)绑定到数据网格,并从OrderType中查看所需的列/字段?

When I bind a List to a datagrid, in the Order.OrderType 'field', I just get the name of the OrderType class with a guid. 当我将List绑定到数据网格时,在Order.OrderType'field'中,我只是获得带有GUID的OrderType类的名称。 I need to be able to say something like 'use the 'Code' field from the OrderType class. 我需要能够说出类似“使用OrderType类中的'Code'字段”之类的内容。

This isn't really an nhibernate question, as this problem could come up with any object, regardless of how's it's persisted. 这并不是一个真正的休眠问题,因为这个问题可能与任何对象有关,无论它如何持久存在。 What I think you're asking is you want to have a list of orders in a grid, and you want to bind to a property of another property that is a class. 我想您要问的是,您想要在网格中有一个订单列表,并且想要绑定到作为类的另一个属性的属性。

<asp:Gridview ID="gv1" runat="server">
   <Columns>
       <!-- regular properties -->
       <asp:BoundField DataField="Id" HeaderText="Id" />
       <asp:BoundField DataField="CreatedAt" HeaderText="DatePlaced" />

       <!-- property of a property-->
       <asp:TemplateField HeaderText="Order Code">
          <ItemTemplate>
                <asp:Label Text='<%#((Order)Container.DataItem).OrderType.Code %>' runat="server" />
          </ItemTemplate>           
       </asp:TemplateField>
   </Columns>
</asp:Gridview>

Hope that helps. 希望能有所帮助。

For WinForms, check out the solutions at Winforms DataGridView databind to complex type / nested property 对于WinForms,请查看Winforms DataGridView数据绑定到复杂类型/嵌套属性的解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM