OR mapping in ado.net use dataset

xiaoxiao2021-03-06  46

$ ID: DataSet_mapper.html, v 1.4 2004/12/16 06:02:30 George Exp $

To Be Continue ...

Abstract: Using DataSet AS Data Holder and Implement Data Mapper Pattern.

I have to Appologize First WHETHER this pattern will be implemented or not is still unknown. I have no idea That How to import uow and session level cache using dataset.

Data Mapper Pattern Is Important In Martin Fowler's Greatest Book. In His Book, HE Mentioned That Implementing

Data Mapper Pattern Using Dataset.

Key considration

How to store data in the mapper? We need to cache the domain object which get from the database, so next time we want to get the same object, we dont need to get it from database and we can use the same object in the system Which Won't be. Where to put the cache?

A. in Mapper's Data MEMBER?

Will Be Shared in All threads in the same process.

b. in Application Session Cache?

NEVER IMPLEMENT IN THIS. Using DataSet in Mapper As The Dataset Holder

a. How to SELECT DATA INTO THE DATASET HOLDER?

According to martin's book, should not insert the data in the same table. That would be some problems if we want to insert the data into the table already exist in the dataset holder. Can not use the select clause to select data from two table in the Same Time or We Don't Know Which Table Owns The Data from Database.

b. How to update, Delete and Insert Data INTO DATABASE for Persistence.

Look at this code Fragment from

8 namespace com.ds.mapper

9 {

10 ///

11 /// from Martin's Excellent Work.

12 ///

13 Public Class DataseTHolder

14 {

15 Public DataSet Data = New Dataset ();

16

17 private hashtable dataadapters = new hashtable (); 18

19 Public Void Filldata (String Query, String Tablename)

20 {

21 IF (DataAdapters.contains (TableName))

twenty two {

23 throw new mutlipleLoadexception ();

twenty four }

25

26 OLEDBDataAdapter Da = New OLEDBDataAdapter (query, db.connection);

27 OLEDBCommandbuilder Builder = New OLEDBCOMMAVAILDER (DA);

28 Da.fill (Data, TableName);

29 DataAdapters.Add (TableName, DA);

30}

31

32 ///

33 /// undo: DONT NEED DELETE METHOD IN Dataset ???

34 ///

35 public void update ()

36 {

37 Foreach (String Table In DataAdapters.keys)

38 {

39 (OLEDBDataAdapter) DataAdapters [Table]) .update (data, table);

40}

41}

42

43 ///

44 /// INDEX for Tables.

45 ///

46 Public DataTable this [String TableName]

47 {

48 get {return data.tables [tablename];

49}

50}

51}

Using CommandBuilder To Generate Insert, Update and Delete SQL CLAUSE. But There Are Some InconViences.

Table Must Has Primary Key and The Prmiary Key Must Be in The SELECT CLAUSE.

Use Select Clause To Select Each Table At A Time, Should Not Select Multiple Table in ONE SELECT CLAUSE, THEN We can't Join Table In Sql Which Would Cause Some Performance Issue.

Unit of work

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

New Post(0)