1. 修改MySQLDatabaseAssembler.cs文件
public class MySQLDatabaseData : DatabaseData
{
#region Public Methods
public MySQLDatabaseData(ConnectionStringSettings connectionStringSettings, IConfigurationSource configurationSource)
: base(connectionStringSettings, configurationSource)
{
}
#endregion
public override System.Collections.Generic.IEnumerable<Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.TypeRegistration> GetRegistrations()
{
yIEld return new TypeRegistration<Database>(
() => new MySQLDatabase(
ConnectionString,
Container.Resolved<IDataInstrumentationProvider>(Name))) {
Name = Name,
Lifetime = TypeRegistrationLifetime.TransIEnt
};
}
}
2. 修改MySqlDatabase.cs文件中的構造函數和在MySQLDatabase類上加上配制屬性
[ConfigurationElementType(typeof(MySQLDatabaseData))]
public class MySQLDatabase : Database
{
public MySQLDatabase(string connectionString)
: base(connectionString, MySQLClIEntFactory.Instance)
{
}
public MySQLDatabase(string connectionString, IDataInstrumentationProvider instrumentationProvider)
: base(connectionString, MySQLClIEntFactory.Instance, instrumentationProvider)
{
}
3. 編譯MySQLDAAB項目
4. 在項目中引用MySQLDAAB項目
5. 配制文件中如下配制:
<configSections>
<section name="dataConfiguration"
type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings,
Microsoft.Practices.EnterpriseLibrary.Data" />
</configSections>
<dataConfiguration >
<providerMappings>
<add name="MySql.Data.MySQLClIEnt"
databaseType="EntLibContrib.Data.MySql.MySqlDatabase, MySQLDAAB" />
</providerMappings>
</dataConfiguration>
<system.data>
<DbProviderFactorIEs>
<add
name="My Sql Data Provider Factory"
invariant="MySql.Data.MySQLClIEnt"
description=""
type="MySql.Data.MySqlClIEnt.MySQLClIEntFactory" />
</DbProviderFactorIEs>
</system.data>
<connectionStrings>
<add name="TestDB_MySQL"
connectionString="server=127.0.0.1;database=test;User Id=root;PassWord=****;Persist Security Info=True;"
providerName="MySql.Data.MySQLClIEnt"/>
</connectionStrings>
這樣就可以使用MySQL數據庫了。