2

我有一个绑定到 EntityDataSource 的 RadGrid。一些列绑定到绑定实体的导航属性。当我尝试删除记录时,会出现以下错误:

错误:Sys.WebForms.PageRequestManagerServerErrorException:在插入、更新或删除操作期间,在实体上找不到名为“Vehicle.VehicleNo”的属性。检查以确保指定为绑定表达式的属性可用于数据源。

我知道如果我选择使用普通的外键 ID,而不是导航属性,一切正常。如果我手动处理它,我可以很容易地让删除工作。但我只是在想,自动删除也必须有一种方法。有什么想法吗?

<telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True" 
                    AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
                    DataSourceID="EntityDataSource1" GridLines="None" ShowGroupPanel="True" Skin="Hay"
                    OnItemUpdated="RadGrid1_ItemUpdated" 
                    OnItemInserted="RadGrid1_ItemInserted" OnItemCommand="RadGrid1_ItemCommand"
                    Height="400px" Width="700px" CellSpacing="0">
                    <MasterTableView DataKeyNames="ADChecklistId" DataSourceID="EntityDataSource1" CommandItemDisplay="Top">
                        <CommandItemSettings AddNewRecordText="Add New Aerial Device Checklist" ShowRefreshButton="false"
                            ShowAddNewRecordButton="true"></CommandItemSettings>
                        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                            <HeaderStyle Width="20px" />
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                            <HeaderStyle Width="20px" />
                        </ExpandCollapseColumn>
                        <Columns>
                            <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn"
                                HeaderText="Edit">
                            </telerik:GridEditCommandColumn>
                            <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" UniqueName="DeleteCommandColumn" HeaderText="Delete" ConfirmDialogType="RadWindow" ConfirmText="Are you sure you want to delete this record?">
                            </telerik:GridButtonColumn>
                            <telerik:GridBoundColumn DataField="Vehicle.VehicleNo" FilterControlAltText="Filter VehicleNo column"
                                HeaderText="VehicleNo" SortExpression="Vehicle.VehicleNo" UniqueName="Vehicle.VehicleNo">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Employee.FirstName" FilterControlAltText="Filter FirstName column"
                                HeaderText="FirstName" SortExpression="Employee.FirstName" UniqueName="Employee.FirstName">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Employee.LastName" FilterControlAltText="Filter LastName column"
                                HeaderText="LastName" SortExpression="Employee.LastName" UniqueName="Employee.LastName">
                            </telerik:GridBoundColumn>  
                            <telerik:GridBoundColumn DataField="Utility.UtilityName" HeaderText="Utility" SortExpression="Utility.UtilityName" UniqueName="Utility.UtilityName" >
                            </telerik:GridBoundColumn>                                
                            <telerik:GridDateTimeColumn DataField="CreatedOn" DataType="System.DateTime" FilterControlAltText="Filter CreatedOn column"
                                HeaderText="CreatedOn" SortExpression="CreatedOn" UniqueName="CreatedOn" DataFormatString="{0:MM/dd/yy}">
                            </telerik:GridDateTimeColumn>
                            <telerik:GridBoundColumn DataField="CreatedBy" FilterControlAltText="Filter CreatedBy column"
                                HeaderText="CreatedBy" SortExpression="CreatedBy" UniqueName="CreatedBy">
                            </telerik:GridBoundColumn>
                            <telerik:GridDateTimeColumn DataField="ModifiedOn" DataType="System.DateTime" FilterControlAltText="Filter ModifiedOn column"
                                HeaderText="ModifiedOn" SortExpression="ModifiedOn" UniqueName="ModifiedOn" DataFormatString="{0:MM/dd/yy}">
                            </telerik:GridDateTimeColumn>
                            <telerik:GridBoundColumn DataField="ModifiedBy" FilterControlAltText="Filter ModifiedBy column"
                                HeaderText="ModifiedBy" SortExpression="ModifiedBy" UniqueName="ModifiedBy">
                            </telerik:GridBoundColumn>
                        </Columns>
                        <EditFormSettings>
                            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                            </EditColumn>
                        </EditFormSettings>
                    </MasterTableView>
                    <ClientSettings AllowDragToGroup="True" EnablePostBackOnRowClick="true">
                        <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                        <Resizing AllowColumnResize="true" ClipCellContentOnResize="false" />
                    </ClientSettings>
                    <FilterMenu EnableImageSprites="False">
                    </FilterMenu>
                    <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
                    </HeaderContextMenu>
                </telerik:RadGrid>
<asp:EntityDataSource ID="EntityDataSource1" runat="server" AutoGenerateWhereClause="True"
    ConnectionString="name=MSOpsEntities" DefaultContainerName="MSOpsEntities" 
    EnableFlattening="False" EnableDelete="True" EntitySetName="ADChecklists"
    Include="Vehicle, Employee, Utility" OrderBy="it.CreatedOn DESC" 
    OnSelecting="EntityDataSource1_Selecting" 
    ondeleting="EntityDataSource1_Deleting">
    <WhereParameters>
        <asp:SessionParameter Name="UtilityId" SessionField="utilityId" Type="Int32" />
    </WhereParameters>
</asp:EntityDataSource>
4

1 回答 1

0

尝试ReadOnly="true"GridBoundColumn包含导航属性的 s 上进行设置,这对我有用。也许你也可以使用模板列Eval而不是Bind

于 2012-03-19T10:20:16.183 回答