views:

61

answers:

2

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.

A: 

Is there a particular reason you pass ConnectionString at all? It seems like a configuration value to me? So using something like a constant (or a Config singleton) might be a better idea.

Mene
I pass it because I like a complete separation of the "application" and the "datalayer" but your comment has made me start rethinking it. Really it is nothing more than a global string, so I can’t see much harm in using it directly in my data access layer right?
Maxim Gershkovich
+1  A: 

Use the app.config file for your connection string.

Anthony Faull
Good point, didn't notice that it was .net
Mene