Implementing the DataMapper Pattern With .Net 1.1 - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Implementing the DataMapper Pattern With .Net 1.1

Description:

Implementing the DataMapper Pattern With .Net 1.1. Don Demsak. www.donxml.com ... (Patterns of Enterprise Application Architecture page 473 by Martin Fowler) ... – PowerPoint PPT presentation

Number of Views:74
Avg rating:3.0/5.0
Slides: 18
Provided by: Don73
Category:

less

Transcript and Presenter's Notes

Title: Implementing the DataMapper Pattern With .Net 1.1


1
Implementing the DataMapper Pattern With .Net 1.1
Code Camp II, Waltham, MA October 16th, 2004
  • Don Demsak
  • www.donxml.com

2
Data Mapper Pattern Definition
A layer of Mappers that moves data between
objects and a database while keeping them
independent of each other and the mapper itself.
(Patterns of Enterprise Application Architecture
page 165 by Martin Fowler)
Mapper (def.) An object that sets up a
communication between two independent objects.
(Patterns of Enterprise Application Architecture
page 473 by Martin Fowler)
3
Alternates To Data Mappers
  • System.Data.DataSet
  • No Domain Objects
  • Strongly Typed DataSet
  • Domain Objects in terms of data only
  • Table Module
  • A single instance that handles the business logic
    for all rows in a database table or view.
  • Transaction Scripts
  • Organizes business logic by procedures where each
    procedure handles a single request from the
    presentation.

4
Layered Architecture
Which Transport Object?
5
Data Transport Choices
  • DataReader
  • Fast But Only 2 Dimensional
  • DataSet
  • Easy But Still Only 2 Dimensional
  • XmlReader
  • Multi- Dimensional
  • XmlSerialization
  • XPathNavigator
  • Mostly Unknown

6
The Example (Using Northwind)
  • Get a list of all employees including
  • Each employees territories
  • Each territories region

7
Northwind ERD
8
Base Line Of Business Diagram
9
GetEmployee SQL
SELECT Employee.EmployeeId as "Employee.Id", Em
ployee.LastName as "Employee.LastName", Employee
.FirstName as "Employee.FirstName", Employee.Tit
le as "Employee.Title", Employee.BirthDate as
"Employee.BirthDate", Territory.TerritoryId as
"Territory.Id", RTRIM(Territory.TerritoryDescrip
tion) as "Territory.Description", Region.RegionI
D as "Region.Id", RTRIM(Region.RegionDescription
) as "Region.Description" from dbo.Employees
Employee INNER JOIN dbo.EmployeeTerritories
et on Employee.EmployeeID et.EmployeeID INNER
JOIN dbo.Territories Territory on
et.TerritoryID Territory.TerritoryID INNER
Join dbo.Region Region on Region.RegionID
Territory.RegionID order by Employee.EmployeeID,
Territory.TerritoryId, Region.RegionId
10
Base Data Access Layer Diagram
11
Code Demo
  • Which Transport Object?

12
Performance Results
  • DataReader 341
  • DataSet 411
  • XmlReader (XmlSerialization) 542
  • XPathNavigator - 450

13
DataReader Results
  • Pros
  • Fast
  • Cons
  • Domain Objects Need To Know the Underlying DB
    implementation
  • Connection Controlled by Application Layer
  • Domain Objects Need to Know Too Much About its
    children
  • Need to Create Internal Setters For Some
    Properties

14
DataSet Results
  • Pros
  • Easy to Learn
  • Cons
  • Domain Objects Need to Know Too Much About its
    children
  • Need to Create Internal Setters For Some
    Properties

15
XmlSerialization Results
  • Pros
  • Very Little Mapping Code Required
  • Cons
  • Connection Controlled by Application Layer
  • Domain Constructors Must Be Public
  • Collection Add Methods Must Be Public

16
XPathNavigator Resuls
  • Pros
  • Complies with Domain Driven Design Principles
  • DataStore Agnostic
  • Declarative In Coding Style
  • Cons
  • Learning Curve (XPath)
  • Slower than DataReader

17
Questions?
Contact Info Web Site www.donxml.com Email
don_at_donxml.com
Write a Comment
User Comments (0)
About PowerShow.com