Problem With Updating Object

3 posts, 1 answers
  1. EVP
    EVP avatar
    8 posts
    Member since:
    Jul 2013

    Posted 18 Jan 2015 Link to this post

    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. Answer
    Boris Georgiev
    Admin
    Boris Georgiev avatar
    190 posts

    Posted 21 Jan 2015 Link to this post

    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.
     
  3. DevCraft banner
  4. EVP
    EVP avatar
    8 posts
    Member since:
    Jul 2013

    Posted 09 Feb 2015 in reply to Boris Georgiev Link to this post

    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.
Back to Top