Upload
david-mccarter
View
2.207
Download
0
Embed Size (px)
DESCRIPTION
Learn how to build real world nTier applications with the new 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. The session will demonstrate how to create and consume these new technologies from the ground up and focus on database modeling including views and stored procedures along with coding against the model via LINQ. Dynamic data website will also be demonstrated.
Citation preview
Please SetPhones ToVibrate
David McCarter
Building nTier Applications with Entity Framework ServicesPart 1
About David McCarter
$12
Specia
l
•Microsoft MVP•David McCarter’s .NET Coding Standards• http://
codingstandards.notlong.com/•dotNetTips.com• 700+ Tips, Tricks, Articles, Links!
•Open Source Projects:• http://codeplex.com/dotNetTips
•San Diego .NET Developers Group• www.sddotnetdg.org
•UCSD Classes• http://
dotnetdaveclasses.notlong.com
Check Out Your Local User Groups! San Diego Cloud Computing User
Group www.azureusergroup.com/group/
sandiegoazureusergroup San Diego .NET Developers Group
www.sddotnetdg.org San Diego .NET User Group
www.sandiegodotnet.com San Diego SQL Server User Group
www.sdsqlug.org
Win Free Software!
Rules Provide your business
card (or email and name)*
Indicate on the back what software you are interested in Otherwise I will pick
Winners will be picked next week
*Yes, most likely I’m going to send you and email about my user group (sddotnetdg.org) and or web site (dotNetTips.com)
Prizes1. CodeRush and Refactor
Pro from DevExpress (4)2. SecondCopy (automatic
backup software) (5) *3. CodeIt.Right Standard
from SubMain (4)
*Requires mailing address and phone number
Agenda
Overview
nTier Architecture Overview
Model to create flexible reusable applications
Only need to modify or add layers instead of rewriting entire applications over
User ExperienceUI ComponentsWindows Forms, Windows Presentation Foundation, ASP.NET (AJAX, MVC), Silverlight, Windows Mobile
Presentation Layer
Communications LayerWindows Communication Foundation (WCF), WCF Data Services, Web Services, Sync Services, Azure (Cloud), RIA Services, Workflow Services
Business Layer
Data LayerEntity Framework, LINQ to SQL, DataSets
Secu
rity
Act
ive D
irect
ory
, C
ard
Space
, W
ind
ow
s Id
enti
ty
Foundati
on
Business EntitiesT4 Templates
Business Components
Business WorkflowWindows Workflow Foundation
SQL Server
Local Storage/ Cache
Entity Framework
Object Relational Mapping
What is ORM? Technique for working with relational
tables as if they were objects in memory Intention is to hide away the complexity
of the underlying tables and give a uniform way of working with data
Why use ORM? Productivity Retain database independence
ObjectsClassesEntities
Object Relational Mapping
It’s nothing new, just new to .NET There are many ORMs for .NET
developers already in existence. E.g. LLBLGen Pro http://www.llblgen.com/ Nhibernate
http://www.hibernate.org/343.html EntitySpaces
http://www.entityspaces.net/Portal/Default.aspx
The Microsoft Entity Data Model An extended relational model with
Entity-Relationship Model concepts Entity Types
Strong type with Identity Inheritance Scalar/Complex properties
EntitySets Hold instances of Entity Types
Similar to relational tables Can have multiple Entitysets of the same EntityTypes
Relationships ("Associations") Named relationships between Entities 0..1:*, 0..1:0..1, 1:1, 1:M, M:N Navigation may be exposed as NavigationProperties
on EntityTypes AssociationSets
Contains instances of associations May be queried directly
EntityContainers Contains EntitySets, AssociationSets
SalesPerson
EmployeeID = 729742LoginID = peteTitle = "Developer"VacationHours = 0…ExpenseAccount = …CarLicenseNum = ……
SalesPerson
EmployeeID = 729742LoginID = peteTitle = "Developer"VacationHours = 0…ExpenseAccount = …CarLicenseNum = ……
SalesPerson
EmployeeID = 729742LoginID = peteTitle = "Developer"VacationHours = 0…ExpenseAccount = true…
SalesPerson
EmployeeID = 294272LoginID = adamTitle = "Dev Lead"VacationHours = 0…
Reports
Manager
11
N
EDM & Entity Framework?
The Entity Framework (EF) is an Object Relational Modeling tool leveraging the EDM
Focus 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
LINQ to Entities – Lots of Topics
DEMO
Pain Points in v3.5 SP1
Pluralization/ Singularization Foreign Keys Model First Lazy Loading Additional LINQ Operators L2S Features & Patterns SQL Gen Improvements
Fixing the Paint Points in EF1
Advanced/ New Features
Model First
Create your conceptual model first (not from an existing database)
Wizard will allow the creation of sql scripts to create database scripts. Also will create EDM files Creates SQL Server, SQL Server Express,
SQL Server Compact database scripts.
Lazy Loading
Enables retrieving all related data (without asking for it) Off by default Settable on the ContextOptions
Good for doing reporting! Not great for going across services
Dim ctx As New AdventureWorksLT_DataEntities() ctx.ContextOptions.LazyLoadingEnabled = True
T4 Templates
Override default EF classes to create… POCO Entity Generator
Better for going over RESTful service layers Self-Tracking Entity Generator
Better for server/ client local storage. Auto generates classes when models
change! Or can be run manually.
Easily modifiable for your own needs Once you learn the T4 scripting
language.
DEMO
Summary
Conclusion
Resources
ADO.NET Team Blog http://blogs.msdn.com/adonet/
default.aspx EF Design Blog
blogs.msdn.com/efdesign Visual Studio Data Blog
http://blogs.msdn.com/vsdata/ dnrTV!
http://shrinkster.com/1734 http://shrinkster.com/1735
Resources
Dan Simmons Blog http://blogs.msdn.com/dsimmons/
MSDN Code Gallery http://shrinkster.com/1733
WCF Data Services Learning Guide: http://msdn.microsoft.com/en-us/data/
bb931106.aspx WCF Data Services Team Blog
http://blogs.msdn.com/astoriateam/default.aspx
Required Book!
EF4 In Aug 2010
Questions?•Presentation Downloads• slideshare.com/dotnetdave
•Please Rate My Session:• speakerrate.com/
dotnetdave•David McCarter’s .NET Coding Standards• codingstandards.notlong.co
m•Geek Swag• geekstuff.notlong.com