Thursday, November 13, 2008

ADO.NET 3.5,要會什麼?

ADO.NET 3.5 的資料存取能力,已較 ADO.NET 2.0 時代已有較大的進步,並且又添加了 LINQ 這樣語言內資料存取的特異功能,讓 ADO.NET 3.5 的核心地位更形穩固,所以微軟特別針對 ADO.NET Application Development 發展一科考試 MCTS Exam 70-561: TS: Microsoft .NET Framework 3.5: ADO.NET Application Development,其考試內容涵蓋了 ADO.NET 2.0 以及新的 ADO.NET 3.5 功能。

Connecting to Data Sources (12 percent)

Manage connection strings

May include but is not limited to: using the ConnectionStringBuilder; leveraging the ConfigurationManager; protecting the connection string; using Security Support Provider Interface ( SSPI) or SQL Server authentication; correctly addressing the SQL Server instance; managing “User Instance” and AttachDBfilename

此為針對連線字串的設定能力,連線字串的學問其實不少,包括伺服器的連結(預設執行個體與具名執行個體),Windows/SQL 驗證,SQL Server Express 特殊功能的使用等。

而連線字串的儲存需要的 ConfigurationManager.ConnectionStrings 屬性,和動態產生 Connection String 的 ConnectionStringBuilder 物件都是需要知道的。

Manage connection objects

May include but is not limited to: managing connection state, managing connection pool; implementing persistent data connections; implementing Multiple Active Result Sets (MARS); encrypting and decrypting data

在連線建立以後,其連線狀態的管理能力,在資料庫應用程式是很重要的,尤其是在 Web Application 上,資料庫連線的消耗不能夠等閒視之。

Work with data providers

May include but is not limited to: Limitations, behaviors, performance, installation issues, deployment issues; ODBC, Microsoft OLE DB, SqlClient, managed providers, third-party providers, native providers

具有判斷與選用 Data Provider 的能力,像是 OLE DB Provider for ODBC (System.Data.Odbc), SQL Server OLE DB Provider (System.Data.SqlClient), 一般型的 OLE DB Provider (System.Data.OleDb) 等。

Connect to a data source by using a generic data access interface

May include but is not limited to: System.Data.Common namespace classes

System.Data.Common 命名空間提供了一般化的資料存取方法,例如 DbProviderFactory, DbDataAdapter, DbTransaction 等。

Handle and diagnose database connection exceptions

May include but is not limited to: Implementing try/catch handlers

處理資料庫連線時的錯誤狀況,一般都用 try/catch 來做。

Selecting and Querying Data (22 percent)

Build command objects

May include but is not limited to: building Parameters collections; using input and output parameters and return values; selecting an appropriate CommandType action; selecting an appropriate Execute method; using the CommandBuilder class; choosing appropriate CommandBehavior

當連線建起來後,就要利用 Command 來執行 SQL 以傳回 DataReader, DataTable 或 DataSet 等,簡化 SQL 指令可使用 CommandBuilder,但要知道其限制以及不應濫用。

Query data from data sources

May include but is not limited to: writing queries to solve assigned problems; implementing data paging; sorting, filtering, and aggregating data

以 DataTable/DataView 的操作 (DataTable.Select(), DataView.Sort, DataView.RowFilter 與 DataTable.Compute() 等方法) 以及 SQL 的查詢方法為主,雖然更多的 SQL 會在 SQL Server 的考試中測驗,不過開發人員也需要知道基礎的 SQL 撰寫。

Retrieve data source data by using the DataReader

May include but is not limited to: retrieving data from SELECT statements; retrieving data from stored procedures; working with multiple result sets

DataReader 的操作法,由於 DataReader 是 Forward-only 的,所以無法捯回捲動,而在多結果集的情況下的操作法也要熟悉 (DataReader.NextResult())。

Manage data by using the DataAdapter or the TableAdapter

May include but is not limited to: retrieving data from SELECT statements; etrieving data from stored procedures; working with multiple result sets; working with JOIN products; creating updatable DataAdapters and TableAdapters; modifying TableAdapter Fill methods

在 Web Application 用到的是 DataAdapter,而 Windows Form Application 用到的是 TableAdapter,兩者相似度高,然而有些地方不太相同。

Execute an asynchronous query

May include but is not limited to: handling asynchronous events

在資料庫執行資料存取時若會預期時間過長時,必須要用非同步的方法來做 (BeginExecuteReader, EndExecuteReader),以避免用戶端因為等待而 hang 住的狀況。

Handle special data types

May include but is not limited to: Binary Large Objects (BLOBs); Filestream, Spatial, Table Value Parameters

針對特殊物件,像是 BLOB (text, ntext, image), 以及 SQL Server 2008 新的特殊物件 FileStream, Spatial 與 Table Value Parameters 的處理方法。

Query data sources by using LINQ

May include but is not limited to: Extended method; CLR delegate; Lambda expressions; Classes of the System.LINQ.Expressions namespace

此處為 .NET Framework 3.5 新功能的部份:LINQ 的查詢分支,例如黏巴達運算式,CLR 委派以及查詢集合物件與 DataTable (LINQ to ADO.NET) 的功能。

Manage exceptions when selecting data

May include but is not limited to: Identifying and resolving syntax errors; Security exceptions

與處理連線錯誤的狀況相當,但此處要處理的是查詢語法,執行與安全性的例外狀況。

Modifying Data (24 percent)

Manage transactions

May include but is not limited to: Selecting an appropriate transaction isolation level; Participating in local transactions; Participating in distributed transactions; Using declarative transactions

處理交易的方法,包含 System.Transactions 的 TransactionScope, ADO.NET 本身的 BeginTransaction, Commit 與 Rollback,以及交易要使用的適當隔離層次等。

Manage data integrity

May include but is not limited to: Cascading updates or cascading deletes; Auto number management; Server-generated value management; Client-side data validation; Business rules, constraints

與資料庫相關的資料完整性管理,包含串連刪除/更新,自動編號管理,伺服器產生值管理,資料驗證,限制與規則等,這部份可能需要一點資料庫的知識基礎,建議可多看 Database System 的書籍。

Update data

May include but is not limited to: Update data by using stored procedures; DataSets to Data Source; Managing concurrency

使用 Command 來更新資料,是 Query Data 的一體兩面。

Manage exceptions when modifying data

May include but is not limited to: Resolve exceptions from data integrity, constraint, or referential integrity violations; Data locking conflicts; Data collision issues

處理資料更新的問題,其中比較麻煩的是 concurrency, locking 鎖定問題以及衝突問題,可利用 try/catch 來處理相對應的例外類別。

Transform data by using LINQ

May include but is not limited to: Aggregation operators; JOIN operator, QUERY operator, LIKE etc.

此處為 .NET Framework 3.5 新功能的部份:LINQ 的查詢分支的更新部份,JOIN/QUERY/LIKE 以及聚合函數等。

Synchronizing Data (15 percent)

Monitor event notifications

May include but is not limited to: Implement notifications by using SqlDependency or SqlNotificationRequest

利用 SqlDependency, SqlNotificationRequest 等方式來實作查詢通知能力。

Cache data

May include but is not limited to: SqlCacheDependency, Local Data Cache

ASP.NET 提供了 SqlCacheDependency 的能力,這個部份需要特別設定,而 Local Cache 以 ASP.NET 為例,可利用 Cache API 來實作。

Manage update conflicts between online data and offline data

處理更新衝突部份,可利用 DataTable.ContinueOnUpdateError 來保持更新發生錯誤時不會中斷,而且可由 DataTable 的事件來檢查與處理。

Partition data for synchronization

此為 Synchronization 的 Service。
可參考:http://msdn2.microsoft.com/en-us/library/bb726006(SQL.100).aspx

Implement Synchronization Services

May include but is not limited to: SyncAgent, SyncTable, ClientSyncProvider, ServerSyncProvider, SyncAdapter

此為 Synchronization Service for ADO.NET 的功能。
可參考:
http://msdn2.microsoft.com/en-us/library/microsoft.synchronization.data.server(SQL.100).aspx
http://msdn2.microsoft.com/en-us/library/microsoft.synchronization.data(SQL.100).aspx
http://msdn2.microsoft.com/en-us/library/microsoft.synchronization(SQL.100).aspx

Working with Disconnected Data (16 percent)

Manage occasionally connected data

管理不定時連結的資料,離線型資料由 DataSet, DataTable 來管理,同時要透過 DataAdapter 來更新資料。

Programmatically create data objects

May include but is not limited to: DataTable; DataSet

以程式化的方式來建立 DataTable 與 DataSet,這個功能相當實用,也相當好用,在資料管理上有相當的重要性。

Work with untyped DataSets and DataTables

May include but is not limited to: Populating a DataSet, DataTable

操作一般化的 DataSet, DataTable,儲如新增,修改,瀏覽與刪除資料等。

Expose a DataTableReader from a DataTable or from a DataSet

使用 DataTableReader 來讀取 DataTable/DataSet,操作法和 SqlDataReader 等相同,是順向型的資料存取物件。

Work with strongly typed DataSets and DataTables

此法與 untyped DataSet/DataTable 不太相同,它本身有自己的資料驗證格式與特別的資料存取法。

Object Relational Mapping by Using the Entity Framework (11 percent)

此主題為 ADO.NET Entity Framework 的部份。

Define and implement an Entity Data Model

May include but is not limited to: Mapping schemas and storage metadata; EDM Generator

此為 Entity Framework 中的 Entity Data Model 資料層與模式建立的部份,EDM Generator 則是自動產生資料與模型對應的工具。

Query data by using Object Services

May include but is not limited to: Querying data as objects and shaping results; Working with objects; Managing the Object Context; Customizing objects

此為 Entity Framework 中的 Object Service 部份,包含查詢與更新資料。

Map data by using the Entity SQL Language

May include but is not limited to: Manually define mapping files; Execute an Entity SQL Query by using EntityCommand

此為 Entity Framework 中的 System.Data.EntityClient 命名空間的部份,包含 Entity SQL 以及相關物件。

Access entity data by using the EntityClient Provider

May include but is not limited to: Managing EntityConnection; Creating EntityCommand; Executing a query by using EntityDataReader; Managing EntityTransaction

此為 Entity Framework 中的 System.Data.EntityClient 命名空間的部份,包含 Entity 相關物件的操作。

資料來源:http://blogs.msdn.com/gerryo/archive/2008/03/13/get-ready-for-the-ado-net-3-5-mcts-exam.aspx

No comments: