[免費下載]Enterprise Library 4.0發佈了

也就是以前講的DAAB(全名Data Access Application Block ),

現在改名為 Patterns & Practices(或是稱為p&p),一般都稱為 Enterprise Library (EntLib)

下載與說明:http://www.codeplex.com/entlib

今天一早就看見 LOLOTA前輩的文章----[Info]Enterprise Library 4.0發佈了

NewpnpheroA.jpg

這東西是什麼啊?

也就是以前講的DAAB(全名Data Access Application Block ),

現在改名為 Patterns & Practices(或是稱為p&p),一般都稱為 Enterprise Library (EntLib)

包含的範圍更廣泛、功能更大了~

以前在MSDN論壇也有討論過,請看這篇文章-- http://forums.microsoft.com/msdn-cht/ShowPost.aspx?PostID=2703042&SiteID=14  

微軟MSDN裡面,有一個專區---- http://msdn.microsoft.com/zh-tw/practices/default(en-us).aspx

 

下載與說明:http://www.codeplex.com/entlib

沒記錯的話,他們是開放原始碼的,有興趣的人可以參考或是改寫。

安裝完成,就會在目錄底下看見一個原始碼(SourceCode)的目錄

 

如果您接手以前的程式,發現裡面常常有一個 SqlHelper()之類的東西。

沒錯,SqlHelper就是前身,您可以參考這篇中文文件(年代有點久):Microsoft Application Blocks for .NET

 

 

小弟在 3.1版的時候,稍稍玩過(試了一下)Enterprise Library ,那時是搭配 .NET 2.0與VS 2005的。那時共有八大分類,「資料存取」僅僅是其中一類。

寫了一些ADO.NET的程式(DataReader與DataSet),跟Enterprise Library提供的比較一下

相同程式跑一萬次,來記錄執行時間。    "似乎"手工自己寫ADO.NET比較快,平均時間都快了一秒。

 ===============================================================

 

我們來看看 Enterprise Libray 4.0的範例吧。

01         ' DataReader that will hold the returned results  
02         ' Create the Database object, using the default database service. The
03         ' default database service is determined through configuration.
04         ' 連結資料庫
05         Dim db As Database = DatabaseFactory.CreateDatabase()
06
07         Dim sqlCommand As String = "Select CustomerID, Name, Address, City, Country, PostalCode " & _
08             "From Customers"
09         Dim dbCommand As DbCommand = db.GetSqlStringCommand(sqlCommand)
10
11         Dim readerData As StringBuilder = New StringBuilder
12
13         ' The ExecuteReader call will request the connection to be closed upon
14         ' the closing of the DataReader. The DataReader will be closed  
15         ' automatically when it is disposed.
16         Using dataReader As IDataReader = db.ExecuteReader(dbCommand)
17
18             ' Iterate through DataReader and put results to the text box.
19             ' DataReaders cannot be bound to Windows Form controls (e.g. the
20             ' resultsDataGrid), but may be bound to Web Form controls.
21             While (dataReader.Read())
22                 ' Get the value of the 'Name' column in the DataReader
23                 readerData.Append(dataReader("Name"))
24                 readerData.Append(Environment.NewLine)
25             End While
26         End Using

 

上面是採用 DataReader的寫法,下面則是 DataSet的寫法,新增一筆資料在DataSet裡面:

01         Dim db As Database = DatabaseFactory.CreateDatabase()
02
03         Dim productsDataSet As DataSet = New DataSet
04
05         Dim sqlCommand As String = "Select ProductID, ProductName, CategoryID, UnitPrice, LastUpdate " & _
06             "From Products"
07         Dim dbCommand As DbCommand = db.GetSqlStringCommand(sqlCommand)
08
09         Dim productsTable As String = "Products"
10
11         ' Retrieve the initial data
12         db.LoadDataSet(dbCommand, productsDataSet, productsTable)
13
14         ' Get the table that will be modified
15         Dim table As DataTable = productsDataSet.Tables(productsTable)
16
17         ' Add a new product to existing DataSet
18         Dim addedRow As DataRow = table.Rows.Add(New Object() {DBNull.Value, "New product", 11, 25})
19
20         ' Modify an existing product
21         table.Rows(0)("ProductName") = "Modified product"
22
23         ' Establish our Insert, Delete, and Update commands
24         Dim insertCommand As DbCommand = db.GetStoredProcCommand("AddProduct")
25         db.AddInParameter(insertCommand, "ProductName", DbType.String, "ProductName", DataRowVersion.Current)
26         db.AddInParameter(insertCommand, "CategoryID", DbType.Int32, "CategoryID", DataRowVersion.Current)
27         db.AddInParameter(insertCommand, "UnitPrice", DbType.Currency, "UnitPrice", DataRowVersion.Current)
28
29         Dim deleteCommand As DbCommand = db.GetStoredProcCommand("DeleteProduct")
30         db.AddInParameter(deleteCommand, "ProductID", DbType.Int32, "ProductID", DataRowVersion.Current)
31
32         Dim updateCommand As DbCommand = db.GetStoredProcCommand("UpdateProduct")
33         db.AddInParameter(updateCommand, "ProductID", DbType.Int32, "ProductID", DataRowVersion.Current)
34         db.AddInParameter(updateCommand, "ProductName", DbType.String, "ProductName", DataRowVersion.Current)
35         db.AddInParameter(updateCommand, "LastUpdate", DbType.DateTime, "LastUpdate", DataRowVersion.Current)
36
37         ' Submit the DataSet, capturing the number of rows that were affected
38         Dim rowsAffected As Integer = db.UpdateDataSet(productsDataSet, "Products", insertCommand, updateCommand, deleteCommand, UpdateBehavior.Standard)

 

如果要比較 [傳統 ADO.NET] 的 DataReader寫法,可以參考我以前PO過的文章---- DataReader的標準範例 for ASP.NET 2.0 / 3.5

 

 

2008/10/8補充:

 

我將思想傳授他人, 他人之所得,亦無損於我之所有;

猶如一人以我的燭火點燭,光亮與他同在,我卻不因此身處黑暗。----Thomas Jefferson

線上課程教學,遠距教學 (Web Form 約 51hr)  https://dotblogs.com.tw/mis2000lab/2016/02/01/aspnet_online_learning_distance_education_VS2015

線上課程教學,遠距教學 (ASP.NET MVC 約 135hr)  https://dotblogs.com.tw/mis2000lab/2018/08/14/ASPnet_MVC_Online_Learning_MIS2000Lab

 

寫信給我,不要私訊 --  mis2000lab (at) yahoo.com.tw  或  school (at) mis2000lab.net

 (1) 第一天 ASP.NET MVC5 完整影片(5.5小時 / .NET 4.x版)免費試聽。影片 https://youtu.be/9spaHik87-A 

 (2) 第一天 ASP.NET Core MVC 完整影片(3小時 / .NET Core 6.0~8.0)免費試聽。影片 https://youtu.be/TSmwpT-Bx4I 

[學員感言] mis2000lab課程評價 - ASP.NET MVC , WebForm  。 https://mis2000lab.medium.com/%E5%AD%B8%E5%93%A1%E6%84%9F%E8%A8%80-mis2000lab%E8%AA%B2%E7%A8%8B%E8%A9%95%E5%83%B9-asp-net-mvc-webform-77903ce9680b  


ASP.NET遠距教學、線上課程(Web Form + MVC)。 第一天課程, "完整" 試聽。 

.........   facebook社團   https://www.facebook.com/mis2000lab   ......................

.........  YouTube (ASP.NET) 線上教學影片  https://www.youtube.com/channel/UC6IPPf6tvsNG8zX3u1LddvA/

 

Blog文章 "附的範例" 無法下載,請看 https://dotblogs.com.tw/mis2000lab/2016/03/14/2008_2015_mis2000lab_sample_download

請看我們的「售後服務」範圍(嚴格認定)。

...................................................................................................................................................... 

ASP.NET MVC  => .NET Core MVC 線上教學  ...... 第一天課程 完整內容 "免費"讓您評估 / 試聽

[遠距教學、教學影片] ASP.NET (Web Form) 課程 上線了!MIS2000Lab.主講   事先錄好的影片,並非上課側錄!   觀看時,有如「一對一」面對面講課