Practical .NET Data Access Layer - 2

zhaozj2021-02-16  45

Less nonsense, first in order to participate, please participate in the participation (Northwind taken as SQL Server):

Code 1: How to call DAF?

// Create a Customer Data Access Object

Customerdaf Daf = New CustomerDaf ();

/ / Return to the Customer Data Sheet according to ID

DataTable Cust1 = (DATATABLE) DAF.GETCUSTOMERBYID ("ALFKI");

/ / Return the successful Customer Dataset according to the name

DataSet Cust2 = (Dataset) Daf.getCustomers ("ab");

/ / Return to the Customer entity object according to the name

Mycustom Cust3 = Daf.getCustomerbyName ("Maria Anders");

/ / Return to all Customer data lists, each list element represents a Customer entity object

IList Cust4 = Daf.GetAllCustomers ();

/ / Return to the Customer Data Reader according to the city

DBDataReader Cust5 = (DBDATAREADER)

Daf.getCustomerbyCITY ("London");

// convert the data reader data into a list of Customer data, each list element represents one

// Customer entity object

IList cast5_list =

EntityConvert.tolist (Cust5, TypeOf (MyCustomer);

Code 1 showcase several basic operations of data through DAF, from, we are not difficult to see: CustomerDaf is the traditional data access class, and Customer corresponds to the data entity class, which is also the most DAL in most DAL The pattern is commonly used. In this case, then why do you want to launch this DAF here (of course, not only to change the name, what is the intention?

Before answering this question, let's tell everyone a truth:

Although the above code returns 5 different Data Entity objects: DataTable, Dataset, MyCustomer, IList, DBDataRead, but in the definition of the Customer Data Access Class "CustomerDaf", all methods of all methods are unified mycustomer! Later, the author analyzes the implementation of this code.

OK, let us first start from the data entity class, see how traditional Data Entity does:

Next paragraph: http://www.9cbs.net/develop/read_article.asp? Id = 27545

转载请注明原文地址:https://www.9cbs.com/read-24106.html

New Post(0)