Updating several tables in relations

Posts   
 
    
rune1975
User
Posts: 2
Joined: 16-Jan-2006
# Posted on: 16-Jan-2006 17:11:11   

Hi, We're pretty new to LLBLGEN and wondering about best practices when it comes to updating many tables that have realtionships.

For instance, we have an "event" table containg sports, concerts, etc. and a "price_spec" table determining a category of prices (say "children", "adults",etc.), the finally a "price" table holding the prices, valid time periodes, etc.



      [event] - (1:n) - [price_spec] - (1:n) - [price]

At first glance it looks as if for each "level" we have to find the event (based on an id), then get the collection of price_specs, and for each item in this collection, get the price-collection, and then update each item in the collections on all levels.

Specifically, for an update on the "two lower levels" we have to traverse a collection of "Old prices", delete the ones that does not exist in the "new price collection". Then traverse the new collection and add the ones that do not exist in the Old collection. Alternatively delete the old collection and add the new one, but would it be optimal?

Then if a price_spec is cut, checking whether to delete this and the prices belonging to it.

This generates a lot of code and we're wondering what's the best way to handle all this updating. Any thoughts, tutorials og examples on this one?

Thanks a lot for your time and help, Rune

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 17-Jan-2006 02:33:05   

You may have to post a bit more detail about your specific instance if this doesn't provide a good answer. If you know the criteria for these updates you can make them without first fetching the data. Here's an example from the manual using C# and Selfservicing. You can see more under Best Practices - How do I update a series of entities directly in the database?

The example below will update all EmployeeID fields in all orders with the value of 5 where the current EmployeeID field is 2. SelfServicing:


// C#
OrderEntity newValues = new OrderEntity();
newValues.EmployeeID = 5;
IPredicateExpression filter = new PredicateExpression();
filter.Add(PredicateFactory.CompareValue(OrderFieldIndex.EmployeeID, ComparisonOperator.Equal, 2));
OrderCollection updater = new OrderCollection();
updated.UpdateMulti(newValues, filter);

// which is equal to:
OrderEntity newValues = new OrderEntity();
newValues.EmployeeID = 5;
OrderCollection updater = new OrderCollection();
updated.UpdateMulti(newValues, (OrderFields.EmployeeID == 2));

rune1975
User
Posts: 2
Joined: 16-Jan-2006
# Posted on: 17-Jan-2006 09:40:24   

Thanks, I think we're basically doing the right thing but was wondering whether we'd overlooked something or if there were any built-in shortcuts that we were missing, but have a feeling we're on the right track now. Thanks for your help and time simple_smile Rune