Home > Database > Mysql Tutorial > WebMisCentral-Client 适配MySql数据库

WebMisCentral-Client 适配MySql数据库

WBOY
Release: 2016-06-01 13:14:03
Original
1156 people have browsed it

由于本身WebMisCentral采用的是EF5.0,所以适配起来还是非常简单的,下面看操作:

1.ElegantWM.WebUI层中(或者ElegantWM.DAL)通过NUGET下载MySQL.Data 6.7.5

2.修改Web.config如下:

<?xml version="1.0"?><!--For more information on how to configure your ASP.NET application, please visithttp://go.microsoft.com/fwlink/?LinkId=152368--><configuration><configsections><section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"></section><sectiongroup name="common"><section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"></section></sectiongroup><em><strong><section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirepermission="false"></section></strong></em></configsections><log4net configsource="log4netFile.xml"></log4net><connectionstrings><!--主数据库,支持多数据库--><add name="SqlServerDB" providername="System.Data.SqlClient" connectionstring="Server=localhost;Uid=sa;Pwd=o;DataBase=CN9295;"></add><em><strong><add name="DefaultDB" providername="MySql.Data.MySqlClient" connectionstring="Data Source=localhost;Port=3306;Initial Catalog=WMC;uid=assp;pwd=assp123;Character Set=utf8;"></add></strong></em></connectionstrings><appsettings><!--系统名称--><add key="SysName" value="WMC-Client"></add><!--请到http://saas.chinacloudtech.com注册账号--><add key="GroupCode" value=""></add><add key="SysId" value=""></add><add key="SSO" value="http://saas.chinacloudtech.com"></add><add key="webpages:Version" value="2.0.0.0"></add><add key="webpages:Enabled" value="true"></add><add key="PreserveLoginUrl" value="true"></add><add key="ClientValidationEnabled" value="true"></add><add key="UnobtrusiveJavaScriptEnabled" value="true"></add></appsettings><system.web>.....</system.web><system.webserver>......</system.webserver><runtime>........</runtime><em><strong><system.data><dbproviderfactories><remove invariant="MySql.Data.MySqlClient"></remove><add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.7.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></add></dbproviderfactories></system.data></strong></em></configuration>
Copy after login

注意上面蓝色的部分是新增的,其他的都不用动。

其中:connectionStrings里你可以随便加不同类型或同类型的多个数据库连接串,因为在WMC中数据库连接串是细化到对象的,不同对象可以拥有不同的连接串,即操作不同的数据库

3.修改ElegantWM.DAL的DBContext.cs,改成如下:

namespace ElegantWM.DAL{	public class DB : DbContext	{		//public static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);		//配置连接串,默认数据库DefaultDB		public DB(string _ConnectStr)			: base(<em><strong>_ConnectStr</strong></em>)		{			<em><strong>//这是以前的做法			//Database.Connection.ConnectionString = ConfigurationManager.ConnectionStrings[_ConnectStr].ToString();</strong></em>			Database.SetInitializer<db>(null);			//this.Configuration.LazyLoadingEnabled = false;		}</db>
Copy after login

4.遗憾的是MySql里的timestamp RowVersion在C# EF里支持不好,需要将byte[] 修改成 DateTime,故你需要将ElegantWM.EntityModel里面的Entity.cs和IEntity.cs中的RowVersion类型修改为DateTime,即可。

5.OK,你可以使用MYSQL了

6.MySql监控EF SQL的工具EFProf.exe,收费的,免费30天试用,用起来还是非常方便强大的。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template