Default Implementation of BusinessListBase.DataPortal_Update() - doesn't coorespond with book.

Default Implementation of BusinessListBase.DataPortal_Update() - doesn't coorespond with book.

Old forum URL: forums.lhotka.net/forums/t/6265.aspx


DCottle posted on Tuesday, January 27, 2009

In Chapter 5 of your C# 2008 Business Objects book, you state that "The BusinessListBase class includes a default implementation of the DataPortal_Update() method, which loops through all child objects (and deleted child objects) to ensure the appropriate Child_XYZ method is called on each when the collection is being saved."

Yet, when i look at the code in the BusinessListBase class, all I see is a NotSupportedException being thrown in DataPortal_Update.

Furthermore, you implemented within your Roles class in ProjectTracker similiar code that simply turns around and fires the Child_Update() method.

This omission means that we need to implement in each of our own BusinessListBase objects the desired behavior of calling the Child_Update method manually, correct?  This assumes that we actually want to allow edits on the BusinessListBase children to be saved.

Please tell me if I am missing something here...

RockfordLhotka replied on Tuesday, January 27, 2009

That's an error - the sentence is referring to the Child_Update() implementation that loops through the child objects.

You do need to implement DataPortal_Update(), because it is your responsibility to open the appropriate database connection (or whatever) so the child objects can be updated.

DCottle replied on Tuesday, January 27, 2009

Thanks Rocky!

One quick question though, with the connection pooling that you provide using your ConnectionManager, wouldn't we be able to delegate the connection string down into the Child_Update portion, thuse allowing the DataPortal_Update method to have a default implementation that calls the Child_Update?

I do not know if this makes sense at all...just thinking.

RockfordLhotka replied on Tuesday, January 27, 2009

If the BLB is a root object, then there’s no pre-existing connection. It is always the root object’s job to open/close the connection – and that’s something CSLA can’t do for you.

 

If the BLB is a child object (so it is owned by some other root object), then you have to implement nothing in the collection, because its parent will have triggered the Child_Update() method by calling either the FieldManager or DataPortal methods to trigger child updates. Of course in this case that other root object has the responsibility to open/close the connection.

 

Rocky

 

From: DCottle [mailto:cslanet@lhotka.net]
Sent: Tuesday, January 27, 2009 10:53 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Default Implementation of BusinessListBase.DataPortal_Update() - doesn't coorespond with book.

 

Thanks Rocky!

One quick question though, with the connection pooling that you provide using your ConnectionManager, wouldn't we be able to delegate the connection string down into the Child_Update portion, thuse allowing the DataPortal_Update method to have a default implementation that calls the Child_Update?

I do not know if this makes sense at all...just thinking.



ajj3085 replied on Monday, February 02, 2009

RockfordLhotka:
You do need to implement DataPortal_Update(), because it is your responsibility to open the appropriate database connection (or whatever) so the child objects can be updated.


I have a question regarding this.  In BB, you can call FieldManager.UpdateChildren( params[] ) to update the children.  For a root BLB, there's no FieldManager property.  Do you have to manually loop through and call DataPortal.UpdateChild for each instance in the list?

rsbaker0 replied on Monday, February 02, 2009

There is a Child_Update() method on BLB that will do this. The child data portal appears to call it via reflection, but I suspect you can also use it directly in a BLB derived class.

ajj3085 replied on Monday, February 02, 2009

Ok, I'll check that out and see if I can just call base.Child_Update.

Thanks!

RockfordLhotka replied on Monday, February 02, 2009

In a root BLB you should be able to call Child_Update() to trigger the updates:

 

protected override void DataPortal_Update()

{

  // open db connection

  Child_Update();

  // close db connection

}

 

Rocky

 

 

From: ajj3085 [mailto:cslanet@lhotka.net]
Sent: Monday, February 02, 2009 10:22 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Default Implementation of BusinessListBase.DataPortal_Update() - doesn't coorespond with book.

 

Image removed by sender.RockfordLhotka:

You do need to implement DataPortal_Update(), because it is your responsibility to open the appropriate database connection (or whatever) so the child objects can be updated.



I have a question regarding this.  In BB, you can call FieldManager.UpdateChildren( params[] ) to update the children.  For a root BLB, there's no FieldManager property.  Do you have to manually loop through and call DataPortal.UpdateChild for each instance in the list?


ajj3085 replied on Monday, February 02, 2009

That does the trick, thanks!

RobertSmith replied on Sunday, December 13, 2009

Am I correct in thinking that the db connection is opened in order to prevent distributed transactions from being used?

CyclingFoodmanPA replied on Sunday, December 13, 2009

The Csla.Data "manager" types exist to help you reuse the same connection for all your objects. This is a technique you can use with System.Transactions.TransactionScope transactions to avoid having TransactionScope use the DTC.

So yes, the idea is to avoid unnecessary use of an expensive distributed transaction.

Copyright (c) Marimer LLC