Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Building nTier Applications with Entity Framework Services


Published on

Learn how to build real world nTier applications with the Entity Framework and related services. With this new technology built into .NET, you can easily wrap an object model around your database and have all the data access automatically generated or use your own stored procedures and views. Then learn how to easily and securely expose your object model using WCF with just a few line of code using ADO.NET Data Services. The session will demonstrate how to create and consume these new technologies from the ground up.

Published in: Technology
  • Be the first to comment

Building nTier Applications with Entity Framework Services

  1. 1. Building nTier Applications with Entity Framework Services<br />
  2. 2.
  3. 3. dotNetDave Conference DVD!<br />Packed full of:<br />Videos of all sessions from 2010 & 2011(1)!<br />Slide decks from 2011 & 2010!<br />Demo projects from 2011 & 2010!<br />David McCarter’s .NET interview Questions!<br />Extras<br />Conference Photos from 2010!<br />Surprise videos!<br />Book + DVD $25!<br />Only $15!<br />
  4. 4. Check Out Your Local User Groups!<br />San Diego Cloud Computing User Group<br /><br />San Diego .NET Developers Group<br /><br />San Diego .NET User Group<br /><br />San Diego SQL Server User Group<br /><br />
  5. 5. Agenda<br />
  6. 6. Overview<br />
  7. 7. Where’s Your Data Model?<br />Applications Today…<br />Implicitly Contain the Data Model<br />Logic and Model Intertwined<br />Conceptual Mismatch<br />Often encapsulate in a "Data Access Layer"<br />
  8. 8. Where’s Your Data Model?<br /><ul><li>What Is Really Needed
  9. 9. Applications work with a well Defined Model
  10. 10. Storage Schema Abstraction
  11. 11. Declarative mapping between application and storage models
  12. 12. No brittle, hard-coded mapping</li></li></ul><li>User Experience<br />Security<br />Active Directory, Card Space, Windows Identity Foundation<br />UI Components<br />Windows Forms, Windows Presentation Foundation, ASP.NET (AJAX, MVC), Silverlight, Windows Mobile<br />Presentation Layer<br />Local Storage/ Cache<br />Communications Layer<br />Windows Communication Foundation (WCF), WCF Data Services, Web Services, Sync Services, Azure (Cloud), RIA Services, Workflow Services<br />Business Layer<br />Business Entities<br />T4 Templates<br />Business Components<br />Business Workflow<br />Windows Workflow Foundation<br />Data Layer<br />Entity Framework, LINQ to SQL, DataSets<br />SQL Server<br />
  13. 13. Object Relational Mapping<br />
  14. 14. The Dilemma<br />Software Architects & Developers<br />Database Designers & Administrators<br />
  15. 15. Object Relational Mapping<br />What is ORM?<br />Technique for working with relational tables as if they were objects in memory<br />Intention is to hide away the complexity of the underlying tables and give a uniform way of working with data<br />
  16. 16. Object Relational Mapping<br />Why use ORM?<br />Productivity<br />Retain database independence<br />Database portability<br />Objects ► Classes ► Entities<br />
  17. 17. Many attempts<br />Typed Datasets<br />Objectspaces ‘v1’<br />Objectspaces ‘v2’<br />Microsoft Business Framework<br />WinFS<br />Linq to SQL<br />NHibernate<br /> Will “RIP”<br /> Not Microsoft’s<br />
  18. 18. Entity Framework<br />
  19. 19. The Microsoft Entity Data Model<br />An extended relational model with Entity-Relationship Model concepts<br />Entity Types<br />Strong type with Identity<br />Inheritance<br />Scalar/Complex properties<br />EntitySets<br />Hold instances of Entity Types<br />Similar to relational tables<br />Can have multiple Entitysets of the same EntityTypes<br />Relationships ("Associations")<br />Named relationships between Entities<br />0..1:*, 0..1:0..1, 1:1, 1:M, M:N<br />Navigation may be exposed as NavigationProperties on EntityTypes<br />AssociationSets<br />Contains instances of associations<br />May be queried directly<br />EntityContainers<br />Contains EntitySets, AssociationSets<br />SalesPerson<br />EmployeeID = 294272LoginID = adamTitle = "Dev Lead"VacationHours = 0…<br />Manager<br />1<br />1<br />N<br />Reports<br />SalesPerson<br />SalesPerson<br />EmployeeID = 729742LoginID = peteTitle = "Developer"VacationHours = 0…ExpenseAccount = …CarLicenseNum = ……<br />SalesPerson<br />EmployeeID = 729742LoginID = peteTitle = "Developer"VacationHours = 0…ExpenseAccount = …CarLicenseNum = ……<br />EmployeeID = 729742LoginID = peteTitle = "Developer"VacationHours = 0…ExpenseAccount = true…<br />
  20. 20. EDM & Entity Framework?<br />The Entity Framework (EF) is an Object Relational Modeling tool leveraging the EDM<br />Focus on your domain, not how to persist!<br />EDM is used to describe your model.<br />Allows different rate of change between database and code!<br />EF uses a storage model and mapping to enable this.<br />
  21. 21. IEnumerable<T><br />LINQ to Entities<br />Entity SQL Query<br />Object Services<br />EDM<br />DataReader<br />Entity SQL<br />Conceptual Model<br />Mapping<br />Entity Data Provider<br />DataReader<br />SQL<br />Storage Model<br />ADO.NET Data Provider<br />EF Model<br />
  22. 22. Performance & Security?<br />Connections to database vs. amount of data<br />You can work with stored procedures <br />You can work with views<br />You can define how the ADO.NET Entity Framework loads your data to <br />Eager <br />Lazy<br />(Explicit)<br />
  23. 23.
  24. 24.
  25. 25. Entity Framework in .NET 4<br />Model First<br />T4 Templates to control code generation<br />Supporting DDD approach with POCO <br />Persistence Ignorance<br />Repository pattern<br />Query Improvements<br />Lazy Loading<br />Disconnected API’s to enable N-tier <br />
  26. 26. Easily Expose Your Entities<br />WCF Data Services<br />
  27. 27. WCF Data Services Overview<br />Framework from Microsoft that that facilitates the creation of RESTful data services via HTTP endpoints<br />Shipped with .NET 3.5 SP1<br />Updates for 3.5 SP1 and .NET 4.0<br />Built on top of WCF4<br />Data representation in ATOM or JSON<br />
  28. 28. WCF Data Services Overview<br />Automates the exposure of data as RESTful resources<br />Anything that implements IQueryable<T> and IUpdatable<T><br />Entity Framework<br />3rd party ORMs<br />LINQ to SQL, custom data driven CLR classes<br />Custom URI based querying<br />
  29. 29. HTTP<br />http://localhost:1234/MyData.svc/MyEntities(10)<br />Open Data Protocol (OData)<br />Hosting/HTTP Listener<br />Data Services Runtime<br />var q = from e in MyEntities where id = 10 select e;<br />Data Access Layer<br />Entity<br />Framework<br />Custom LINQ Provider<br />SELECT * FROM MyEntity WHERE id = 10<br />Relational Database<br />Other Sources<br />
  30. 30. Data Services - A REST Interface<br /><ul><li>The underlying model
  31. 31. Entities and associations  resources and links</li></li></ul><li>URL Conventions<br />Addressing entities and sets<br /><ul><li>Presentation options</li></li></ul><li>WCF Data Services in .NET 4<br />Data Binding<br />New DataServiceCollection class provides simplified binding of data service data to (WPF) controls. Includes auto updating.<br />Counting Entities in an Set <br />$count - total number of resources returned by a URI<br />$inlinecount - total resource count together with the resource data<br />Server-driven Paging <br />Service can be configured to return requested resources as a set of paged responses<br />
  32. 32. WCF Data Services in .NET 4<br />Query Projections<br />Query results can be modified to include only a subset of properties by using the new $select query option.<br />Custom Data Service Providers<br />Can 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.<br />Streaming of Binary Resources<br />This enables you to retrieve and save binary large object data independent of the entity to which it belongs.<br />
  33. 33.
  34. 34.
  35. 35. Summary<br />
  36. 36. Resources<br />ADO.NET Team Blog<br /><br />EF Design Blog<br /><br />Visual Studio Data Blog<br /><br />dnrTV!<br /><br /><br />
  37. 37. Resources<br />ADO.NET team blog<br /><br />WCF Data Services team blog<br /><br />
  38. 38. Required Book!<br />