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

Proper use of one to many

3 Answers 65 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Rob
Top achievements
Rank 1
Rob asked on 15 Nov 2012, 04:00 PM
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

3 Answers, 1 is accepted

Sort by
0
Rob
Top achievements
Rank 1
answered on 16 Nov 2012, 10:38 PM
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
0
Ralph Waldenmaier
Telerik team
answered on 19 Nov 2012, 04:44 PM
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.
0
Rob
Top achievements
Rank 1
answered on 19 Nov 2012, 05:12 PM
Thanks for the info. I've created a support ticket instead.
Tags
General Discussions
Asked by
Rob
Top achievements
Rank 1
Answers by
Rob
Top achievements
Rank 1
Ralph Waldenmaier
Telerik team
Share this question
or