nopcommerce mysql_nopCommerce如何支持MySQL

本文档详细介绍了如何使nopCommerce支持MySQL数据库,包括在Easy.Data中添加MySqlConnectionFactory和MySqlDataProvider类,修改EfDataProviderManager加载数据提供程序的代码,调整初始化数据库的函数,更改领域模型的映射,并在安装界面添加MySQL配置选项。
摘要由CSDN通过智能技术生成

此方法支持nopCommerce2.4以上版本(缺少的代码,可参照nopCommerce2.6源码)

在工程Easy.Data中:

1、添加MySqlConnectionFactory和MySqlDataProvider

在Easy.Data目录下添加两个Class,MySqlConnectionFactory和MySqlDataProvider,

MySqlConnectionFactory:

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

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:

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值