Updating child from parent?

Posts   
 
    
Ren
User
Posts: 42
Joined: 01-Jul-2005
# Posted on: 01-Jul-2010 18:54:27   

LLBLGen 1.0.2005.1/Adapter/

I am trying to update some child entities and for some reason all of the items get set with the same value.

My code below returns a Batch and the batch items using a pretch path


            var batch =
                _repository.GetEntityWithPredicate<InvoiceBatchEntity>(
                    _batchPredicate.GetInvoiceBatchDetailsByInvoiceBatchId(model.BatchId));


Next I loop through the many items and update a property. I set the cost property (for the 3 items) to 1, 2, 3.


            int i = 1;
            foreach (InvoiceBatchDetailEntity entity in batch.InvoiceBatchDetails)
            {
                entity.Cost = i; //this should increment so my cost for 3 items should be 1,2,3
                i++;
            }

Checking the values I see that everything looks good. The cost property is set and the entities are dirty.

Then I call an update like so:


            _repository.UpdateEntity(batch);

// the above code calls a method that looks like this:
        public TEntity UpdateEntity<TEntity>(TEntity updEntity) where TEntity : IEntity2
        {

           using (DataAccessAdapter adapter = new DataAccessAdapter())
           {
               adapter.SaveEntity(updEntity, false, true);  //recurse is true
           }

           return updEntity;
    }

The problem is that all of the items in the table after the update have a cost of 3. The update query that is used (from viewing SQL Profiler) for the detail has no predicate and it just sets all items to the last incremented from the foreach loop.

Any ideas would be appreciated on what I am doing wrong.

Thanks, E

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 01-Jul-2010 21:26:04   

First - you should get a prize for still using possibly the oldest version of LLBLGen still in production...simple_smile

Your code looks sensible - I can't see why anything in there should cause it to fail.

Could you post the code inside the GetInvoiceBatchDetailsByInvoiceBatchId method which retrieves the entities - perhaps something funny is going on in there...?

Could you also post the generated SQL.

Is there any chance you could upgrade to a newer version and try with that ?

Matt