How to maintain Connection between Parent Object and Children Object?

Topics: Data Access Application Block
Mar 17, 2011 at 2:18 AM

This is my situation, im my Business Class, after Insert Parent object, Insert Child object(s) immediately, Parent and Children have their own DataAccess Classes  ParentDao and ChildDao, my question is how to maintain Database Connection between Parent and Children? Thanks!

Mar 17, 2011 at 2:42 AM

Is the reason behind is that you want to perform transactional update, insert or delete between the two?  If that is the case, you can create a DbConnection from a Database object by calling database.CreateConnection and then create a DbTransaction by calling dbConnection.BeginTransaction().  The ExecuteNonQuery allows you to pass a DbTransaction object so that it executes on a transaction thus sharing the same connection. 

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Mar 17, 2011 at 3:06 AM

Do you mean there is no need that my ChildDao class contain a Database instance, and let ParentDao pass a Conection to ChildDao?

Mar 17, 2011 at 3:16 AM

I would think a DbTransaction parameter in the ChildDao class instead of a DbConnection since most likely, the transaction has already been created at the ParentDao.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Mar 17, 2011 at 3:25 AM
Edited Mar 17, 2011 at 3:25 AM

Thank you for your so timely response, i 'm building an app using Csla.net + Entlib, something confusing me.

Mar 17, 2011 at 4:00 AM

You're welcome.  Do you have any further questions about this?

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com