3 tier application pattern suggestion

Posted by Maxim Gershkovich on Stack Overflow See other posts from Stack Overflow or by Maxim Gershkovich
Published on 2010-04-12T15:22:23Z Indexed on 2010/04/12 15:43 UTC
Read the original article Hit count: 332

Filed under:
|
|
|
|

I have attempted to make my first 3 tier application. In the process I have run into one problem I am yet to find an optimal solution for. Basically all my objects use an IFillable interface which forces the implementation of a sub as follows

Public Sub Fill(ByVal Datareader As Data.IDataReader) Implements IFillable.Fill

This sub then expects the Ids from the datareader will be identical to the properties of the object as such.

Me.m_StockID = Datareader.GetGuid(Datareader.GetOrdinal("StockID"))

In the end I end up with a datalayer that looks something like this.

Public Shared Function GetStockByID(ByVal ConnectionString As String, ByVal StockID As Guid) As Stock
        Dim res As New Stock
        Using sqlConn As New SqlConnection(ConnectionString)
            sqlConn.Open()
            res.Fill(StockDataLayer.GetStockByIDQuery(sqlConn, StockID))
        End Using
        Return res
 End Function

Mostly this pattern seems to make sense. However my problem is, lets say I want to implement a property for Stock called StockBarcodeList. Under the above mentioned pattern any way I implement this property I will need to pass a connectionstring to it which obviously breaks my attempt at layer separation.

Does anyone have any suggestions on how I might be able to solve this problem or am I going about this the completely wrong way? Does anyone have any suggestions on how I might improve my implementation? Please note however I am deliberately trying to avoid using the dataset in any form.

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about ASP.NET