Connection.open() on updating projectresource

Connection.open() on updating projectresource

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


Ton Smeets posted on Tuesday, October 03, 2006

Hello,

I'm new to CSLA. It is a very impressive framework. I bought the book after I discovered your site, and I intend to use it in developing my software. While reading the book, I came to the part where a ProjectResource get updated (page 441). Paging back (page 438) I discovered that the connection is opened by the ProjectResource, UpdateAssignment() is called, passing the connectionstring, then the commandobject is created, DoAddUpdate is called and the command is executed. In fact the insert and delete commands work the same way.

My question is; Could the Connection.Open() be called within DoAddUpdate() instead, by passing is the connection as a parameter.

Or am I missing the big picture here.

However, thanx for the great work.

Ton Smeets.

PS. I am from the Netherlands, and cann't figure out what 'leveraging' means. Please help me out here to.

JHurrell replied on Tuesday, October 03, 2006

Hi Tom and welcome to CSLA.

I can answer your question about "leveraging." Leverage means to use one thing to help you with another thing. In simple terms, think of using a lever like a metal bar to help you lift something heavy.

In the context of the book, Rocky uses "leverage" to mean: take a concept or piece of code that he's described and use it somewhere else.

- John

Ton Smeets replied on Tuesday, October 03, 2006

Wow,

Thank you for responding so quickly. I thought it might mean something like that.

Anyway, thank you.

JoeFallon1 replied on Wednesday, October 04, 2006

The key thing to remember when looking at Project Tracker is that it is just a sample - it is only one way to build and use BOs.

For Example here is what some Fetch code looks like in one of my BOs:

Protected Overrides Sub DataPortal_Fetch(ByVal criteria As Object)
 
DoFetch(criteria)
  ValidationRules.CheckRules()
End Sub

Protected Overridable Sub DoFetch(ByVal criteria As Object)
 
Dim cn As IDbConnection
 
Try
   
cn = DAL.CreateConnection
    cn.Open()
    PreFetchData(criteria, cn)
   
FetchData(criteria, cn)
    PostFetchData(criteria, cn)
    FetchChildren(criteria, cn)
 
Finally
   
cn.Close()
 
End Try
End Sub

As you can see - I call a Protected Overridable Sub called DoFetch which creates the connection (using my own DAL code which creates a SQL or Oracle connection as needed), opens it and passes it as a parameter to 4 other methods which are all Protected Overridable.

Using this style of code, I can use Codesmith to generate a Base class.
Then in my final type I can hand write code and Override any of the methods to add functionality.
If I need to use the Base functionality the Overriden method will make the call to MyBase and then add whatever it needs. If I need to change it completely, I just omit the call to MyBase.

Hope that helps.

Joe

Ton Smeets replied on Wednesday, October 04, 2006

Yes, I get the picture.

Reading further in Rocky's book some thing got clear to me.

Thank you for your response.

Copyright (c) Marimer LLC