This is a migrated thread and some comments may be shown as answers.

Error with automatic delete when RadGrid is bound to EntityDataSource

6 Answers 84 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Han
Top achievements
Rank 1
Han asked on 02 Sep 2011, 05:39 PM
Hi,
I have a RadGrid that's bound to EntityDataSource. A few of the columns are bound to navigation properties of the bound entity. When I try to delete a record, it gives the following error:

Error: Sys.WebForms.PageRequestManagerServerErrorException: A property named 'Vehicle.VehicleNo' was not found on the entity during an insert, update, or delete operation. Check to ensure that properties specified as binding expressions are available to the data source.

I know if I choose to use the plain foreign key IDs, instead of the navigation properties, everything works. I can easily get the delete to work if I handle it manually. But I"m just thinking there's got to be a way for the automatic delete to work too. Please advise.

<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>

6 Answers, 1 is accepted

Sort by
0
Shawn Clabough
Top achievements
Rank 1
answered on 03 Sep 2011, 08:46 AM
I too am just having the same erro using EF4 and the RadGrid.  I'm not using navigation properties during my delete though, just foreign/primary keys.

"Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: A property named 'Rooms' was not found on the entity during an insert, update, or delete operation. Check to ensure that properties specified as binding expressions are available to the data source."

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BuildingsAndRooms.aspx.cs" Inherits="SchedulerTest.BuildingsAndRooms" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title></title>
    <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" />
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <Scripts>
            <%--Needed for JavaScript IntelliSense in VS2010--%>
            <%--For VS2008 replace RadScriptManager with ScriptManager--%>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
        </Scripts>
    </telerik:RadScriptManager>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="rlbBuildings">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="rlbRooms" />
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="rbAddBuilding">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="rlbBuildings" />
                    <telerik:AjaxUpdatedControl ControlID="txtNewBuilding" />
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="rbAddRoom">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="rlbRooms" />
                    <telerik:AjaxUpdatedControl ControlID="txtNewRoomName" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
        <ClientEvents></ClientEvents>
    </telerik:RadAjaxManager>
    <div>
        <fieldset style="width:400px">
            <legend>Buildings</legend>
            <telerik:RadListBox ID="rlbBuildings" runat="server" AllowDelete="True" DataKeyField="BuildingPK" DataSourceID="BuildingsDataSource" DataTextField="BuildingName" DataValueField="BuildingPK" EmptyMessage="No buildings found" AutoPostBack="True" OnSelectedIndexChanged="rlbBuildings_SelectedIndexChanged" AllowAutomaticUpdates="True" AutoPostBackOnDelete="True">
                <ButtonSettings TransferButtons="All"></ButtonSettings>
                <EmptyMessageTemplate>
                    No buildings found
                </EmptyMessageTemplate>
            </telerik:RadListBox>
            <br />
            New Building Name:
            <asp:TextBox ID="txtNewBuilding" runat="server"></asp:TextBox>
            <br />
            <telerik:RadButton ID="rbAddBuilding" runat="server" Text="Add Building" onclick="rbAddBuilding_Click">
            </telerik:RadButton>
        </fieldset>
        <fieldset style="width:400px;">
            <legend>Rooms for selected building</legend>
            <telerik:RadListBox ID="rlbRooms" runat="server" AllowDelete="True" DataKeyField="RoomPK" DataSourceID="RoomsDataSource" DataTextField="RoomName" DataValueField="RoomPK" AllowAutomaticUpdates="True" AutoPostBack="True" AutoPostBackOnDelete="True">
            </telerik:RadListBox>
            <br />
            New Room Name:<asp:TextBox ID="txtNewRoom" runat="server"></asp:TextBox>
            <br />
            <telerik:RadButton ID="rbAddRoom" runat="server" Text="Add Room" onclick="rbAddRoom_Click">
            </telerik:RadButton>
        </fieldset>
    </div>
    <asp:EntityDataSource ID="BuildingsDataSource" runat="server" ConnectionString="name=SqlTestEntities" DefaultContainerName="SqlTestEntities" EnableDelete="True" EnableFlattening="False" EnableInsert="True" EnableUpdate="True" EntitySetName="Buildings">
        <DeleteParameters>
            <asp:Parameter Name="BuildingPK" DbType="Int32" />
        </DeleteParameters>
    </asp:EntityDataSource>
    <asp:EntityDataSource ID="RoomsDataSource" runat="server" ConnectionString="name=SqlTestEntities" DefaultContainerName="SqlTestEntities" EnableDelete="True" EnableFlattening="False" EnableInsert="True" EnableUpdate="True" EntitySetName="Rooms" AutoGenerateWhereClause="True" CommandText="" Where="">
        <WhereParameters>
            <asp:ControlParameter ControlID="rlbBuildings" Name="BuildingFK" PropertyName="SelectedValue" Type="Int32" DefaultValue="0" />
        </WhereParameters>
    </asp:EntityDataSource>
    </form>
</body>
</html>
0
Accepted
Daniel
Telerik team
answered on 08 Sep 2011, 12:33 PM
Hi guys,

@Zhe: You have to set ReadOnly = true to the columns that are bound to navigation properties.

@Shawn: I examined your code, but I'm afraid that it is hard to guess what causes this error judging by the provided snippets. Could you please post your RadGrid declaration here?

Regards,
Daniel
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Han
Top achievements
Rank 1
answered on 08 Sep 2011, 03:08 PM
Daniel:
That fixed my problem. Thanks.
Do you know why it has to be set to "ReadOnly=true" for the delete to work?

Han
0
Shawn Clabough
Top achievements
Rank 1
answered on 08 Sep 2011, 05:32 PM
Daniel, Sorry, I was working on two things at once and got my circuits crossed. This time I was getting the error using a radlistbox, not a radgrid.
0
Peter
Top achievements
Rank 1
answered on 22 Oct 2014, 05:47 AM
My single navigation property is already read-only equals true, however I've now added a new unbound GridCheckBox column - and this seems to be the cause. When I look at the extracted form values, it shows up as a blank item/key in the hashtable. 

How do I have an unbound checkbox in my automatic updated grid? (And avoid this error?). Use a template column instead?

0
Kostadin
Telerik team
answered on 24 Oct 2014, 01:05 PM
Hi ,

@Shawn - I am afraid we still need the code in order to investigate it further. Meanwhile you can check whether the filed names are equal in the EntityDataSource and in the RadListBox.

@Peter - I would recommend you to use a TemplateColumn with a CheckBox control as an EditTemplate instead GridCheckBox column. Additionally could you please let me know which edit mode you are using?


Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Han
Top achievements
Rank 1
Answers by
Shawn Clabough
Top achievements
Rank 1
Daniel
Telerik team
Han
Top achievements
Rank 1
Peter
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or