Upload
amos-shaw
View
221
Download
0
Tags:
Embed Size (px)
Citation preview
2
Entity Framework, LINQ and n-Tier architectures
Guil MagalhaesDevelopment ConsultantMicrosoft
ARC307
3
Talking Points
Overview of LINQ, Entity Framework
nTier ArchitectureDesigning with requirements in mind
nTier Development with Entity FrameworkService Recommendations and Tips
4
LINQ
5
LINQ Overview
Introduced in .NET 3.0Super powerful.It rocks.We are going to see more LINQ throughout the presentation
Everything uses it now. You should too!
6
nTier
7
nTier Architecture Overview
Presentation Layer
Business Layer
Data Access Layer
UX LayerPresentation Layer
Communications Layer
You can have a simple or more elaborated design.It’s a good thing if you can use the same Entity everywhere. If you can’t, use at least the same object contract.
The Whole Thing Layer
8
Service/Business Logic Tier
Data Tier
Consumers/Presentation Tier
Service contract
nTier Architecture Overview
When?Medium to large enterprise applications
CharacteristicsStrong UI/business logic separationEnables service-orientationEnables re-use of services and components
UI in web browser
Entity Framework
Desktop application
Webserver
9
nTier Architecture Overview
Key points:You create layers to keep things organized, structured, extensible, etc... But definitely not just for fun.There’s no point on having layers if they have absolutely strong binding.Create strong boundaries in between the layers, interfaces with strong and possibly extensible contracts.
10
nTier Architecture Overview
Demos that you usually see are not real nTier. Even the nTier demos don’t usually map to your real world requirements.
Typical requirements:Granular/Business security on entities.Fast service response. Bulk operations.Consistent programming model.Transactional support.
11
Entity Framework
12
Entity Framework Overview
13
Building a Entity Framework Model
Guilherme MagalhaesTitleCompany
demo
14
Entity Framework Overview
You can use multiple tables for the same entityToday you can generate the EDM from the RDBMS, in the future you’ll be able to do the other way around.It supports change tracking, detaching and attaching entities from its ObjectContext
Many other good features
15
ObjectContext
Entity Framework OverviewChange Tracking Across Tiers
ObjectContext
Sales Order #1
Line Item A
Line Item B
detach*&Serializeentities
deserialize& attachentities
ObjectStateEntry
SO1 EntityKey Original ValuesCurrent Values Other ∆ Info
ObjectStateEntry
SO2 EntityKeyOriginal ValuesCurrent ValuesOther ∆ Info
ObjectStateEntry
LIA EntityKeyOriginal ValuesCurrent ValuesOther ∆ Info
ObjectStateEntry
LIB EntityKeyOriginal ValuesCurrent Values
Other ∆ Info
*Detach can be explicit or implicit. Serialization will automatically detach.
16
Entity Framework Overview
Entity State:UnchangedModifiedAddedDeletedDetached
17
EF with WCF
Putting it all together
demo
18
Recommendations - Service Design
Define strong contracts and boundaries.Do not mix entities on the same service.Create homogeneous CRUD operations if you can
This saves time and creates a better programming experience
19
Recommendations - Service Design
Why not use Read(string entitySQL)? Creates “static” or strongly typed queries. Isn’t that better than 500 “GetClientByID, GetClientByName, GetClientByEnrollmentDataInBetween?”Security: You would check ACL anyway, wouldn't you?Single or Many results. It saves you processing on the client and improves performance.Opinions?
How I used to do it
20
Recommendations - Service DesignBusiness Services
Think about Entity Services and Business Services
Business Services contain your business logic:ExecuteOrder(Order orderEntity) could check your stock levels, fire off the order orchestration...I like to see them as “business providers”. You can add new ones, replace or delete old ones... But your structured data is still safe and reliable.
Entity Services only handle simple entity information:
Collection<Order> ReadAll() return all your orders on a report.
21
Recommendations - Service Design
Go ahead and support Transactions! It doesn't hurt.
BPM is a really nice ally. And if you design your services this way it’s easier to adopt it later.
22
Recommendations - Service Design Warning! Warning!
There’s a few things to remember:Your EF generated WCF contracts don’t really support data member ordering or other advanced attributes.It’s not as fast as raw T-SQL.Silverlight 2.0 should be treated differently.
24
SummaryThe ADO.NET Entity Framework automatically generates a data-access layer from aconceptual modelThe EDM is serializible, you can use it everywhere.Each application scenario has its specific requirements, and the Entity Framework provides the building blocks to handle them.Service Design is super important to your solution. Using EF features can help you to make it more extensible.
29
Resources
www.microsoft.com/teched Tech·Talks Tech·Ed BloggersLive Simulcasts Virtual Labs
http://microsoft.com/technet
Evaluation licenses, pre-released products, and MORE!
http://microsoft.com/msdn
Developer’s Kit, Licenses, and MORE!
32
Please complete anevaluation
33
© 2008 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.