Update in OpenAccess with multiple Domain models

Thread is closed for posting
2 posts, 0 answers
  1. Vipin
    Vipin avatar
    2 posts
    Member since:
    Jan 2013

    Posted 27 Feb 2013 Link to this post

    I am new to OpenAccess ORM.

    Say I have 3 domain models. 
    2. Address
    a. Id
    b. Address Line 1
    c. Address Line 2
    a. Id

    Employee and Address have 1 to 1 relation. Where as Address and Phone have 1 to Many relation. I can insert the code to DB by:

    Employee.Address = Address;

    But when Updating, I am having problems. I When I use  code similar to above

    Employee emp = Context.Employees.Where(<some condition>).toList().First();

    emp.Address = Address;


    , no error is thrown, but Phone and Adress is not getting updated.

    I feel like I am doing it all wrong. Can you guide me how to do Update with multiple domain levels in OpenAccess ORM?

  2. Doroteya
    Doroteya avatar
    498 posts

    Posted 04 Mar 2013 Link to this post

    Hi Vipin,

    Thank your for the detailed explanation.

    Generally, updating an object with Telerik OpenAccess ORM is performed by referencing it from the database, changing the values of its properties and calling the SaveChanges method of the context.

    In other words, in order to update the phone number of an employee, for example, you need to reference the needed Phone object and update the value of the PhoneNumber property (for details about the update operation check here).

    A possible solution that utilizes the multiple levels would look like this:
    using (EntitiesModel dbContext = new EntitiesModel())
          Employee emp = dbContext.Employees.First(<some condition>);
          Phone phone = emp.Address.Phones.Where(<some conditon>).First();
          phone.PhoneNumber = <a new value for the phone number>;

    If you experience any difficulties or have additional questions, do not hesitate to get back to us.


    the Telerik team
    OpenAccess ORM Q1 2013 is out featuring Multi-Diagrams, Persistent Data Stream Support and much more. Sign up for a free webinar to see all the new stuff in action.
Back to Top