Data Access Tech Ed India

Post on 06-May-2015

438 views 0 download

transcript

Modern Data Access: Patterns & Implementations

Don Smith, Program ManagerMicrosoft patterns & practices

Agenda

The data access layer and your optionsPatterns for keeping entities consistentPatterns for managing entity differencesData access technology assessmentOther data access challengesSummary and questions

Layers & Relationships

ConsiderationsDomain complexityDeveloper experienceGreenfield vs. brownfieldDesired approach: data, code, or model first?Object/schema fidelity

Two OptionsKeep entities consistentManage their differences

Data Access Layer DataStorage

BusinessLogic Layer

BusinessLogicLayer

Data Storage

Keeping Entities Consistent

Recommended when domain is less complexRestricts object-oriented design optionsCan benefit from code generation strategiesMore difficult to evolve over time, but easier to manage

Common patternsRow Data GatewayTable Data GatewayTable ModuleActive RecordRecord Set

We have choicesShape of the objectsHow to combinedata and logic

Pre-Built Types

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

Table Data GatewayEncapsulates all SQLCan return record sets

Table ModuleAccepts a record setContains 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 logicRequires more developer experienceCan leverage more OO (GoF) design patternsAppropriate for apps that evolve over time

Common patternsDomain ModelData MapperRepositoryUnit of WorkSpecification

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 Implementationdemo

Domain Model & Mapping

Domain ModelAn object model that represents the domainContains the combination of data and business logicTwo basic options

May be robust and leverage OO principlesMay 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 modelAlmost always aware of the data access technologyImplementations are often included in O/RM solutionsMapping support varies

Repository

Collection-type interface to data accessMediates between domain model and mapperImplementations 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 changesCan 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 manageAvoids the need for a method for each query

Field : stringValue : objectOperator : OpEnum

Specification

Technology Assessment

ADO.NETDataSetDataAdapterDataReader

LINQ to SQLO/RM for simple mappings

ADO.NET Entity FrameworkO/RM for more complex mappings

Related Challenges

Domain Model ResponsibilitiesSerialization (DTOs)Data bindingEdit trackingValidation

Domain Model RepresentationsSubset of the typeView models

Summary

Steps for making choices1. Determine consistency possibilities between the

domain model and the data modelKeep entities consistentManage their differences

2. Choose shape of the typesPre-builtCustom built

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

Resources

Don’s email: dons@microsoft.comProject’s community site: http://dataguidance.codeplex.comPatterns of Enterprise Application Architecturehttp://www.martinfowler.com/eaaCatalogThe Microsoft Patterns & Practices Teamhttp://microsoft.com/practices

question & answer

© 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.

Video Titlevideo

Announcement Titleannouncing

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 leftFont Size Requirements

Main bullet points must not be smaller than 24ptDo NOT use any font size lower than 20ptSet subhead to 36pt or smaller so it will fit on a single lineTurn off Auto Resizing on all text boxes

PowerPoint Guidelines

Font, size, and color for text have been formatted for you in the Slide MasterUse the color palette shown belowSee next slide for additional guidelinesHyperlink 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

Category 1 Category 2 Category 3 Category 4

4.3

2.5

3.5

4.5

2.4

4.4

1.8

2.8

2 2

3

5

Chart Title

Series 1 Series 2 Series 3

Pie Chart Example

59%23%

10%9%

Chart Title

1st Qtr2nd Qtr3rd Qtr4th 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