Updating an Entry in a Database using Telerik OpenAccess ORM

Thread is closed for posting
2 posts, 0 answers
  1. EIMCM
    EIMCM avatar
    7 posts
    Member since:
    Nov 2010

    Posted 10 Feb 2014 Link to this post


    I have an MVC application and a user has the option to update a data model that is pulled from the database.  Is it possible to update the model in the database (SQL Management Server 2008) using Telerik OpenAccess ORM without having to set each individual property in the model?  Right now I update the db by a method that looks like this:

         public ActionResult Edit(QuoteViewModel _quote)
                 using(var dbcontext = new EntitiesModel())
                         var _existingQuote = dbContext.Quotes.Where(s => s.QuoteNum == _quote.QuoteNum).FirstOrDefault();
                         _existingQuote.CustomerName = "Mike";
                         _existingQuote.PhoneNumber = "8675309";
                         _existingQuote.Address = "5555 Nakatomi Plaza";
                         //more properties would follow?

  2. Boris Georgiev
    Boris Georgiev avatar
    190 posts

    Posted 12 Feb 2014 Link to this post

    Hi Shaun,

    Yes, you can update only the properties that you want to update. So if you want to update only the phone number of an existingQuote - you should get the entity from the database, change the value of the phone number property and save the change:
    01.public ActionResult Edit(QuoteViewModel _quote)
    03.    using(var dbcontext = new EntitiesModel())
    04.    {
    05.        var _existingQuote = dbContext.Quotes.Where(s => s.QuoteNum == _quote.QuoteNum).FirstOrDefault();
    06.        _existingQuote.PhoneNumber = "8675309";
    07.        dbcontext.SaveChanges();
    08.    }

    I hope that helps.

    Boris Georgiev
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
Back to Top