在所选数据源上找不到具有名称的字段或属性

Dav*_*key 6 vb.net asp.net linq-to-entities entity-framework entity-framework-4

我有一个实体数据模型,其中包含两个实体"角色"和"用户".我有一个导航属性,我有一个EntityDataSource和一个GridView.EntityDataSource指向Users实体并具有Include ="Roles"参数.

我在GridView中添加了一个BoundField,它指向RoleName,它是实体Roles的一个属性.但是,当我执行代码时,我得到上述错误.

我在另一个应用程序中成功使用了非常相似的代码 任何想法为什么这不起作用?

这是我的EntityDataSource:

    <asp:EntityDataSource ID="EntityDataSource1" runat="server" 
    ConnectionString="name=pbu_checklistEntities" 
    DefaultContainerName="pbu_checklistEntities" EnableDelete="True" 
    EnableFlattening="False" EnableUpdate="True" EntitySetName="Users" Include="Role">
    </asp:EntityDataSource>
Run Code Online (Sandbox Code Playgroud)

这是BoundField:

<asp:BoundField DataField="RoleName" HeaderText="Role" SortExpression="RoleName" />
Run Code Online (Sandbox Code Playgroud)

Sla*_*uma 20

您不能将asp:BoundFielda用作相关导航属性的属性.您只能使用a asp:TemplateField然后将其绑定为readonly with Eval(not Bind).BoundFields总是在Bind内部使用,这就是它无法工作的原因.我不得不在不久前解决这个问题:

一个带有EntityDataSource的ASP.NET GridView中的两个相关数据库表的列

  • 这似乎只适用于IIS 6而不是IIS 7.任何人都可以确认或否认这种差异吗? (2认同)
  • 是John Bledsoe,我尝试在VS 2010/IIS 6设置上部署我在VS 2013/IIS 7上开发的项目时遇到了这个问题.在VS 2013/IIS 7环境中进行测试时,我没有遇到任何问题.将所有内容转换为TemplateFields对我有用. (2认同)