StrataFrame Forum

Dynamic DataSourceKey?

http://forum.strataframe.net/Topic23527.aspx

By dgsoft - 6/16/2009

Hi,

I want on fly in my application switch between databases, each of them has own DataSourceKey.



My problem is - If I not write the DataSourceKey hardcoded for BO component, I have an error like DataSourceKey is empty...

The question is - how can I make dynamic datasourcekey and also.. question.. can businessobjectmapper as default take my subclass of businesslayer, where I can add additional standard functionality for my projects.



For this purpose I thought to do





Public Class PSOFormStore_PensBO

Inherits MicroFour.StrataFrame.Business.BusinessLayer



#Region " Data Retrieval Methods "



Overloads ReadOnly Property DataSourceKey() As String

Get

Return(DatabaseManager.GetCurrentDataSourceKey())

End Get

End Property

#End Region

End Class



Public Class DatabaseManager

Public Shared Function GetCurrentDataSourceKey() as String

Return("TEST")

End Func

End Class

By Trent L. Taylor - 6/17/2009

If you change the data source key of a BO instance, you will have call the ReCreateDataLayer method on the BO to have it pull from the new data source key. That is the ONLY trick.



MyBO.DataSourceKey = "NewKey"

MyBO.ReCreateDataLayer()




As for creating a subclassed BO, that is not something you need to do through the BO Mapper. When you create a new BusinessLayer, just change the inheritance once. This is done in the main class instead of the Designer file so that the BO Mapper leaves the inheritance alone. But if you put the inheritance declaration on the partial class (designer file) it will be overwritten every time the partial is rebuilt. This is why, by default, we put the inheritance in the main file. That is all that is required.