data access tech ed india

32

Upload: rsnarayanan

Post on 06-May-2015

441 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Data Access   Tech Ed India
Page 2: Data Access   Tech Ed India

Modern Data Access: Patterns & Implementations

Don Smith, Program ManagerMicrosoft patterns & practices

Page 3: Data Access   Tech Ed India

Agenda

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

Page 4: Data Access   Tech Ed India

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

Page 5: Data Access   Tech Ed India

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

Page 6: Data Access   Tech Ed India

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

Page 7: Data Access   Tech Ed India

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

Page 8: Data Access   Tech Ed India

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

Page 9: Data Access   Tech Ed India

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

Page 10: Data Access   Tech Ed India

Storefront Reference Implementationdemo

Page 11: Data Access   Tech Ed India

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

Page 12: Data Access   Tech Ed India

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

Page 13: Data Access   Tech Ed India

Unit of Work

Maintains a list of new, changed and deleted objects and coordinates persisting changesCan be used across multiple repositories

SubmitChanges()CancelChanges()

UnitOfWork

Page 14: Data Access   Tech Ed India

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

Page 15: Data Access   Tech Ed India

Technology Assessment

ADO.NETDataSetDataAdapterDataReader

LINQ to SQLO/RM for simple mappings

ADO.NET Entity FrameworkO/RM for more complex mappings

Page 16: Data Access   Tech Ed India

Related Challenges

Domain Model ResponsibilitiesSerialization (DTOs)Data bindingEdit trackingValidation

Domain Model RepresentationsSubset of the typeView models

Page 17: Data Access   Tech Ed India

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

Page 18: Data Access   Tech Ed India

Resources

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

Page 19: Data Access   Tech Ed India

question & answer

Page 20: Data Access   Tech Ed India

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

Page 21: Data Access   Tech Ed India

Video Titlevideo

Page 22: Data Access   Tech Ed India

Announcement Titleannouncing

Page 23: Data Access   Tech Ed India

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

Page 24: Data Access   Tech Ed India

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

Page 25: Data Access   Tech Ed India

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

Page 26: Data Access   Tech Ed India

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.

Page 27: Data Access   Tech Ed India

Table Format

Table TitleColumn 1 Column 2 Column 3 Column 4 Column 5

Page 28: Data Access   Tech Ed India

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

Page 29: Data Access   Tech Ed India

Pie Chart Example

59%23%

10%9%

Chart Title

1st Qtr2nd Qtr3rd Qtr4th Qtr

Page 30: Data Access   Tech Ed India

धन्यवा�दઆભા�ર ধন্য�বা�দ

ਧੰ�ਨਵਾ�ਦ

ଧନ୍ୟ�ବା�ଦ

நன்றி�

ధన్య�వాదాలు� ಧನ್ಯ�ವಾ�ದಗಳು

നി�ങ്ങള്‍‌ക്ക്� നിന്ദി�

Page 31: Data Access   Tech Ed India

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)

Page 32: Data Access   Tech Ed India

Track Resources

Resource 1

Resource 2

Resource 3

Resource 4