此方法支持nopCommerce2.4以上版本(缺少的代码,可参照nopCommerce2.6源码)
在工程Easy.Data中:
1、添加MySqlConnectionFactory和MySqlDataProvider
在Easy.Data目录下添加两个Class,MySqlConnectionFactory和MySqlDataProvider,
MySqlConnectionFactory:
usingMySql.Data.MySqlClient;usingSystem;usingSystem.Collections.Generic;usingSystem.Data.Common;usingSystem.Data.Entity.Infrastructure;usingSystem.Linq;usingSystem.Text;namespaceEasy.Data
{public classMySqlConnectionFactory : IDbConnectionFactory
{private readonly string_baseConnectionString;private Func_providerFactoryCreator;publicMySqlConnectionFactory()
{
}public MySqlConnectionFactory(stringbaseConnectionString)
{this._baseConnectionString =baseConnectionString;
}public DbConnection CreateConnection(stringnameOrConnectionString)
{string connectionString =nameOrConnectionString;bool treatAsConnectionString = nameOrConnectionString.IndexOf('=') >= 0;if (!treatAsConnectionString)
{
MySqlConnectionStringBuilder builder= new MySqlConnectionStringBuilder(this.BaseConnectionString);
builder.Server=nameOrConnectionString;
connectionString=builder.ConnectionString;
}
DbConnection connection= null;try{
connection= this.ProviderFactory("MySql.Data.MySqlClient").CreateConnection();
connection.ConnectionString=connectionString;
}catch{
connection= newMySqlConnection(connectionString);
}returnconnection;
}public stringBaseConnectionString
{get{return this._baseConnectionString;
}
}internal FuncProviderFactory
{get{
Func func1 = this._providerFactoryCreator;return delegate(stringname)
{returnDbProviderFactories.GetFactory(name);
};
}set{this._providerFactoryCreator =value;
}
}
}
}
View Code
MySqlDataProvider:
usingEasy.Data.Initializers;usingMySql.Data.MySqlClient;usingSystem;usingSystem.Collections.Generic;usingSystem.Data.Common;usingSystem.Data.Entity;usingSystem.Data.Entity.Infrastructure;usingSystem.IO;usingSystem.Linq;usingSystem.Text;usingSystem.Web.Hosting;namespaceEasy.Data
{public classMySqlDataPro