Don Smith, Program Manager
Microsoft patterns & practices
Agenda
 The data access layer and your options
 Patterns for keeping entities consistent
 Patterns for managing entity dif...
Layers & Relationships
    Business
   Business                                       Data
                               ...
Keeping Entities Consistent
 Recommended when            Common patterns
 domain is less complex       Row Data Gateway
 R...
Pre-Built Types
when objects and schema have a simple relationship

  Record Set (DataSet)          TableDataGateway
    C...
Custom Types
when objects and schema have a simple relationship

  Row Data Gateway              RowDataGateway
    Repres...
Managing Entity Differences
 Appropriate for         Common patterns
 complex domain logic     Domain Model
 Requires more...
Storefront Overview
    Customer                                                        Retailer



               IE     ...
Storefront Reference Implementation
Domain Model & Mapping
Domain Model                        Data Mapper
 An object model that                Represents an ...
Repository
 Collection-type interface
 to data access
                                Repository
 Mediates between        ...
Unit of Work
 Maintains a list of new,
 changed and deleted
                                UnitOfWork
 objects and coordi...
Specification/Query Object
 An object that represents
 the criteria of a query
 Allows queries to be            Specificat...
Technology Assessment
 ADO.NET
   DataSet
   DataAdapter
   DataReader
 LINQ to SQL
   O/RM for simple mappings
 ADO.NET E...
Related Challenges
 Domain Model Responsibilities
   Serialization (DTOs)
   Data binding
   Edit tracking
   Validation
 ...
Summary
 Steps for making choices
 1. Determine consistency possibilities between the
    domain model and the data model
...
Resources
 Don’s email:
 dons@microsoft.com
 Project’s community site:
 http://dataguidance.codeplex.com
 Patterns of Ente...
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be...
Video Title
Announcement Title
PowerPoint Template
Subtitle color

  Set the slide title in “title case” and subheads in
  “sentence case”
  The subhead ...
PowerPoint Guidelines
 Font, size, and color for text have been
 formatted for you in the Slide Master
 Use the color pale...
Instructions on Color Readability
 Colors are brighter when projected, so contrast
 and readability are diminished
  Use b...
Slide for Showing Software Code
Use this layout to show software code
  The font is Consolas, a monospace font
  The slide...
Table Format
                       Table Title
 Column 1   Column 2     Column 3    Column 4   Column 5
Bar Chart Example
                                Chart Title
                    Series 1        Series 2     Series 3

 ...
Pie Chart Example

           Chart Title
    10%
           9%
                          1st Qtr
     23%            58%
Related Content
Breakout Sessions (session codes and titles)



Interactive Theater Sessions (session codes and titles)


...
Track Resources
Resource 1



Resource 2



Resource 3



Resource 4
Data Access   Tech Ed India
Data Access   Tech Ed India
Data Access   Tech Ed India
Upcoming SlideShare
Loading in …5
×

Data Access Tech Ed India

551 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
551
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
17
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • 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.
  • Data Access Tech Ed India

    1. 1. Don Smith, Program Manager Microsoft patterns & practices
    2. 2. 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
    3. 3. 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
    4. 4. 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
    5. 5. 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)
    6. 6. 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()
    7. 7. 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
    8. 8. 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
    9. 9. Storefront Reference Implementation
    10. 10. 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
    11. 11. 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
    12. 12. 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
    13. 13. 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
    14. 14. 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
    15. 15. Related Challenges Domain Model Responsibilities Serialization (DTOs) Data binding Edit tracking Validation Domain Model Representations Subset of the type View models
    16. 16. 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
    17. 17. 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
    18. 18. © 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.
    19. 19. Video Title
    20. 20. Announcement Title
    21. 21. 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
    22. 22. 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
    23. 23. 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
    24. 24. 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.
    25. 25. Table Format Table Title Column 1 Column 2 Column 3 Column 4 Column 5
    26. 26. 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
    27. 27. Pie Chart Example Chart Title 10% 9% 1st Qtr 23% 58%
    28. 28. 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)
    29. 29. Track Resources Resource 1 Resource 2 Resource 3 Resource 4

    ×