Adapter save recursively

Posts   
 
    
Posts: 94
Joined: 23-Aug-2006
# Posted on: 24-Mar-2007 17:55:56   

The snippet below is adding an entity to a collection. For some reason it keeps complaining about an index out of range on the line that assigns a LanguageId. Has anyone seen similar behavior?

Dont know if this makes a difference but the entire process happens while iterating across a collection of departments. For each dept it potentially adds an employee and for each employee it potentially adds the Reviews -- all in one graph, which I hope gets subsequently saved properly by the adapter.......

I'm only showing the specific snippet that has me stopped.

Thanks!

[code][code]--code section removed for brevity ---


            if (department.Employee[0].EmployeeReview.Count == 0)

            {

                department.Employee[0].EmployeeReview.Add(new EmployeeReviewEntity());

                department.Employee[0].EmployeeReview[0].Title = reviewTitle;
                department.Employee[0].EmployeeReview[0].Description = reviewDesc;
                department.Employee[0].EmployeeReview[0].EmployeeId = department.Employee[0].EmployeeId;
                department.Employee[0].EmployeeReview[0].LanguageId = 1;

            }
            
            
            adapter.SaveEntity(department, false);
            
  ---code section removed for brevity ---
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 25-Mar-2007 03:23:24   

You simple code snippet above should work. Please provide Exception detail and more code. Thanks.

David Elizondo | LLBLGen Support Team
Posts: 94
Joined: 23-Aug-2006
# Posted on: 25-Mar-2007 07:00:50   

Yep thats why I'm puzzled. As I mentioned before, LLBLGen throws and "Index Out of Range Exception". I wonder if its something I'm doing..... in another method of the same class I have the following which gets an identical index out of range exception I've noted the line with a short comment below. As you can see the code is pretty similar.


if (dashboardProduct.ProductItem.Count == 0)
{
    dashboardProduct.ProductItem.Add(new ProductItemEntity());
}

    dashboardProduct.ProductItem[0].Upcnumber = sonyProduct.Upc;
    dashboardProduct.ProductItem[0].TaxTypeId = productItemItemTypeId;
    dashboardProduct.ProductItem[0].ProductItemTypeId=productItemItemTypeId;


if (dashboardProduct.ProductItem[0].ProductItemWarehouse.Count == 0)
{
    dashboardProduct.ProductItem[0].ProductItemWarehouse.Add(new ProductItemWarehouseEntity());
}

    dashboardProduct.ProductItem[0].ProductItemWarehouse[0].ProductItemId = dashboardProduct.ProductItem[0].ProductItemId;
    dashboardProduct.ProductItem[0].ProductItemWarehouse[0].WarehouseId = productItemWarehouseIdWarehouseId; <<Gets Index out of Range Exc.
    dashboardProduct.ProductItem[0].ProductItemWarehouse[0].HasInventory = productItemWarehouseHasInventory;
    dashboardProduct.ProductItem[0].ProductItemWarehouse[0].InventoryWarningLevel = productItemWarehouseIdInventoryWarningLevel;
    dashboardProduct.ProductItem[0].ProductItemWarehouse[0].InventoryReorderLevel = productItemWarehouseIdInventoryReorderLevel;
    dashboardProduct.ProductItem[0].ProductItemWarehouse[0].InventoryMinimumLevel = productItemWarehouseIdInventoryMinimumLevel;
    dashboardProduct.ProductItem[0].ProductItemWarehouse[0].AllowPreorder = productItemWarehouseAllowPreorder;
    dashboardProduct.ProductItem[0].ProductItemWarehouse[0].PreOrderLimit = productItemWarehouseIdPreOrderLimit;
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 25-Mar-2007 07:52:38   

I don't think that is a LLBL exception. However,

dashboardProduct.ProductItem[0].ProductItemWarehouse[0].ProductItemId = dashboardProduct.ProductItem[0].ProductItemId;

As I see, dashboardProduct.ProductItem[0].ProductItemId should be null at this point, as never has assigned at your code above.

dashboardProduct.ProductItem[0].ProductItemWarehouse[0].WarehouseId = productItemWarehouseIdWarehouseId; <<Gets Index out of Range Exc.

What's the value of productItemWarehouseIdWarehouseId variable at this point? Debug and watch what's going wrong.

Could you post the Exception's StackTrace and complete Exception Message.

David

David Elizondo | LLBLGen Support Team
Posts: 94
Joined: 23-Aug-2006
# Posted on: 25-Mar-2007 17:16:44   

That brings up an interesting question - should the assignment be handled differently because the ID - as you say - is null. It would be null until the save since this ID points to one of the objects in the graph that is inserted into the db as part of the save and therefore would not have an actual value to provide in this assignment even though this is a bit of a side issues and not the Out of Range problem, it could potentially mean I need to rework this because I have certain assumptions in regards to saving a graph that could be wrong. In which case the out of range issue becomes mute anyways..... simple_smile

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 25-Mar-2007 21:29:11   

You could search at LLBLGenPro Help and Forums. There are a lot of information about that. And for the OutOfSync I'm shure the StackTrace and ExceptionMessage will tell us where is the issue.

David Elizondo | LLBLGen Support Team