Download presentation
Presentation is loading. Please wait.
1
Accessing Data in a .NET Web Application
Shyam Pather Development Manager Data and Modeling Group – Microsoft
2
Agenda .NET Data Access basics for the Web
MVC, Repositories, and POCOs Using Models: Entity Framework and EDM Accessing OData
3
Demo: .NET Data Access basics
4
Demo Recap ADO.NET basic patterns
using (connection) { … } connection.CreateCommand() command.ExecuteReader() Connection strings managed in Web.config Simple, streaming access to data
5
Where should data access go?
M, V, C is about separation of concerns Data Access goes in model layer Use the repository pattern to hide data access details Use POCO / “Persistence Ignorant” data classes Controllers consume repository Views consume POCO model classes Controller Action Methods View HTML Model Repository + POCOs
6
Where do we get our POCOs?
Definition of POCO classes Hand-written classes (Later) Code generation Instantiation of POCO classes “By hand” from DataReader results Automatically, using ExecuteStoreQuery<T>
7
Demo: MVC, Repositories, POCOs
8
Demo Recap Same basic ADO.NET patterns but hide the details
Use repository pattern Repositories return POCOs Consumed by the controller Bound to the View ExecuteStoreQuery<T> Easiest way to get objects from query results
9
Using Models Entity Data Model lets you describe your data
Entities with Relationships Complex types, inheritance, navigations etc. Mapping to database Entity Framework gives you CRUD over your model LINQ querying, POCOs for results Change tracking, updates You can get other services too… E.g. WCF Data Services provides OData head
10
Creating Models Start with the database Start with an edmx model
“Database is the truth” Why? It already exists, or you want low level control over the database What? Import model into edmx and tweak Walkthrough: This talk Start with an edmx model “Edmx is the truth” Why? You want separation from code and database in a declarative format What? Create a model in the designer Walkthrough: Start with .net classes “Code is the truth” Why? Primarily focused on code shape, database is an implementation detail What? Define classes in code, adjust shape using contextbuilder Walkthrough:
11
Demo: Using Models
12
Demo Recap 3 ways to create an EDM
From database On the design surface With code Entity Framework provides rich data access over EDM E.g. LINQ, lazy loading, change tracking T4-based code generation Using EDM gives you other services e.g. OData head Use WCF Data Services
13
What is OData? Uniform way of representing structured data
Atom, JSON formats Uniform URL conventions Navigation, filtering, sorting, paging, etc. Uniform operations Addressability GET, POST, PUT, DELETE always mean the same A growing number of services and clients Servers: OGDI, NetFlix, Reporting Services Clients: .NET, AJAX, PHP, Excel
14
Consuming OData Services
On .NET Use Add Service Reference (generates proxy classes) WCF Data Services client library Uses patterns similar to Entity Framework Supports LINQ querying Fits easily into the repository pattern Many other clients for other platforms
15
Demo: OData Access
16
Demo Recap Add Service Reference generates OData proxies
Similar patterns to Entity Framework LINQ, Change Tracking etc. Use the repository pattern!
17
Call to Action Explore your data access options in .NET
Visit Try out the .NET 4 / VS2010 RC Learn more about OData
18
Don’t forget… Please fill out an evaluation! Session Code: FT 15
Send questions to:
19
11/27/2018 7:29 PM © 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.
20
11/27/2018 7:29 PM © 2010 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. © 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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.