I want to do batch inserts quickly. Imagine that Order type has a Customer property. I have the customer's ID, and I want to create many orders quickly.

I want to set the Order.Customer property by ID, without having DO load the Customer entity from the database. Is this possible?

asked Mar 07 '11 at 22:36

ara's gravatar image


2 Answers:

Try to use DirectPersistentAccessor, here is example:

Entity entity = e.Entity;
var accessor = entity.Session.Services.Demand<DirectPersistentAccessor>();
var id = entity.TypeInfo.UnderlyingType.GetId();
var fieldInfo = entity.TypeInfo.Fields["ItemType.Id"];
accessor.SetFieldValue(entity, fieldInfo, id);

answered Mar 09 '11 at 02:14

pil0t's gravatar image


edited Mar 09 '11 at 02:17

Good idea! But i think this can only be possible if you switch off the validation features. (for example, business rule, you can only assign an Active Customer to an order, you need the load the customer entity and check the active state).

answered Mar 08 '11 at 04:59

Marco's gravatar image


Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview


Once you sign in you will be able to subscribe for any updates here



Asked: Mar 07 '11 at 22:36

Seen: 3,391 times

Last updated: Mar 09 '11 at 02:17

powered by OSQA