Hi,
I have a question about the persistence manager: I need to peek into several databases, all with the same schema and all mapped with the same model.dll before I decide wich one to use in my application. I have created my own DataSourceKeyResolver which returns a different connection string based on an entry in the registry. Simplified what I do is this:
Dim aEmployee As Employee
Dim EmployeeQuery As New EntityQuery(GetType(Employee))
Registry.SetValue(
"HKEY_CURRENT_USER\SOFTWARE\DimensionProject", "DataBase", "DP1")
'The line above instructs the datasourcekeyresolver to return a connection string to DP1
PersMgr = PersistenceManager.DefaultManager
EmployeeQuery.AddClause(Employee.EmployeeCodeEntityColumn, EntityQueryOp.EQ,
"JC")
aEmployee = PersMgr.GetEntity(
Of Employee)(EmployeeQuery)
MsgBox(aEmployee.Name)
'This shows data from DP1
PersMgr.QueryCache.Clear()
Dim pEntityTables As DataTableCollection = PersMgr.DataSet.Tables
Dim anEntityTable As DataTable
For Each anEntityTable In pEntityTables
ClearEntityTable(anEntityTable)
Next
PersMgr.Clear()
Registry.SetValue(
"HKEY_CURRENT_USER\SOFTWARE\DimensionProject", "DataBase", "DP2")
'Datasourcekeyresolver to return connection string to DP2. If I break the program in the
'keyresolver it DOES get called when I create the persistencemanager in th next line,
'and it DOES return the correct connectionstring
PersMgr = New PersistenceManager(True)
EmployeeQuery.AddClause(Employee.EmployeeCodeEntityColumn, EntityQueryOp.EQ,
"JC")
aEmployee = PersMgr.GetEntity(
Of Employee)(EmployeeQuery, QueryStrategy.DataSourceOnly)
MsgBox(aEmployee.Name)
'This still shows me data from DP1
If I "quickwatch" the peristencemanager and look at PersMgr.DataSourceResolver.mDataSourceResolver.DataSourceKeys.Items(0) it shown the correct connectionstring to DP2, but I still get data from DP1.
Am I missing a point somewhere or is it not possible to do something like this?
Best regards
Jesper Carstensen