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

Problem With Updating Object

2 Answers 37 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
EVP
Top achievements
Rank 2
EVP asked on 19 Jan 2015, 02:37 AM
Hi There,
         I'm having trouble updating an object via an ASP.NET application. I've shortened the update method below for just updating a single field from a form. When I look at the value for the website.Text item, it is showing the "updated" value, however the changes are not being pushed to the database itself. Any help would be appreciated!

01.public void UpdateRestaurant(Guid guid)
02.        {
03.                using (var dbContext = new WingFestEntitiesModel())
04.                {
05.                    Restaurant restaurantToUpdate = (from r in dbContext.Restaurants1 where r.restaurantid == guid select r).First();
06.                    restaurantToUpdate.website = website.Text;
07.                    dbContext.SaveChanges();
08.                }
09.                Response.Redirect("restaurant.aspx?task=create");
10.            }
11.        }

2 Answers, 1 is accepted

Sort by
0
Accepted
Boris Georgiev
Telerik team
answered on 21 Jan 2015, 08:47 PM
Hello Eric,

At first sight the code looks fine and it should work correctly. Unfortunately looking into this code fragment we couldn't see the surrounded code and the problems which could derived from that.

Could you make some verification and provide the result to us:
- Could you check what is the current value of the restaurantToUpdate.website property and the value of the website.Text property? Is it possible that the value of the website.Text property is not what you are seeing in the website?
- Could you check what is in the collection of the changed items in the context after you change the property value? You could access the collection through the GetChanges() method in the OpenAccessContext class - dbContext.GetChanges(). Could you find your entity in this collection?
- Could you check the state of the restaurantToUpdate object after you changed the property value? You could take the state with the GetState() method in the OpenAccessContext class - dbContext.GetState(restaurantToUpdate). If the property is changed correctly, the state of the object should be Dirty. More information about object states you could find here.

Answering these questions and any other information which you could provide for you scenario, will help us to understand the issue.

I am looking forward to hearing from you.

Regards,
Boris Georgiev
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
0
EVP
Top achievements
Rank 2
answered on 09 Feb 2015, 10:03 PM
Thanks for following-up Boris. I was able to solve the issue between when I posted and when you replied.

Enjoy your week!

Note for others with similar problem: I was using DevExpress fields, and there was some bizarre conflict that their control was causing. They looked at the project and were able to fix the issue.
Tags
General Discussions
Asked by
EVP
Top achievements
Rank 2
Answers by
Boris Georgiev
Telerik team
EVP
Top achievements
Rank 2
Share this question
or