|
|
|
Forum Guru
      
Group: Forum Members
Last Login: 2011-07-06 03:19:22
Posts: 65,
Visits: 156
|
|
I find the question at the url.
http://groups.google.com.tw/group/borland.public.delphi.modeldrivenarchitecture.eco/browse_thread/thread/f368f38698af0d7d/b709d602def132aa?hl=zh-TW&lnk=gst&q=InitializeComponent#b709d602def132aa
Just call it "ChangeDbCode" for the moment.
===========================================================
string EcoDbType = WebConfigurationManager.AppSettings["EcoDbType"];
string strConn = WebConfigurationManager.AppSettings["EcoDbConnection"];
switch (EcoDbType)
{
case "SQL2000":
{
persistenceMapperSqlServer1.Connection.ConnectionString = strConn;
PersistenceMapper = persistenceMapperSqlServer1;
} break;
case "MySQL":
{
persistenceMapperMySql1.Connection.ConnectionString = strConn;
PersistenceMapper = persistenceMapperMySql1;
} break;
}
===========================================================
In my concept,
ORM tools let change DB be a mouse click opration.
ECO does it indeed at designTime, but at runTime ECO could be more convinient.
In ECO designer view,
the EcoSpace Class does not need to care about what the real DB is.
So "ChangeDbCode" should be located in the constructor for the persistance mapper provider.
But in ECO user view,
if the "ChangeDbCode" can be located in user code area (for example: Webservice.asmx.cs),
"ChangeDbCode" is not mixed in ECO auto-generate area and that will be more explicit.
Is it possible?
.
|
|
|
|
|
Supreme Being
      
Group: Administrators
Last Login: 2010-11-30 12:17:13
Posts: 1 230,
Visits: 1 382
|
|
I'm sorry, I didn't understand the question, could you please rephrase? Do you want the code sample to be a part of the project template? Sorry for being a little slow today...
/Jonas Hogstrom [CapableObjects]
|
|
|
|
|
Forum Guru
      
Group: Forum Members
Last Login: 2011-07-06 03:19:22
Posts: 65,
Visits: 156
|
|
Put a persistenceMapperSqlServer1 and a persistenceMapperMySql1 on xxxPMP.cs
Could i dynamic change PersistenceMapper in Webservice.asmx.cs? (Not in constructor of xxxPMP.cs)
I hope "user code" no mix in "ECO auto-generate file" (like XXXEcoSpace.cs, xxxPMP.cs)
|
|
|
|
|
Supreme Being
      
Group: Forum Members
Last Login: 2012-01-27 18:06:44
Posts: 189,
Visits: 777
|
|
Hi there,
I can understand having a run-time configuration setting to change the persistence mapper based on what you actually want to use.
However, I can't understand why you would want to change that after you have started an application and configured the PersistenceMapperProvider. Once you have configured it, and started retrieving or adding objects, why would you want to change it again when things might be interacting with one database already?
Could you please explain what it is you are trying to achieve? It is a little difficult to advise you as to the best course of action without knowing, as well as you do, what it is you are trying to achieve. 
Kind regards, Scott
|
|
|
|
|
Forum Guru
      
Group: Forum Members
Last Login: 2011-07-06 03:19:22
Posts: 65,
Visits: 156
|
|
The developer burns a CD with ECO applications and many default DB files.
(like xxx.mdb, xxx.mdf, xxx.db3; already configured by PersistenceMapperProvider)
Then a salesman takes the CD to visit some customers.
Maybe each customer uses different DB.
After applitcation installation,
the customer copy his kind DB files from CD and hang up it.
The salesman just rewirte some words in config text file and then starts the demo.
==============================================================
Of course it could be achieved at the first post of the topic.
But I still hope "user code" no mix in "ECO auto-generate file".
[I hope the ideal code could be uesd in Webservice.asmx.cs]
EcoSapce.PersistenceMapper = EcoSapce.PersistenceMapperProvider.persistenceMapperSqlServer1;
EcoSapce.PersistenceMapperProvider.persistenceMapperSqlServer1.Connection.ConnectionString = ....
.
|
|
|
|
|
Supreme Being
      
Group: Forum Members
Last Login: 2012-01-27 18:06:44
Posts: 189,
Visits: 777
|
|
Yep, reconfiguration by runtime parameters is a common need.
I am sorry, the way I had read your post made me think you wanted to have an application start with one database, and then change it whilst it was running to another. I just didn't understand why you would want to do this. 
Normally I have an AppSetting that identifies the item I am wanting to use. Be it an enumeration value which defines the type of database to use, or a string, is really a preference thing for you to choose. 
Secondly the PersistenceMapperProvider will need to control the aspects of configuring the EcoSpace it is being asked to provide. It is at this point you would want to do your custom code.
I would suggest using a common named ConnectionString section entry, as it's easy to encrypt this at a later date without causing too much of an issue, hiding often rather key security information.
|
|
|
|
|
Forum Guru
      
Group: Forum Members
Last Login: 2011-07-06 03:19:22
Posts: 65,
Visits: 156
|
|
Let us think back some steps of creating an ECO project.
1. New a VisualStudio ECO project ========> mouse opration
2. Draw diagrams in xxx.mmcseco ========> user complex opration
3. Generate xxxClass.cs from model =======> mouse opration
4. Set persistenceMapperXXX in xxxPMP.cs ===> mouse opration
5. Evolve schema to DB ===============> mouse opration
6. Design View,Control(WebForm,WebService)=> user complex opration
To achieve dynamic changing DB,
the user code is locationed in constructor of xxxPMP.cs (Step4)
My point is "user code should no mix in ECO auto-generate file"
(user complex opration should no mix in mouse opration)
So the meaning of my question may be
" How to achieve dynamic changing DB in Step6 "
.
|
|
|
|
|
Forum Member
      
Group: Forum Members
Last Login: 2009-12-11 17:29:47
Posts: 27,
Visits: 281
|
|
I just don't understand why you want to do this.
The PersistenceMapperProvider is not auto-generated in the sense that it may be regenerated at any time.
It is a template.
It is normal to modify both the PMP and the EcoSpace classes.
Our intent was that the PMP should be the place where everything related to persistence is done. That is where you place
and configure the persistencemapper components, generate and evolve the database etc.
Having the code for configuring the connectionstring "somewhere else" defeats that. You can't just look at the PMP to see what is happening in that area.
|
|
|
|
|
Supreme Being
      
Group: Administrators
Last Login: 2010-11-30 12:17:13
Posts: 1 230,
Visits: 1 382
|
|
The constructor for the PersistenceMapperProvider is located in "PersistenceMapperProvider.cs", not in "PersistenceMapperProvider.Design.cs". Feel free to make any changes you want there. You can have a couple of persistencemappers on the designsurface of the provider, and select the relevant based on some setting in web.config or app.config.
In Eco5, the PersistenceMappers will have a ConnectionString-property so there will be no need to drop the actual connection components on the designer
You can load the value for the connectionstring properties from the config-file too if you want to, that way you can have full freedom to select the database you want dynamically. You will need a reference to the corresponding assembly (Eco.Persistence.MySql.dll etc) for each database you want to be able to connect to. There is no dynamic factory for the persistencemappers in ECO
/Jonas Hogstrom [CapableObjects]
|
|
|
|
|
Supreme Being
      
Group: Forum Members
Last Login: 2012-01-27 18:06:44
Posts: 189,
Visits: 777
|
|
I think there is some minor miscommunication issues here.
To suggest "dynamic changing DB" does, to me at least, suggest that this can be changed at any time throughout the life of the running process.
I think what you are asking is how best to configure Eco to use one of many possible database sources using some runtime configuration settings. I hope the following might help you:
In your SomethingPMP.cs file:
using System;
using System.ComponentModel;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using Eco.Persistence;
namespace EcoWrappingTest
{
public enum EcoDatabaseSource
{
MicrosoftSqlServer = 0,
MySql,
Firebird
}
public partial class EcoWrappingTestPMP : Eco.Persistence.PersistenceMapperProvider
{
// Other code that preceeds the constructor.
...
// PersistenceMapperProvider constructor
public EcoWrappingTestPMP(): base()
{
InitializeComponent();
// After InitializeComponent we can do the customizing of the database to use, and
// the connection string that we will be using this time.
ConnectionStringSettingsCollection conStrs = ConfigurationManager.ConnectionStrings;
NameValueCollection appSettings = ConfigurationManager.AppSettings;
ConnectionStringSettings css = conStrs["MyConnectionString"];
if (css != null)
{
string sConfigDatabaseSource = appSettings["MyDatabaseSourceKey"];
if (string.IsNullOrEmpty(sConfigDatabaseSource))
{
throw new ArgumentNullException("MyDatabaseSourceKey");
}
else
{
EcoDatabaseSource ds = (EcoDatabaseSource)System.Enum.Parse(typeof(EcoDatabaseSource), sConfigDatabaseSource);
switch (ds)
{
case EcoDatabaseSource.MicrosoftSqlServer:
{
this.persistenceMapperSqlServer1.Connection.ConnectionString = css.ConnectionString;
this.PersistenceMapper = this.persistenceMapperSqlServer1;
break;
}
case EcoDatabaseSource.MySql:
{
this.persistenceMapperMySql1.Connection.ConnectionString = css.ConnectionString;
this.PersistenceMapper = this.persistenceMapperMySql1;
break;
}
case EcoDatabaseSource.Firebird:
{
this.persistenceMapperFirebird1.Connection.ConnectionString = css.ConnectionString;
this.PersistenceMapper = this.persistenceMapperFirebird1;
break;
}
default:
throw new ArgumentException("EcoDatabaseSource Switch Value Error");
}
}
}
else
{
throw new ArgumentNullException("MyConnectionString");
}
}
}
This will parse the AppSettings key called "MyDatabaseSourceKey" and convert it into an Enumerated type. It wil try to obtain the ConnectionString by Name and use that connection string setting's .ConnectionString property as the source ConnectionString with which to configure the appropriate connection in the switch() block of code.
However, please note, this will only happen during the constructor of the PMP, so it is not actually dynamic as I would think of the term, rather a one-time configuration of the important ECO elements to control how this running instance will react to the chosen database settings.
I hope that helps you.
Kind regards,
Scott
|
|
|
|