Updating Order LineItems

Posts   
 
    
Valdar
User
Posts: 24
Joined: 07-Oct-2005
# Posted on: 30-Apr-2006 09:54:59   

I wasn't sure where to put this question.

I have an Order table and an OrderLineItems table. OrderLineItems has a FK relationship to the PK of the Order table.

Currently, when an order is being updated this is the process:

  1. Delete all the OrderLineItems from the database, with the adapter.DeleteEntityDirectly().
  2. Add new OrderLineItems to the Order.OrderLineItems collections.
  3. Save the updated Order, with adapter.SaveEntity();
  4. Save the OrderLineItems with adapter.SaveEntityCollection(Order.OrderLineItems);

I know there is a better way to do this, but perhaps I'm not seeing it?

Although I do have a PK on the OrderLineItems table the system I am synchronizing with (quickbooks) does not, so I have no way to tell if a particular LineItem has been updated or if it's an entirely new lineitem. This is why I delete everything first then re-add it.

Has anyone had a similar problem/solution?

sparmar2000 avatar
Posts: 341
Joined: 30-Nov-2003
# Posted on: 30-Apr-2006 11:15:39   

Given the contraints you have i.e.

Although I do have a PK on the OrderLineItems table the system I am synchronizing with (quickbooks) does not, so I have no way to tell if a particular LineItem has been updated or if it's an entirely new lineitem. This is why I delete everything first then re-add it.

the method you outlined seems to be safe. However, it is I/O intensive so....

if it is posible to compare OrderLineItems changes, then you could make it a bit more efficient. One method is to compare OrderLineItems ID just read from quickbooks against original OrderLineItems ID's that you have in memory. If it is new then you have an update;if it already esists then it is a possible update, so I am assumimng that maybe only one or two attributes would have chhanged e.g. Quantity, which you compare for changes. This method would allow you to minimise I/O because you go to the DB with only changes or updates.