新聞中心
ADO.NET DbProviderFactories發(fā)展還是很快的,就使用ADO.NET DbProviderFactories并擴(kuò)充兼容mysql我深入的研究了一下,在這里給大家分享一下,我們現(xiàn)在一起來(lái)看看吧。ADO.NET2.0 。

成都創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作、二道江網(wǎng)絡(luò)推廣、微信平臺(tái)小程序開發(fā)、二道江網(wǎng)絡(luò)營(yíng)銷、二道江企業(yè)策劃、二道江品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營(yíng)等,從售前售中售后,我們都將竭誠(chéng)為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);成都創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供二道江建站搭建服務(wù),24小時(shí)服務(wù)熱線:028-86922220,官方網(wǎng)址:www.cdcxhl.com
ADO.NET通用接口的限制:接口不易擴(kuò)展,ADO.NET1.1無(wú)法創(chuàng)建某些類的實(shí)例,ADO.NET1.1無(wú)法判斷可用的.NET數(shù)據(jù)提供程序。提供工廠模型如何解決上述限制,通過(guò)抽象積累來(lái)擴(kuò)展ADO,NET模型,#t#
使用ADO.NET DbProviderFactories類來(lái)創(chuàng)建對(duì)象。提供程序工廠模型的限制,許多查詢結(jié)構(gòu)都是數(shù)據(jù)庫(kù)特有的。為參數(shù)化查詢?cè)O(shè)置CommandText時(shí),可能需要提供程序特有的代碼,指定參數(shù)數(shù)據(jù)類型可能需要提供程序特有的代碼。
為了使開發(fā)的代碼通用,不局限于特定的數(shù)據(jù)庫(kù),本次開發(fā)中決定使用DbProviderFactory+標(biāo)準(zhǔn)SQL,以開發(fā)一個(gè)適用于mysql和 sqlserver的封裝,但DbProviderFactories 并沒(méi)有提供對(duì)mysql的DbProviderFactory的支持,所以需要擴(kuò)充ADO.NET DbProviderFactories類兼容mysql,而且在ADO.net 2.0中mysql和sqlserver的ParameterMarkerFormat都有bug,所以擴(kuò)展類要解決這個(gè)bug。
- public static class DbProviderFactoriesEx { public static DbProviderFactory GetFactory(string providerName)
- { if (providerName == null) throw new ArgumentNullException("providerName"); DbProviderFactory dbFactory;
- switch (providerName) { case "MySql.Data.MySqlClient": return new MySqlClientFactory(); default:
- return DbProviderFactories.GetFactory(providerName); } } public static string GetParameterMarkerFormat(DbConnection connect)
- { if (connect == null) throw new ArgumentNullException("connect"); Type type = connect.GetType();
- if (type == typeof(MySql.Data.MySqlClient.MySqlConnection)) return "?{0}";//mysql bug
if (type == typeof(System.Data.SqlClient.SqlConnection)) return "@{0}";//ms bug connect.Open();- string result = connect.GetSchema("DataSourceInformation").Rows[0]["ParameterMarkerFormat"].ToString(); connect.Close(); return result; } }
當(dāng)前標(biāo)題:ADO.NETDbProviderFactories發(fā)展與兼容說(shuō)明
URL地址:http://fisionsoft.com.cn/article/cojejpd.html


咨詢
建站咨詢
