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

Hierarchiel Radgrid LINQ INSERT problem

1 Answer 86 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 2
Darren asked on 12 Nov 2008, 10:36 AM

Hi again,

I have a Hierarchiel radgrid of 2levels. My first level is populated by LinqDataSourceTargetCategory.
2nd level is populated by LinqDataSourceTargetCategoryInfo.

Level 1 data is from tblTargetCategory.
Level 2 data is from tblTargetCategoryInfo.

LinqDataSourceTargetCategoryInfo has:

 Where="TargetCategoryId == @TargetCategoryId">        
               <asp:Parameter Name="TargetCategoryId" Type="Int32" />

So it knows which record in level 2 grid belong to which record from level1. I also have:
     <MasterTableView DataKeyNames="TargetCategoryId" DataSourceID="LinqDataSourceTargetCategory"
          CommandItemDisplay="Top" Width="100%"> 

and have

          <telerik:GridRelationFields DetailKeyField="TargetCategoryId" MasterKeyField="TargetCategoryId" />                           

tblTargetCategoryInfo has a foreign key TargetCategoryId which comes from tblTargetCategoryId(is primarykey).

I've done this so that my radgrid can load correctly which is does. It loads the 2nd level and associates the records according to TargetCategoryId.

On level one i can INSERT UPDATE DELETE fine using:


But here is the problem. On my 2nd level the data loads correctly but when i want to do an INSERT it says:

"INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK_tblTargetCategoryInfo_tblTargetCategory'. The conflict occurred in database 'spe', table

'tblTargetCategory', column 'TargetCategoryId'.
The statement has been terminated."

So i turned off "Enforce foreign key constraint rule" to see what value was been parsed into TargetCategoryId, i noticed it was 0. Obviously causing the error.
TargetCategoryId should be equal to the record which i'm working with, which is on level 1.
So if i'd have record x on level 1 with TargetCategoryId = 1,
then i expand and add a new item y. When i insert i want it to automatically know that i'm adding it to with TargetCategoryId = 1 which is x.

I'm using LINQ datasources.
Sorry for the long post but rather i give you all the information you need to help me. Hope it was a clear description of the problem.



I went to and look at the ASPX. It's a custom type of Datasource.. How can i do that INSERT normally? Somehow my DELETE and UPDATE work fine.

1 Answer, 1 is accepted

Sort by
Top achievements
Rank 2
answered on 13 Nov 2008, 10:02 AM
Asked by
Top achievements
Rank 2
Answers by
Top achievements
Rank 2
Share this question