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

Grid returns null properties that were not edited.

2 Answers 47 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ben Hayat
Top achievements
Rank 2
Ben Hayat asked on 20 Dec 2012, 01:51 AM
Hello Team;
Let me first provide some info, before discussing my problem.

Previously I had used EF and "ObjectCondext" for my Model. Then for each ASP Page that I needed DataSource, I had used ObjectDataSource (ODS). In the ODS declaration, I had identified the "Update" method which takes two parameters. One the modified object and the second the Original object.
In the Update method first I would attach the Original object to my ObjectContext first and the call "ApplyCurrentValues" Method from ObjectContext and pass the modified object. This method would then compare the properties between the two objects and create the proper SQL update command to update only Modified properties.

Now, with this new project, I'm using CodeFirst and DbContext and unfortunately DBContext does not have "ApplyCurrentValues" Method to pass two objects (before & after). It only takes the modified object.

But I'm running into a serious problem with Telerik Grid in this situation. Let's say I have a customer object with 20 properties and three Foreign key properties. If I connect the Grid to ObjectDataSource and have only 5 properties as "Editable" in the grid, when I do an update, the grid returns me an object with all the properties, but all the other 15 properties that were not editable and bound to TextBox (with Bind), they all become Null, including all my Foreign key fields.
In most cases, I don't need to have all the properties shown, Especially the foreign key values.

How do I solve this problem, that the grid returns me the original values of those properties that were not changed? 
..Ben

2 Answers, 1 is accepted

Sort by
0
Ben Hayat
Top achievements
Rank 2
answered on 20 Dec 2012, 02:55 AM
Perhaps, I can summarize the problem as following:
When I pass and object to the grid, and properties (including those holding Foreign key values) that are not bound to grid columns, the grid replaces the original values with null and passes me back and object with only properties that were bound to grid.

In many cases I don't need to display ALL the properties. How can I solve this? What am I doing wrong?
Thanks!
0
Ben Hayat
Top achievements
Rank 2
answered on 20 Dec 2012, 02:29 PM
I came up with a workaround this problem that I'd like to share with others, but not sure if this the best. Hoping something less manual.

Basically, once the grid passes back the object to the middle tier repository class, I have to read a fresh copy of that class from the database and then replace those changed properties from the object returned from grid to the new object and then save the new object back. Sounds like a lot of manual work.
But is this how to work with ObjectDataSource and Telerik grid?
Thanks!
Tags
Grid
Asked by
Ben Hayat
Top achievements
Rank 2
Answers by
Ben Hayat
Top achievements
Rank 2
Share this question
or