Don Smith, Program Manager Microsoft patterns &...

Post on 03-Apr-2020

1 views 0 download

Transcript of Don Smith, Program Manager Microsoft patterns &...

Don Smith, Program ManagerMicrosoft patterns & practices

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

Layers & Relationships

ConsiderationsDomain complexity

Developer experience

Greenfield vs. brownfield

Desired approach: data, code, or model first?

Object/schema fidelity

Two OptionsKeep entities consistent

Manage their differences

Data Access Layer DataStorage

BusinessLogic Layer

BusinessLogicLayer

Data Storage

Keeping Entities Consistent

Recommended when domain is less complex

Restricts object-oriented design options

Can benefit from code generation strategies

More difficult to evolve over time, but easier to manage

Common patternsRow Data Gateway

Table Data Gateway

Table Module

Active Record

Record Set

We have choicesShape of the objects

How to combinedata and logic

Pre-Built Types

Record Set (DataSet)Contains the data as rows and columns

Table Data GatewayEncapsulates all SQL

Can return record sets

Table ModuleAccepts a record set

Contains business logic

when objects and schema have a simple relationship

RowsColumns

RecordSet

Find() : RecordSetUpdate(a, b, c)Insert(a, b, c)Delete(id)

TableDataGateway

Process(RecordSet)Calculate(RecordSet)

TableModule

Custom Types

Row Data GatewayRepresents a table’s rowIncludes all CRUD capability

Transaction ScriptContains business logic

Active RecordRepresents a table’s rowContains business logicIncludes all CRUD capability

ID : longFirstName : stringLastName : stringUpdate(first, last)Insert(first, last)Delete(id)

RowDataGateway

ID : longFirstName : stringLastName : stringUpdate(first, last)Insert(first, last)Delete(id)Process()

ActiveRecord

ProcessCostChange()CalculateAdjustment()

TransactionScript

when objects and schema have a simple relationship

Managing Entity Differences

Appropriate for complex domain logic

Requires more developer experience

Can leverage more OO (GoF) design patterns

Appropriate for apps that evolve over time

Common patternsDomain Model

Data Mapper

Repository

Unit of Work

Specification

Storefront Overview

SQLServer

ASP.NETMVC

DataServices

Customer Retailer

Broker

• Manages product information

• Maintains inventory

• Processes and ships orders

IE WPF

Silverlight

• Collects a percentage from each sale• Views sales & site usage reports

• Searches for products

• Buys products• Views order

status• Rates products

and retailers

Storefront Reference Implementation

Domain Model & Mapping

Domain ModelAn object model that represents the domain

Contains the combination of data and business logic

Two basic optionsMay be robust and leverage OO principles

May be straightforward in less complex scenarios

May have no knowledge of data access technology

Data MapperRepresents an association of types and properties across the domain model and data model

Almost always aware of the data access technology

Implementations are often included in O/RM solutions

Mapping support varies

Repository

Collection-type interface to data access

Mediates between domain model and mapper

Implementations are specific to a technology

GetById(id)GetAll()Add(object)Update(object)Delete(id)

Repository

Unit of Work

Maintains a list of new, changed and deleted objects and coordinates persisting changes

Can be used across multiple repositories

SubmitChanges()CancelChanges()

UnitOfWork

Specification/Query Object

An object that represents the criteria of a query

Allows queries to be easier to manage

Avoids the need for a method for each query

Field : stringValue : objectOperator : OpEnum

Specification

Technology Assessment

ADO.NETDataSet

DataAdapter

DataReader

LINQ to SQLO/RM for simple mappings

ADO.NET Entity FrameworkO/RM for more complex mappings

Related Challenges

Domain Model ResponsibilitiesSerialization (DTOs)

Data binding

Edit tracking

Validation

Domain Model RepresentationsSubset of the type

View models

Summary

Steps for making choices1. Determine consistency possibilities between the

domain model and the data modelKeep entities consistent

Manage their differences

2. Choose shape of the typesPre-built

Custom built

3. Determine how to attach the business logicInfluenced by the shape of the types

Resources

Don’s email: dons@microsoft.com

Project’s community site: http://dataguidance.codeplex.com

Patterns of Enterprise Application Architecturehttp://www.martinfowler.com/eaaCatalog

The Microsoft Patterns & Practices Teamhttp://microsoft.com/practices

© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS,

IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Announcement Title

PowerPoint TemplateSubtitle 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 RequirementsMain 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

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 Fill

Sample Fill

Sample Fill

Sample Fill

Sample Fill

Sample

Fill

Sample

Fill

Sample

Fill

Sample

Fill

Sample

Fill

Use white text only on these colors

Instructions on Color Readability

Colors are brighter when projected, so contrast and readability are diminished

Sample SampleSample

Sample

Sample

Sample SampleSample

Sample Sample

Use black or dark gray text only on these colors

Slide for Showing Software Code

Use this layout to show software codeThe font is Consolas, a monospace fontThe slide doesn’t use bullets but levels can be indented using the “Increase List Level” icon on the Home menuTo use straight quotes " instead of smart quotes ”, do this:1.Click on the Office Button in the upper left corner2.At the bottom of the menu, choose PowerPoint Options3.From the left pane, select Proofing4.Click on the AutoCorrect Options button5.Select the AutoFormat As You Type tab, and deselect “Straight quotes” with “smart quotes”. Then Click OK.

Table Format

Table TitleColumn 1 Column 2 Column 3 Column 4 Column 5

Bar Chart Example

4.3

2.5

3.5

4.5

2.4

4.4

1.8

2.8

2 2

3

5

Category 1 Category 2 Category 3 Category 4

Chart Title

Series 1 Series 2 Series 3

Pie Chart Example

58%23%

10%9%

Chart Title

1st Qtr

Related Content

Breakout Sessions (session codes and titles)

Interactive Theater Sessions (session codes and titles)

Hands-on Labs (session codes and titles)

Hands-on Labs (session codes and titles)

Track Resources

Resource 1

Resource 2

Resource 3

Resource 4