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

LinqToSQL Bound Automatic Update

2 Answers 115 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Oliver
Top achievements
Rank 1
Oliver asked on 13 Jul 2017, 11:02 AM

So, I have a hierarchical Radgrid bound to two LinqToSQL Datasources, and I'm trying to get Updates working on the second level table. Inserts work perfectly but when attempting to update a row, I get an "Object Reference not set to an instance of an object" exception, but it doesn't cause any error to be displayed on the page. I can only see the error through Visual Studio while debugging. See ASPX code below. I have no code doing anything in the codebehind so far.

05.<asp:UpdatePanel ID="upGrid" runat="server" ChildrenAsTriggers="true">
06.<ContentTemplate>
07.<telerik:RadGrid ID="masterGrid" runat="server"
08.AutoGenerateColumns="False"
09.DataSourceID="linqDepots"
10.OnUpdateCommand="masterGrid_UpdateCommand">
11.<ClientSettings>
12.<Selecting AllowRowSelect="true" />
13.</ClientSettings>
14.<GroupingSettings CollapseAllTooltip="Collapse all groups" />
15.<MasterTableView DataSourceID="linqDepots" DataKeyNames="dID,dCode">
16.<Columns>
17.<telerik:GridBoundColumn DataField="dID" ForceExtractValue="Always" Visible="false"></telerik:GridBoundColumn>
18.<telerik:GridBoundColumn DataField="dCode" FilterControlAltText="Filter dCode column" HeaderText="Depot Code" ReadOnly="True" SortExpression="Depot Code" UniqueName="dCode">
19.</telerik:GridBoundColumn>
20.<telerik:GridBoundColumn DataField="dName" FilterControlAltText="Filter dName column" HeaderText="Depot Name" ReadOnly="True" SortExpression="Depot Friendly Name" UniqueName="dName">
21.</telerik:GridBoundColumn>
22.<telerik:GridBoundColumn DataField="IncidentCount" HeaderText="Incidents"></telerik:GridBoundColumn>
23.</Columns>
24.<DetailTables>
25.<telerik:GridTableView Name="Incident" runat="server" DataSourceID="linqIncidents" CommandItemDisplay="Top"  AllowAutomaticInserts="true" AllowAutomaticUpdates="true" DataKeyNames="iID">
26.<ParentTableRelation><telerik:GridRelationFields DetailKeyField="fk1_dID" MasterKeyField="dID" /></ParentTableRelation>
27.<Columns>
28.<telerik:GridEditCommandColumn Display="true" EditText="Update"></telerik:GridEditCommandColumn>
29.<telerik:GridBoundColumn DataField="iID" Visible="false" ReadOnly="true"></telerik:GridBoundColumn>
30.<telerik:GridBoundColumn HeaderText="Acc Ref" DataField="AccRef" SortExpression="iID" UniqueName="AccRef" ReadOnly="true">
31.<FilterTemplate>
32.<telerik:RadComboBox ID="ddlFilterID" runat="server" Width="50px" DataSourceID="LinqiID" DataTextField="iID" DataValueField="iID" OnClientSelectedIndexChanged="SelectedRefIndexChanged" SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("AccRef").CurrentFilterValue %>' AppendDataBoundItems="true">
33.<Items><telerik:RadComboBoxItem Text="All" Value="" /></Items>
34.</telerik:RadComboBox>
35.<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
36.<script type="text/javascript"> function SelectedRefIndexChanged(sender, args) { var tableView = $find(" <%# ((GridItem)Container).OwnerTableView.ClientID %>"); tableView.filter("AccRef", args.get_item().get_value(), "EqualTo"); } </script>
37.</telerik:RadScriptBlock>
38.</FilterTemplate>
39.</telerik:GridBoundColumn>
40.<telerik:GridDateTimeColumn DataField="iDate" DataType="System.DateTime" AllowFiltering="false" ItemStyle-HorizontalAlign="Center" FilterControlAltText="Filter iDate column" HeaderText="Date" SortExpression="iDate" UniqueName="iDate" DataFormatString="{0:d}"></telerik:GridDateTimeColumn>
41.<telerik:GridDropDownColumn DataField="fk2_dID" DataSourceID="linqDrivers" HeaderText="Driver" ListTextField="dName" ListValueField="dID"></telerik:GridDropDownColumn>
42.<telerik:GridDropDownColumn DataField="fk3_cID" DataSourceID="linqVehicle" HeaderText="Vehicle" ListTextField="cReg" ListValueField="cID"></telerik:GridDropDownColumn>
43.<telerik:GridCheckBoxColumn AllowFiltering="False" DataField="iNotificationForm" HeaderText="Notification Form" SortExpression="iNotificationForm"/>
44.<telerik:GridCheckBoxColumn AllowFiltering="False" DataField="iInterviewForm" HeaderText="Interview Form" SortExpression="iInterviewForm"/>
45.<telerik:GridCheckBoxColumn AllowFiltering="False" DataField="iAccidentForm" HeaderText="Accident Form" SortExpression="iAccidentForm"/>
46.<telerik:GridBoundColumn AllowFiltering="False" DataField="iEstimate" HeaderText="Estimate" SortExpression="iEstimate" DataType="System.Decimal" DataFormatString="{0:c}" FilterControlAltText="Filter iEstimate column" UniqueName="iEstimate"/>
47.<telerik:GridBoundColumn AllowFiltering="False" DataField="iClarkesCost" HeaderText="Cost" SortExpression="iClarkesCost" DataType="System.Decimal" DataFormatString="{0:c}"/>
48.<telerik:GridCheckBoxColumn AllowFiltering="False" DataField="iPaid" HeaderText="Paid" SortExpression="iPaid"/>
49.<telerik:GridBoundColumn AllowFiltering="False" DataField="iDescription" HeaderText="Description" SortExpression="iDescription"/>
50.<telerik:GridBoundColumn DataField="iLocation" HeaderText="Location" SortExpression="iLocation"/>
51.<telerik:GridCheckBoxColumn DataField="iDriverAware" Visible="false" HeaderText="Driver Aware"></telerik:GridCheckBoxColumn>
52.<telerik:GridBoundColumn DataField="DriverAwareStr" HeaderText="Driver Aware" SortExpression="iDriverAware" ReadOnly="true"/>
53.<telerik:GridCheckBoxColumn DataField="iDriverFault" Visible="false" HeaderText="Driver at Fault"></telerik:GridCheckBoxColumn>
54.<telerik:GridBoundColumn DataField="DriverFaultStr" HeaderText="Driver at Fault" SortExpression="iDriverFault" ReadOnly="true"/>
55.<telerik:GridBoundColumn DataField="iAJGRef" HeaderText="AJG Ref" SortExpression="iAJGRef" FilterControlAltText="Filter iAJGRef column" UniqueName="iAJGRef" ReadOnly="True" />
56.</Columns>
57.</telerik:GridTableView>
58.</DetailTables>
59.</MasterTableView>
60.</telerik:RadGrid>
61.<asp:LinqDataSource ID="linqDepots" runat="server" ContextTypeName="Forms_BI.RetorqueLinqDataContext" Where="dID != 0"
62.EntityTypeName="" TableName="Depots"></asp:LinqDataSource>
63.<asp:LinqDataSource ID="linqIncidents" runat="server" ContextTypeName="Forms_BI.RetorqueLinqDataContext"
64.EntityTypeName=""
65.TableName="Incidents" Where="fk1_dID == @fk1_dID"
66.EnableInsert="True" EnableUpdate="true" OnUpdating="linqIncidents_Updating">
67.<WhereParameters>
68.<asp:Parameter Name="fk1_dID" Type="Int32" />
69.</WhereParameters>
70.</asp:LinqDataSource>
71.<asp:LinqDataSource ID="linqDrivers" runat="server" ContextTypeName="Forms_BI.RetorqueLinqDataContext" EntityTypeName="" TableName="Drivers"></asp:LinqDataSource>
72.<asp:LinqDataSource ID="linqVehicle" runat="server" ContextTypeName="Forms_BI.RetorqueLinqDataContext" EntityTypeName="" TableName="Cabs"></asp:LinqDataSource>
73.</ContentTemplate>
74.</asp:UpdatePanel>

2 Answers, 1 is accepted

Sort by
0
Oliver
Top achievements
Rank 1
answered on 17 Jul 2017, 09:02 AM

I've narrowed down the issue to when the LinqDataSource tries to perform the update. Stacktrace below. Anyone have any ideas why the automatic update fails in this way? Do I need to add a setting on the RadGrid to expose some extra data or something?

at Forms_BI.Insurance.linqIncidents_Updating(Object sender, LinqDataSourceUpdateEventArgs e)
at System.Web.UI.WebControls.LinqDataSourceView.OnUpdating(LinqDataSourceUpdateEventArgs e)
at System.Web.UI.WebControls.LinqDataSourceView.UpdateObject(Object oldEntity, Object newEntity)
at System.Web.UI.WebControls.QueryableDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues)
at System.Web.UI.WebControls.ContextDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues)
at System.Web.UI.WebControls.LinqDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues)
at System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback)
0
Marin Bratanov
Telerik team
answered on 18 Jul 2017, 01:03 PM

Hi Oliver,

I am pasting here my initial response to the same question from your ticket, in case it helps someone else.

There is nothing obviously wrong with the provided setup.

At this point I can offer three ideas:

 

 

Regards,

 

Marin Bratanov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Oliver
Top achievements
Rank 1
Answers by
Oliver
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or