Building nTier Applications with Entity Framework Services
Agenda
Overview
nTier Architecture OverviewModel to create flexible reusable applicationsOnly need to modify or add layers instead of rewriting entire applications over
Where’s Your Data Model?Applications Today…Implicitly Contain the Data ModelLogic and Model IntertwinedConceptual MismatchOften encapsulate in a "Data Access Layer"
Where’s Your Data Model?What Is Really Needed
Applications work with a well Defined Model
Storage Schema Abstraction
Declarative mapping between application and storage models
No brittle, hard-coded mappingEntity Framework
 Object Relational MappingWhat is ORM?Technique for working with relational tables as if they were objects in memoryIntention is to hide away the complexity of the underlying tables and give a uniform way of working with dataWhy use ORM?ProductivityRetain database independenceObjectsClassesEntities
 Object Relational MappingThere are many ORMs for .NET developers already in existence. E.g.LLBLGen Pro http://www.llblgen.com/Nhibernate http://www.hibernate.org/343.htmlEntitySpaces http://www.entityspaces.net/Portal/Default.aspx
The Microsoft Entity Data ModelAn extended relational model with Entity-Relationship Model  conceptsEntity TypesStrong type with IdentityInheritanceScalar/Complex propertiesEntitySetsHold instances of Entity TypesSimilar to relational tablesCan have multiple Entitysets of the same EntityTypesRelationships ("Associations")Named relationships between Entities0..1:*, 0..1:0..1, 1:1, 1:M, M:NNavigation may be exposed as NavigationProperties on EntityTypesAssociationSetsContains instances of associationsMay be queried directlyEntityContainersContains EntitySets, AssociationSetsSalesPersonEmployeeID = 294272LoginID = adamTitle = "Dev Lead"VacationHours = 0…Manager11NReportsSalesPersonSalesPersonEmployeeID = 729742LoginID = peteTitle = "Developer"VacationHours = 0…ExpenseAccount = …CarLicenseNum = ……SalesPersonEmployeeID = 729742LoginID = peteTitle = "Developer"VacationHours = 0…ExpenseAccount = …CarLicenseNum = ……EmployeeID = 729742LoginID = peteTitle = "Developer"VacationHours = 0…ExpenseAccount = true…
EDM & Entity Framework?The Entity Framework (EF) is an Object Relational Modeling tool leveraging the EDMFocus on your domain, not how to persist!EDM is used to describe your model.Allows different rate of change between database and code!EF uses a storage model and mapping to enable this.
ADO.NET Entity Framework
EF Providers in Progress
LINQ to Entities – Lots of Topics
Using Entity Framework with ASP.NET
Pain Points in v3.5 SP1Pluralization/ SingularizationForeign KeysModel FirstLazy LoadingAdditional LINQ OperatorsL2S Features & PatternsSQL Gen Improvements
Entity Framework in .NET 4Improvements:Model FirstT4 Templates to control code generationSupporting DDD approach with POCO Persistence IgnoranceRepository patternQuery ImprovementsLazy LoadingDisconnected API’s to enable N-tier
Easily Expose Your EntitiesWCF Data Services
Data Services OverviewExtends Windows Communication FoundationFunctionalityCRUD access to data over RESTful web servicesBuilt-in URI-based query syntaxClient-side libraries for .NET and AJAX clients
Data ServicesHTTPOpen Data ProtocolHosting/HTTP ListenerData Services RuntimeIQueryable/IEnumerable[+ IUpdatable]Data Access LayerEntity FrameworkCustom LINQ ProviderRelational databaseOther sources
Data Services - A REST InterfaceThe underlying model
Entities and associations  resources and linksWCF 4Programming ModelCore ServicesWeb HTTP ServicesData ServicesRIA ServicesWorkflow ServicesService ModelData ContractService ContractService  BehaviorChannel ModelFormats(Atom, JSON, XML,…)Transports(HTTP, TCP, …)Protocols(SOAP, HTTP, Open Data Protocol,…)
URL ConventionsAddressing entities and setsPresentation optionsModern Data-Driven Web AppsAJAX integrationAJAX-friendly JSON format in servicesJavascript library that integrates with the ASP.NET AJAX toolkitSilverlight support.NET programming model for data servicesObject based, LINQ enabled APICode-gen entity types from metadata
"Traditional" ApplicationsWeb applicationsData services client can be used in ASP.NETASP.NET data source control for accessing remote servicesDesktop applicationsFully-featured .NET client librarySame API in desktop and Silverlight environments
What’s New in .NET 4Data BindingNew DataServiceCollection class provides simplified binding of data service data to (WPF) controls. Includes auto updating.Counting Entities in an Set $count - total number of resources returned by a URI$inlinecount - total resource count together with the resource dataServer-driven Paging Service can be configured to return requested resources as a set of paged responses
What’s New in .NET 4Query ProjectionsQuery results can be modified to include only a subset of properties by using the new $select query option.Custom Data Service ProvidersCan implement a set of new data service provider interfaces, you can use various types of data with a data service, even when the data model changes during execution.Streaming of Binary ResourcesThis enables you to retrieve and save binary large object data independent of the entity to which it belongs.
Summary
Conclusion
Before You Begin…What I Have Learned So Far About The Entity Framework and ADO.NET Data Serviceshttp://dotnettips.com/2008/09/30/WhatIHaveLearnedSoFarAboutTheEntityFrameworkAndADONETDataServices.aspx*Part 2 coming out soon!Using Microsoft ADO.NET Data Serviceshttp://msdn.microsoft.com/en-us/library/cc907912.aspx
ResourcesADO.NET Team Bloghttp://blogs.msdn.com/adonet/default.aspxEF Design Blogblogs.msdn.com/efdesignVisual Studio Data Bloghttp://blogs.msdn.com/vsdata/dnrTV!http://shrinkster.com/1734http://shrinkster.com/1735
ResourcesDan Simmons Bloghttp://blogs.msdn.com/dsimmons/MSDN Code Galleryhttp://shrinkster.com/1733WCF Data Services Learning Guide:http://msdn.microsoft.com/en-us/data/bb931106.aspxWCF Data Services Team Bloghttp://blogs.msdn.com/astoriateam/default.aspx

Building N Tier Applications With Entity Framework Services 2010

  • 1.
    Building nTier Applicationswith Entity Framework Services
  • 3.
  • 4.
  • 5.
    nTier Architecture OverviewModelto create flexible reusable applicationsOnly need to modify or add layers instead of rewriting entire applications over
  • 6.
    Where’s Your DataModel?Applications Today…Implicitly Contain the Data ModelLogic and Model IntertwinedConceptual MismatchOften encapsulate in a "Data Access Layer"
  • 7.
    Where’s Your DataModel?What Is Really Needed
  • 8.
    Applications work witha well Defined Model
  • 9.
  • 10.
    Declarative mapping betweenapplication and storage models
  • 11.
    No brittle, hard-codedmappingEntity Framework
  • 12.
    Object RelationalMappingWhat is ORM?Technique for working with relational tables as if they were objects in memoryIntention is to hide away the complexity of the underlying tables and give a uniform way of working with dataWhy use ORM?ProductivityRetain database independenceObjectsClassesEntities
  • 13.
    Object RelationalMappingThere are many ORMs for .NET developers already in existence. E.g.LLBLGen Pro http://www.llblgen.com/Nhibernate http://www.hibernate.org/343.htmlEntitySpaces http://www.entityspaces.net/Portal/Default.aspx
  • 14.
    The Microsoft EntityData ModelAn extended relational model with Entity-Relationship Model conceptsEntity TypesStrong type with IdentityInheritanceScalar/Complex propertiesEntitySetsHold instances of Entity TypesSimilar to relational tablesCan have multiple Entitysets of the same EntityTypesRelationships ("Associations")Named relationships between Entities0..1:*, 0..1:0..1, 1:1, 1:M, M:NNavigation may be exposed as NavigationProperties on EntityTypesAssociationSetsContains instances of associationsMay be queried directlyEntityContainersContains EntitySets, AssociationSetsSalesPersonEmployeeID = 294272LoginID = adamTitle = "Dev Lead"VacationHours = 0…Manager11NReportsSalesPersonSalesPersonEmployeeID = 729742LoginID = peteTitle = "Developer"VacationHours = 0…ExpenseAccount = …CarLicenseNum = ……SalesPersonEmployeeID = 729742LoginID = peteTitle = "Developer"VacationHours = 0…ExpenseAccount = …CarLicenseNum = ……EmployeeID = 729742LoginID = peteTitle = "Developer"VacationHours = 0…ExpenseAccount = true…
  • 15.
    EDM & EntityFramework?The Entity Framework (EF) is an Object Relational Modeling tool leveraging the EDMFocus on your domain, not how to persist!EDM is used to describe your model.Allows different rate of change between database and code!EF uses a storage model and mapping to enable this.
  • 16.
  • 17.
  • 18.
    LINQ to Entities– Lots of Topics
  • 20.
  • 21.
    Pain Points inv3.5 SP1Pluralization/ SingularizationForeign KeysModel FirstLazy LoadingAdditional LINQ OperatorsL2S Features & PatternsSQL Gen Improvements
  • 22.
    Entity Framework in.NET 4Improvements:Model FirstT4 Templates to control code generationSupporting DDD approach with POCO Persistence IgnoranceRepository patternQuery ImprovementsLazy LoadingDisconnected API’s to enable N-tier
  • 23.
    Easily Expose YourEntitiesWCF Data Services
  • 24.
    Data Services OverviewExtendsWindows Communication FoundationFunctionalityCRUD access to data over RESTful web servicesBuilt-in URI-based query syntaxClient-side libraries for .NET and AJAX clients
  • 25.
    Data ServicesHTTPOpen DataProtocolHosting/HTTP ListenerData Services RuntimeIQueryable/IEnumerable[+ IUpdatable]Data Access LayerEntity FrameworkCustom LINQ ProviderRelational databaseOther sources
  • 26.
    Data Services -A REST InterfaceThe underlying model
  • 27.
    Entities and associations resources and linksWCF 4Programming ModelCore ServicesWeb HTTP ServicesData ServicesRIA ServicesWorkflow ServicesService ModelData ContractService ContractService BehaviorChannel ModelFormats(Atom, JSON, XML,…)Transports(HTTP, TCP, …)Protocols(SOAP, HTTP, Open Data Protocol,…)
  • 28.
    URL ConventionsAddressing entitiesand setsPresentation optionsModern Data-Driven Web AppsAJAX integrationAJAX-friendly JSON format in servicesJavascript library that integrates with the ASP.NET AJAX toolkitSilverlight support.NET programming model for data servicesObject based, LINQ enabled APICode-gen entity types from metadata
  • 29.
    "Traditional" ApplicationsWeb applicationsDataservices client can be used in ASP.NETASP.NET data source control for accessing remote servicesDesktop applicationsFully-featured .NET client librarySame API in desktop and Silverlight environments
  • 30.
    What’s New in.NET 4Data BindingNew DataServiceCollection class provides simplified binding of data service data to (WPF) controls. Includes auto updating.Counting Entities in an Set $count - total number of resources returned by a URI$inlinecount - total resource count together with the resource dataServer-driven Paging Service can be configured to return requested resources as a set of paged responses
  • 31.
    What’s New in.NET 4Query ProjectionsQuery results can be modified to include only a subset of properties by using the new $select query option.Custom Data Service ProvidersCan implement a set of new data service provider interfaces, you can use various types of data with a data service, even when the data model changes during execution.Streaming of Binary ResourcesThis enables you to retrieve and save binary large object data independent of the entity to which it belongs.
  • 33.
  • 34.
  • 35.
    Before You Begin…WhatI Have Learned So Far About The Entity Framework and ADO.NET Data Serviceshttp://dotnettips.com/2008/09/30/WhatIHaveLearnedSoFarAboutTheEntityFrameworkAndADONETDataServices.aspx*Part 2 coming out soon!Using Microsoft ADO.NET Data Serviceshttp://msdn.microsoft.com/en-us/library/cc907912.aspx
  • 36.
    ResourcesADO.NET Team Bloghttp://blogs.msdn.com/adonet/default.aspxEFDesign Blogblogs.msdn.com/efdesignVisual Studio Data Bloghttp://blogs.msdn.com/vsdata/dnrTV!http://shrinkster.com/1734http://shrinkster.com/1735
  • 37.
    ResourcesDan Simmons Bloghttp://blogs.msdn.com/dsimmons/MSDNCode Galleryhttp://shrinkster.com/1733WCF Data Services Learning Guide:http://msdn.microsoft.com/en-us/data/bb931106.aspxWCF Data Services Team Bloghttp://blogs.msdn.com/astoriateam/default.aspx

Editor's Notes

  • #5 Goals:To show a new way of serving up dateGet you thinking to learn more when you leave this presentation
  • #6 How do you or have you designed your applications??? Be truthful!!N-tier application architecture provides a model for developers to create a flexible and reusable application. By breaking up an application into tiers, developers only have to modify or add a specific layer, rather than have to rewrite the entire application over, if they decide to change technologies or scale up. In the term "N-tier," "N" implies any number -- like 2-tier, or 4-tier; basically, any number of distinct tiers used in your architecture. Application architectures are part of Layer 7 of the OSI model.
  • #10 Talk about the separation between database developer and programmer.
  • #11 Talk about the separation between database developer and programmer.
  • #13 Applications can work in terms of a more application-centric conceptual model, including types with inheritance, complex members, and relationships.Applications are freed from hard-coded dependencies on a particular data engine or storage schema.Mappings between the conceptual model and the storage-specific schema can change without changing the application code.Developers can work with a consistent application object model that can be mapped to various storage schemas, possibly implemented in different database management systems.Multiple conceptual models can be mapped to a single storage schema.Language-integrated query (LINQ) support provides compile-time syntax validation for queries against a conceptual model.
  • #16 POCO = Plane Old .NET Classes
  • #17 Demo: AdventureWorks.DataDemo: AdvertureWorks.ExampleDemo: EntityDesignerDiagram.png
  • #18 AdventureWorks.AdminAdd entity referenceAdd Reference to System.Data.EntityAdd connection string to web.configShow ProductCategories table.
  • #23 Talk about any object can be exposed via EF!
  • #31 Demo: AdvertureWorksServiceDemo: AdventureWorks.Client