【问题标题】:EntityDataSource Show Entity Data With It Navigation PropertiesEntityDataSource 显示实体数据导航属性
【发布时间】:2010-09-25 13:58:14
【问题描述】:

您好,我有一个冷用户的实体,它有一个导航属性 UsersData 有一个字段“LastLoginDate”。

我想要做的是使用 EntityDataSource 在 GridView 中显示用户的一些信息(我不想在 linq 后面的代码中这样做)。

我尝试使用 EntityDataSource 的 Include 属性,但我不知道如何在我的 gridview 中使用它们来选择 LastLoginDate 字段有人可以帮助我吗? 它需要做一个非常基本的事情,显示一个关系表字段...... 这是我的代码:

<asp:EntityDataSource ID="EntityDataSource" runat="server" 
    ConnectionString="name=MyModelEntities" DefaultContainerName="ModelEntities" 
    EnableDelete="True" EnableInsert="True" 
    EnableUpdate="True" EntitySetName="Users" Include="UsersData" AutoGenerateWhereClause="True" 
    EnableFlattening="False">
</asp:EntityDataSource>

【问题讨论】:

    标签: asp.net .net entity-framework


    【解决方案1】:

    如果用户和用户数据之间的关系是多重性 1:1,您可以尝试添加到您的网格字段中:

    <asp:BoundField DataFiled="UsersData.LastLoginDate" HeaderText="Last Login" />
    

    UsersData 是用户实体中导航属性的名称。同样,您可以尝试在 TemplateField 中使用 Eval 表达式:

    <%# Eval("UsersData.LastLoginDate") %> 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多