這篇文章主要講解了“ADO.NET批注在編程中的意義是什么”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“ADO.NET批注在編程中的意義是什么”吧!
創(chuàng)新互聯(lián)一直通過網(wǎng)站建設(shè)和網(wǎng)站營銷幫助企業(yè)獲得更多客戶資源。 以"深度挖掘,量身打造,注重實效"的一站式服務(wù),以成都網(wǎng)站建設(shè)、成都做網(wǎng)站、移動互聯(lián)產(chǎn)品、成都營銷網(wǎng)站建設(shè)服務(wù)為核心業(yè)務(wù)。十載網(wǎng)站制作的經(jīng)驗,使用新網(wǎng)站建設(shè)技術(shù),全新開發(fā)出的標(biāo)準(zhǔn)網(wǎng)站,不但價格便宜而且實用、靈活,特別適合中小公司網(wǎng)站制作。網(wǎng)站管理系統(tǒng)簡單易用,維護方便,您可以完全操作網(wǎng)站資料,是中小公司快速網(wǎng)站建設(shè)的選擇。
ADO.NET批注使您能夠在不修改基礎(chǔ)架構(gòu)的情況下修改類型化 DataSet 中元素的名稱。如果修改基礎(chǔ)架構(gòu)中元素的名稱,則會使類型化 DataSet 引用不存在于數(shù)據(jù)源中的對象,并且會丟失對存在于數(shù)據(jù)源中的對象的引用。
利用批注,您可以使用更有意義的名稱來自定義類型化 DataSet 中對象的名稱,從而使代碼更易于閱讀,類型化 DataSet 更易于為客戶端使用,同時保持基礎(chǔ)架構(gòu)不變。例如,Northwind 數(shù)據(jù)庫中 Customers 表的以下架構(gòu)元素會生成 CustomersRow 這一 DataRow 對象名稱和一個名為 Customers 的 DataRowCollection。
<xs:element name="Customers"> <xs:complexType> <xs:sequence> <xs:element name="CustomerID" type="xs:string" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element>
DataRowCollection 名稱 Customers 在客戶端代碼中是有意義的,但 DataRow 名稱 CustomersRow 則會導(dǎo)致誤解,因為它是單個對象。此外,在通常情況下,將不使用 Row 標(biāo)識符來引用該對象,而僅將該對象當(dāng)作 Customer 對象來引用。解決方案是為架構(gòu)添加ADO.NET批注并標(biāo)識 DataRow 和 DataRowCollection 對象的新名稱。下面是上一架構(gòu)的批注版本。
<xs:element name="Customers" codegen:typedName="Customer" codegen:typedPlural="Customers"> <xs:complexType> <xs:sequence> <xs:element name="CustomerID" type="xs:string" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element>
將 typedName 的值指定為 Customer 將生成 DataRow 對象名稱 Customer。將 typedPlural 的值指定為 Customers 則會保留 DataRowCollection 名稱 Customers。
若要使用類型化 DataSet 批注,則必須在 XML 架構(gòu)定義語言 (XSD) 架構(gòu)中包含以下 xmlns 引用。
xmlns:codegen="urn:schemas-microsoft-com:xml-msprop"
下面是一個ADO.NET批注架構(gòu)示例,它公開 Northwind 數(shù)據(jù)庫的 Customers 表并包含與 Orders 表的關(guān)系。
<?xml version="1.0" encoding="utf-8"?> <xs:schema id="CustomerDataSet" xmlns:codegen="urn:schemas-microsoft-com:xml-msprop" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xs:element name="CustomerDataSet" msdata:IsDataSet="true"> <xs:complexType> <xs:choice maxOccurs="unbounded"> <xs:element name="Customers" codegen:typedName="Customer" codegen:typedPlural="Customers"> <xs:complexType> <xs:sequence> <xs:element name="CustomerID" codegen:typedName="CustomerID" type="xs:string" minOccurs="0" /> <xs:element name="CompanyName" codegen:typedName="CompanyName" type="xs:string" minOccurs="0" /> <xs:element name="Phone" codegen:typedName="Phone" codegen:nullValue="" type="xs:string" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="Orders" codegen:typedName="Order" codegen:typedPlural="Orders"> <xs:complexType> <xs:sequence> <xs:element name="OrderID" codegen:typedName="OrderID" type="xs:int" minOccurs="0" /> <xs:element name="CustomerID" codegen:typedName="CustomerID" codegen:nullValue="" type="xs:string" minOccurs="0" /> <xs:element name="EmployeeID" codegen:typedName="EmployeeID" codegen:nullValue="0" type="xs:int" minOccurs="0" /> <xs:element name="OrderAdapter" codegen:typedName="OrderAdapter" codegen:nullValue="1980-01-01T00:00:00" type="xs:dateTime" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> </xs:choice> </xs:complexType> <xs:unique name="Constraint1"> <xs:selector xpath=".//Customers" /> <xs:field xpath="CustomerID" /> </xs:unique> <xs:keyref name="CustOrders" refer="Constraint1" codegen:typedParent="Customer" codegen:typedChildren="GetOrders"> <xs:selector xpath=".//Orders" /> <xs:field xpath="CustomerID" /> </xs:keyref> </xs:element> </xs:schema>
感謝各位的閱讀,以上就是“ADO.NET批注在編程中的意義是什么”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對ADO.NET批注在編程中的意義是什么這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!
分享標(biāo)題:ADO.NET批注在編程中的意義是什么
分享路徑:http://chinadenli.net/article48/jgjdhp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、移動網(wǎng)站建設(shè)、App設(shè)計、小程序開發(fā)、虛擬主機、電子商務(wù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)