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

RadGrids with Entity Framework

3 Answers 131 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eric Neason
Top achievements
Rank 1
Eric Neason asked on 26 Aug 2011, 01:48 PM
I have 2 radgrids on my page, both bound with entity data sources. The second grid's data source uses a WHERE clause to filter the set by a parent/foriegn key.  The second grid is cofigured for allow inserts/updates/deletes on both the data source and radgrid. When I insert a record on the second grid I would like to pass the key field from the first grid to the foreign key on the second.  I have seen several examples to do this but even when a value is successfully passed to the edit column textbox, I get an Entity error that the foreign key is null. Can someone help with this or is this an Entity Framewwork issue?

3 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 01 Sep 2011, 07:41 AM
Hello Dan,

On what event are you trying to pass this value? Have you tried setting it as a predefined one as shown here:

Inserting Values Using InPlace and EditForms Modes (more specifically the Setting predefined values for different column editors section)

Generally, you should either set this value in the column editor on EditCommand, or if you are using UpdateCommand to do this, you should set the foreign key directly in the insert query to the datasource.

Best wishes,
Tsvetina
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
Eric Neason
Top achievements
Rank 1
answered on 01 Sep 2011, 08:02 PM
When I click on Add new record from the second grid, a blank new row appears.  If I manually add a value into the foreign key field and click Insert, the row posts to the database without errors.  If a pass a value to the foreign key field either from a Session variable or another grid's selected value and click Insert, the insert fails with an entiry framework error that the foriegn key was null. 
0
Tsvetina
Telerik team
answered on 06 Sep 2011, 03:12 PM
Hi Dan,

Have you tried setting the foreign key as a predefined value on InitInsert, as shown in the previously linked article? This will show the value in the edit form and then use it for the insert operation if you have allowed automatic operations for your grid. Does it not work in this way on your side?


All the best,
Tsvetina
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 >>

Tags
Grid
Asked by
Eric Neason
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Eric Neason
Top achievements
Rank 1
Share this question
or