building ntier applications with entity framework services (part 1)

28
Please Set Phones To Vibrate [email protected] David McCarter Building nTier Applications with Entity Framework Services Part 1

Upload: david-mccarter

Post on 25-Jan-2015

2.210 views

Category:

Technology


0 download

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.

TRANSCRIPT

Page 1: Building nTier Applications with Entity Framework Services (Part 1)

Please SetPhones ToVibrate

[email protected]

David McCarter

Building nTier Applications with Entity Framework ServicesPart 1

Page 2: Building nTier Applications with Entity Framework Services (Part 1)

[email protected]

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

Page 3: Building nTier Applications with Entity Framework Services (Part 1)

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

Page 4: Building nTier Applications with Entity Framework Services (Part 1)

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

Page 5: Building nTier Applications with Entity Framework Services (Part 1)

Agenda

Page 6: Building nTier Applications with Entity Framework Services (Part 1)

Overview

Page 7: Building nTier Applications with Entity Framework Services (Part 1)

nTier Architecture Overview

Model to create flexible reusable applications

Only need to modify or add layers instead of rewriting entire applications over

Page 8: Building nTier Applications with Entity Framework Services (Part 1)

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

Page 9: Building nTier Applications with Entity Framework Services (Part 1)

Entity Framework

Page 10: Building nTier Applications with Entity Framework Services (Part 1)

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

Page 11: Building nTier Applications with Entity Framework Services (Part 1)

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

Page 12: Building nTier Applications with Entity Framework Services (Part 1)

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

Page 13: Building nTier Applications with Entity Framework Services (Part 1)

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.

Page 14: Building nTier Applications with Entity Framework Services (Part 1)

ADO.NET Entity Framework

Page 15: Building nTier Applications with Entity Framework Services (Part 1)

LINQ to Entities – Lots of Topics

Page 16: Building nTier Applications with Entity Framework Services (Part 1)

DEMO

Page 17: Building nTier Applications with Entity Framework Services (Part 1)

Pain Points in v3.5 SP1

Pluralization/ Singularization Foreign Keys Model First Lazy Loading Additional LINQ Operators L2S Features & Patterns SQL Gen Improvements

Page 18: Building nTier Applications with Entity Framework Services (Part 1)

Fixing the Paint Points in EF1

Advanced/ New Features

Page 19: Building nTier Applications with Entity Framework Services (Part 1)

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.

Page 20: Building nTier Applications with Entity Framework Services (Part 1)

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

Page 21: Building nTier Applications with Entity Framework Services (Part 1)

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.

Page 22: Building nTier Applications with Entity Framework Services (Part 1)

DEMO

Page 23: Building nTier Applications with Entity Framework Services (Part 1)

Summary

Page 24: Building nTier Applications with Entity Framework Services (Part 1)

Conclusion

Page 25: Building nTier Applications with Entity Framework Services (Part 1)

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

Page 26: Building nTier Applications with Entity Framework Services (Part 1)

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

Page 27: Building nTier Applications with Entity Framework Services (Part 1)

Required Book!

EF4 In Aug 2010

Page 28: Building nTier Applications with Entity Framework Services (Part 1)

[email protected]

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