Microsoft Enterprise Library 5.0 supports MYSQL

Source: Internet
Author: User

Three-step Enterprise Library support for MySQL database

1. Create a Mysqldatabasedata class

Using microsoft.practices.enterpriselibrary.common.configuration;using Microsoft.practices.enterpriselibrary.common.configuration.containermodel;using Microsoft.practices.enterpriselibrary.data;using microsoft.practices.enterpriselibrary.data.configuration;using Microsoft.practices.enterpriselibrary.data.instrumentation;using System.configuration;namespace grass.mysqldal.data{//<summary>//Describes a <see cref= "SQLDatabase"/> Instance, aggregating Informati  On from A///<see cref= "Connectionstringsettings"/&GT;. </summary> public class Mysqldatabasedata:databasedata {#region public Methods public Mysqldatabaseda Ta (connectionstringsettings connectionstringsettings, Iconfigurationsource configurationsource): Base ( Connectionstringsettings, Configurationsource) {} #endregion//<summary>//Creates a <see cre f= "Typeregistration"/> Instance describing the <see cref= "SQLDatabase"/> represented by// This configuration object. </summary>//<returns>a <see cref= "typeregistration"/> Instance describing A Database.</retu Rns> public override system.collections.generic.ienumerable< Microsoft.practices.enterpriselibrary.common.configuration.containermodel.typeregistration> GetRegistrations () {yield return new typeregistration<database> (() = new Mysqldatabase (connecti  Onstring, container.resolved<idatainstrumentationprovider> (name)) {name =    Name, Lifetime = typeregistrationlifetime.transient}; }  }}

2. Create a Mysqldatabase class

Using microsoft.practices.enterpriselibrary.common.configuration;using Microsoft.practices.enterpriselibrary.data;using Microsoft.Practices.EnterpriseLibrary.Data.Instrumentation;  Using Mysql.data.mysqlclient;namespace grass.mysqldal.data{///<summary>//MYSQL Database access Basics//</summary>    [ConfigurationElementType (typeof (Mysqldatabasedata))] public class Mysqldatabase:database {//<summary>    Initializes a new instance of the <see cref= "SQLDatabase"/> class with a connection string. </summary>//<param name= "connectionString" >the connection string.</param> public Mysqldatab    ASE (String connectionString): Base (connectionString, Mysqlclientfactory.instance) {}//<summary> Initializes a new instance of the <see cref= "SQLDatabase"/> class with A///connection string and Instrume    Ntation provider. </summary>//<param name= "connectionString" >the connection String.</param>//<param name= "Instrumentationprovider" >the instrumentation provider.</param> Public Mysqldatabase (String connectionString, Idatainstrumentationprovider instrumentationprovider): Base (Connectionstrin G, Mysqlclientfactory.instance, Instrumentationprovider) {}//<summary>//Retrieves parameter infor  Mation from the stored procedure specified in the <see cref= "DbCommand"/> and populates the Parameters collection of     The specified <see cref= "DbCommand"/> object. </summary>//<param name= "Discoverycommand" >the <see cref= "DbCommand"/> To do the discovery.&lt ;/param>//<remarks>the <see cref= "DbCommand"/> must be a <see cref= "SqlCommand"/> instance.< /remarks> protected override void DeriveParameters (System.Data.Common.DbCommand discoverycommand) {mysqlcom    Mandbuilder.deriveparameters ((Mysqlcommand) discoverycommand); }  }}



3. Add Config Support

<?xml version= "1.0"?><configuration> <!--MYSQL Enterprise Library supports-begin--> <configSections> <!--01. Declares a Database configuration section--<section name= "dataconfiguration" type= " Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data "/> </configSections> <dataconfiguration > <!--02. Register MYSQL Data Provider-<providerMappings> <add name= "MySql.Data.MySqlClient" databasetype= "Grass.mysqlda L.data.mysqldatabase, Grass.mysqldal "/> </providerMappings> </dataConfiguration> <system.data > <!--03. Register MySQL Data Provider factory class--<DbProviderFactories> <add name= "MySQL Provider Fac Tory "invariant=" MySql.Data.MySqlClient "description=" MySql Data Provider "type=" MySql.Data.MyS Qlclient.mysqlclientfactory "/> </DbProviderFactories> </system.data> <!--MYSQL Enterprise Library support-end--> &L T;connectionstrings>   <!--04. Database connection string--<add name= "Test_mysql" connectionstring= "server=127.0.0.1;database=test; User Id=root; password=123456;         Persist Security info=true; " Providername= "MySql.Data.MySqlClient"/> </connectionStrings></configuration>


OK, try it out ~ ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.