The document provides an agenda and overview for a presentation on data access layer patterns and options. It discusses considerations for keeping data entities consistent or managing differences between objects and schemas. It also covers common patterns for each approach, including row and table data gateways, active record, domain models, data mappers, repositories, and unit of work. The presentation will assess data access technologies and discuss additional challenges like domain model responsibilities. Attendees can contact the presenter with any other questions.
3. Agenda
The data access layer and your options
Patterns for keeping entities consistent
Patterns for managing entity differences
Data access technology assessment
Other data access challenges
Summary and questions
4. Layers & Relationships
Business
Business Data
Data
Logic Data Access Layer
Logic Storage
Storage
Layer
Layer
Considerations Two Options
Domain complexity Keep
Developer experience entities
Greenfield vs. brownfield consistent
Desired approach: data, Manage their
code, or model first? differences
Object/schema fidelity
5. Keeping Entities Consistent
Recommended when Common patterns
domain is less complex Row Data Gateway
Restricts object-oriented Table Data Gateway
design options Table Module
Can benefit from code Active Record
generation strategies Record Set
More difficult to evolve
over time, but easier to We have choices
manage Shape of the objects
How to combine
data and logic
6. Pre-Built Types
when objects and schema have a simple relationship
Record Set (DataSet) TableDataGateway
Contains the data as rows Find() : RecordSet
and columns Update(a, b, c)
Insert(a, b, c)
Table Data Gateway Delete(id) RecordSet
Encapsulates all SQL Rows
Can return record sets Columns
Table Module
TableModule
Accepts a record set
Process(RecordSet)
Contains business logic Calculate(RecordSet)
7. Custom Types
when objects and schema have a simple relationship
Row Data Gateway RowDataGateway
Represents a table’s row ID : long ActiveRecord
Includes all CRUD FirstName : string
ID : long
capability LastName : string
FirstName : string
Update(first, last)
Transaction Script Insert(first, last)
LastName : string
Update(first, last)
Contains business logic Delete(id)
Insert(first, last)
Active Record Delete(id)
Represents a table’s row Process()
Contains business logic TransactionScript
Includes all CRUD
ProcessCostChange()
capability CalculateAdjustment()
8. Managing Entity Differences
Appropriate for Common patterns
complex domain logic Domain Model
Requires more Data Mapper
developer experience Repository
Can leverage more OO Unit of Work
(GoF) design patterns Specification
Appropriate for apps
that evolve over time
9. Storefront Overview
Customer Retailer
IE WPF
ASP.NET Data
MVC Services
• Searches for • Manages product
products information
• Buys products • Maintains
• Views order SQL inventory
Server
status • Processes and
• Rates products ships orders
and retailers Broker
• Collects a percentage from each sale
• Views sales & site usage reports
Silverlight
11. Domain Model & Mapping
Domain Model Data Mapper
An object model that Represents an association of
represents the domain types and properties across the
Contains the combination of domain model and data model
data and business logic Almost always aware of the
Two basic options data access technology
May be robust and leverage OO Implementations are often
principles included in O/RM solutions
May be straightforward in less Mapping support varies
complex scenarios
May have no knowledge of data
access technology
12. Repository
Collection-type interface
to data access
Repository
Mediates between GetById(id)
domain model GetAll()
Add(object)
and mapper Update(object)
Delete(id)
Implementations are
specific to a technology
13. Unit of Work
Maintains a list of new,
changed and deleted
UnitOfWork
objects and coordinates SubmitChanges()
persisting changes CancelChanges()
Can be used across
multiple repositories
14. Specification/Query Object
An object that represents
the criteria of a query
Allows queries to be Specification
easier to manage Field : string
Value : object
Avoids the need for a Operator : OpEnum
method for each query
15. Technology Assessment
ADO.NET
DataSet
DataAdapter
DataReader
LINQ to SQL
O/RM for simple mappings
ADO.NET Entity Framework
O/RM for more complex mappings
16. Related Challenges
Domain Model Responsibilities
Serialization (DTOs)
Data binding
Edit tracking
Validation
Domain Model Representations
Subset of the type
View models
17. Summary
Steps for making choices
1. Determine consistency possibilities between the
domain model and the data model
Keep entities consistent
Manage their differences
2. Choose shape of the types
Pre-built
Custom built
3. Determine how to attach the business logic
Influenced by the shape of the types
18. Resources
Don’s email:
dons@microsoft.com
Project’s community site:
http://dataguidance.codeplex.com
Patterns of Enterprise Application Architecture
http://www.martinfowler.com/eaaCatalog
The Microsoft Patterns & Practices Team
http://microsoft.com/practices
23. PowerPoint Template
Subtitle color
Set the slide title in “title case” and subheads in
“sentence case”
The subhead color is defined for this template as the
fourth font color from the left
Font Size Requirements
Main bullet points must not be smaller than 24pt
Do NOT use any font size lower than 20pt
Set subhead to 36pt or smaller so it will fit
on a single line
Turn off Auto Resizing on all text boxes
24. PowerPoint Guidelines
Font, size, and color for text have been
formatted for you in the Slide Master
Use the color palette shown below
See next slide for additional guidelines
Hyperlink color: www.microsoft.com
Sample Sample Sample Sample Sample
Fill Fill Fill Fill Fill
Sample Sample Sample Sample Sample
Fill Fill Fill Fill Fill
25. Instructions on Color Readability
Colors are brighter when projected, so contrast
and readability are diminished
Use black or dark gray text
only on these colors
Sample Sample
Use white text only on these colors
Sample Sample Sample Sample
Sample Sample Sample Sample
26. Slide for Showing Software Code
Use this layout to show software code
The font is Consolas, a monospace font
The slide doesn’t use bullets but levels can be indented
using the “Increase List Level” icon on the Home menu
To use straight quotes quot; instead of
smart quotes ”, do this:
1.Click on the Office Button in the upper left corner
2.At the bottom of the menu, choose PowerPoint Options
3.From the left pane, select Proofing
4.Click on the AutoCorrect Options button
5.Select the AutoFormat As You Type tab,
and deselect “Straight quotes” with “smart
quotes”. Then Click OK.
27. Table Format
Table Title
Column 1 Column 2 Column 3 Column 4 Column 5
28. Bar Chart Example
Chart Title
Series 1 Series 2 Series 3
5
4.3 4.4 4.5
3.5
3 2.8
2.4 2.5
2 2 1.8
Category 1 Category 2 Category 3 Category 4
To get data out of a database, you have to issue T-SQL statements to it. Scattering these statements throughout the business logic makes the solution more difficult to manage/troubleshoot.Dependencies go out from the DAL! The arrows are showing flow and dependencies.Quality AttributesSeparation of ConcernsEvolvabilityTestabilityPerformance
Most of us know that the practices a team uses when building a solution has a tremendous influence on the code that implements the ultimate solution. Also, the technologies used can either make that process easier or harder. Unit testing is a prime example. So for this project, we’re going to start with building a reference implementation and be very transparent about the process by which we build it. We’ve began with domain modeling and TDD as primary practices and (because we’re only in our second iteration) are considering a switch to a more BDD approach. So let’s talk about the scenario.The goal of the solution is pretty simple – it’s just to broker sales between retailers who are selling products and customers who are buying them. We represent the broker who is building the solution and mostly interested in collecting a percentage of each sale … and we have to manage the solution too of course. Hopefully this diagram will give you sense of the products and technologies we’re going to use and the main things the solution will have to do. We feel pretty good about this scenario because if you’ve used Amazon, it should be familiar to your, and the domain model has an appropriate level of complexity.
If you would like to host your demo on the Virtual Server, please use the myVPC demo slide, not this slide.