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

AutoInsert into DetailTable fails when using LINQ

1 Answer 75 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stephen Rochford
Top achievements
Rank 1
Stephen Rochford asked on 31 Jul 2008, 05:16 PM
I have a RadGrid that I am converting from using standard SQL datasources to using LINQDatasources.  This is a grid that has a two level hyerarchy with a mastertableview and a detailtableview which are defined as follows:

<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True"   
        AllowSorting="True" DataSourceID="FormulationDS"   
        GridLines="None" ShowGroupPanel="True"   
        AllowAutomaticInserts="True" AllowAutomaticUpdates="True"   
        EnableLinqExpressions="true">  
          
        <MasterTableView AutoGenerateColumns="False" DataKeyNames="FormNomId"   
           CommandItemDisplay="Top" DataSourceID="FormulationDS">  
  ..  
  ..   
  ..  
<DetailTables> 
                <telerik:GridTableView runat="server" CommandItemDisplay="Top"   
                    DataSourceID="FormBatchDS" AutoGenerateColumns="False"   
                    DataKeyNames="BatchId" AllowAutomaticInserts="true">  
                      
                    <ParentTableRelation> 
                        <telerik:GridRelationFields   
                            DetailKeyField="FormNomId"   
                            MasterKeyField="FormNomId" /> 
                    </ParentTableRelation> 
..  
..  
.. 
When I was using the SQL datasource automatic Inserts into the DetailTable (FormBatchDS) worked fine.  Now that I am using a LINQ datasource the parents MasterKeyField (FormNomId) is not getting passed to the DetailTable properly.  From what I see in the debugger (by putting a break point in the generated LINQ insert handler) FormNomId is being passed in as 0 when it should be some non-zero number. 

Is there some way to hook the grids insert command to set the proper value for that field before the insert is passed to the LINQ?  I figured out how to use the "ItemCommand" method to capture the "PerformInsertCommand" event and then read the parent records MasterKey value:

_formNomId = (int)(parentItem.OwnerTableView.DataKeyValues[parentItem.ItemIndex["FormNomId"]); 

which gets me the correct MasterKey, but I have not figured out how to update the data being submitted for insert so that the proper value is set when the data is passed to LINQ for the actual DB update.

By the way, if i make the FormNomId field visible and editable in the DetailTableView grid I can manually populate the field the the Insert works just find.  Make it read-only and/or not visible and the Insert fails.

Thanks,
Stephen

1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 04 Aug 2008, 10:02 AM
Hello Stephen,

One possible option would be to preserve the field, as a normal editable field, and simply hide it. Parallel to hiding it, you can also set some value for the textbox. This should be picked up by the insert statement, and the underlying database should be properly updated.
If this is not an option, or the issue persists, you can open a formal support ticket, and send us the problematic code, in the form of a small working project.

Sincerely yours,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Stephen Rochford
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or