Proper use of one to many

4 posts, 0 answers
  1. Rob
    Rob avatar
    3 posts
    Member since:
    Aug 2007

    Posted 15 Nov 2012 Link to this post

    Hi - I'm new to OpenAccess, so I may just not be doing this right. I have a model that has a property that's 1:M. When I save the context, I see in the ORM profiler that it's loading the whole M:1 collection on the 1 before saving. Why would the framework need to load the whole collection just to associate 1 record? I'm using version 2012.3.1012.1. Here's my example in more concrete terms:

    Invoice model has one Employee
    Each Employee can have many Invoices they are associated with

    I'm doing this, with an Employee model that's already been loaded from the DB:

    var invoice = new Invoice
        {
            CreatedDate = DateTime.UtcNow,
            Employee = employee,
        };
    Context.Add(invoice);
    Context.SaveChanges()

    Before saving the new Invoice record, I can see in the profiler that a LEFT JOIN from Employee to Invoice is executed, which is returning all of the Invoices for that employee. All I want it to do is set the foreign key value and save.

    Thanks for your help,

    Rob
  2. Rob
    Rob avatar
    3 posts
    Member since:
    Aug 2007

    Posted 16 Nov 2012 Link to this post

    I'm a current, paying customer of Telerik, is there an alternative to the forums to get my question answered? It's time sensitive, and I would like a response.

    Thanks,

    Rob
  3. DevCraft banner
  4. Ralph Waldenmaier
    Admin
    Ralph Waldenmaier avatar
    202 posts

    Posted 19 Nov 2012 Link to this post

    Hello Rob,

    While we are always trying to get you the necessary guidance and answers in our community forums as well, we encourage you to open support tickets for matters of high urgency. Another thing you can do as a licensed client of Telerik OpenAccess ORM is to state in your forum post that you would like a fast reply - this way we will consider your thread with priority and we can still contribute to the OpenAccess ORM community with the problem resolution.

    The behavior you experience is expected in case your 1:m association is configured to be managed. This means that we will populate the collection of Invoices in your Employee object when assigning an employee to your Invoice.

    To avoid this behavior, you need to set the IsManaged property to false. You can find details here

    Feel free to ask if you have any other question.

    Kind regards,
    Ralph
    the Telerik team
    Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
  5. Rob
    Rob avatar
    3 posts
    Member since:
    Aug 2007

    Posted 19 Nov 2012 Link to this post

    Thanks for the info. I've created a support ticket instead.
Back to Top