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

Updating an Entry in a Database using Telerik OpenAccess ORM

1 Answer 109 Views
Databases and Data Types
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
EIMCM
Top achievements
Rank 1
EIMCM asked on 10 Feb 2014, 05:16 PM
Hello,

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?
                     dbcontext.SaveChanges();
             }
     }

Thanks,
Shaun

1 Answer, 1 is accepted

Sort by
0
Boris Georgiev
Telerik team
answered on 12 Feb 2014, 12:44 PM
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)
02.{
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.    }
09.}

I hope that helps.


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.
Tags
Databases and Data Types
Asked by
EIMCM
Top achievements
Rank 1
Answers by
Boris Georgiev
Telerik team
Share this question
or