1 Entity Framework Introduction. Outline Goals of Entity Framework 2.
What Impact Will Entity Framework Have On Architecture
-
Upload
eric-nelson -
Category
Technology
-
view
5.622 -
download
0
description
Transcript of What Impact Will Entity Framework Have On Architecture
![Page 1: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/1.jpg)
ORM and ADO.NET Entity Framework
What impact will the Entity Framework and Entity Data Model have on application
architecture?
Eric NelsonMicrosoft UKBlog: http://geekswithblogs.net/iupdateableTwitter: http://twitter.com/ericnel and http://twitter.com/ukmsdnPodcast: http://bit.ly/msdnpodcast Newsletter: http://msdn.microsoft.com/en-gb/flash
Slides, links and background “diary” posts can be found on my blog
![Page 2: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/2.jpg)
ORM and ADO.NET Entity Framework
Agenda
• ORM Overview and Impact• Entity Framework V1 recap • Entity Framework V4 overview• Impact of embracing Entity Framework
![Page 3: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/3.jpg)
ORM and ADO.NET Entity Framework
ORM OVERVIEW“Not your fathers ORM”
![Page 4: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/4.jpg)
ORM and ADO.NET Entity Framework
Why did the industry create ORMs?
• We started with data in the 70s• The first RDBMS were data centric
– Overtime they received bolt ons for behaviour
• In the late 90s, programming became object centric– Rise of OOP and OOD– Behaviour
• The two approaches didn’t play nice– “impedance mismatch”– Different type systems– Different emphasis– Set vs Graph theory– Many to Many
![Page 5: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/5.jpg)
ORM and ADO.NET Entity Framework
One approach – the Object Database
Rise of the Object
Database
Stall of the Object
Database
Rise of the Object
Database?
![Page 6: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/6.jpg)
ORM and ADO.NET Entity Framework
The “winning approach” – Object Relational Mapping
• Technique for working with relational data as if they were objects in memory– Hide away the complexity of the underlying tables and give a uniform
way of working with data
• An Abstraction– RDBMS is about data– OO is about data + behaviour
![Page 7: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/7.jpg)
ORM and ADO.NET Entity Framework
What good comes from adopting an ORM
• Developer productivity– Less code– Better code than the “average” developer– Better database code than the “average” developer
• Retain database independence
![Page 8: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/8.jpg)
ORM and ADO.NET Entity Framework
ORM and Code Gen
• ORMs are highly configurable code gen tools – Made normally by someone else
• We like code gen– Helps with DRY
• But we sometimes dislike ORMs– As they can break YAGNI– And they often are “leaky”– And we didn’t write them– And they aren’t perfect for what we have in mind
![Page 9: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/9.jpg)
ORM and ADO.NET Entity Framework
ORM is not...
• The answer to life the universe and everything• The absolute fastest way to do everything• Supported by many reporting tools• Always in step with RDBMS advances
![Page 10: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/10.jpg)
ORM and ADO.NET Entity FrameworkSi
deBa
rORM is the Vietnam of Computer Science
• Ted Neward– “there is no good solution to the
object/relational mapping problem”– Painful tradeoffs
• Proposed “Integration of relational concepts into the languages”
![Page 11: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/11.jpg)
ORM and ADO.NET Entity Framework
IMPACT OF ADOPTING AN ORM
![Page 12: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/12.jpg)
ORM and ADO.NET Entity Framework
Impact of adopting an ORM
• Start with Behaviour or start with Data?• Code first or Map first?• Database Independence but at what cost? • Always access via the ORM?• No behaviour in the database?
![Page 13: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/13.jpg)
ORM and ADO.NET Entity Framework
Behaviour in the database?
• RDBMS can model data and behaviour– Stored Procedures– Triggers– Views– User defined types
• Some RDBMS better than others– SQL Server 2005/2008 can run .NET code and you can extend the type
system.
![Page 14: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/14.jpg)
ORM and ADO.NET Entity Framework
Stored Procedures are evil?
• From the world of Java– All about portability and vendor neutrality– Stored Procedures were hard to port
• ANSI SQL std doesnt includes SPs– Therefore don’t use Stored Procedures– This is changing...
• From the world of .NET– Overuse – Incorrect use– Lead to “no sps here”
![Page 15: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/15.jpg)
ORM and ADO.NET Entity Framework
Stored Procedures and ORMS
• Some ORMs offer little or no support• Some offer great support
– CUD vs CRUD– Functions
• Still a great choice– Can solves identified performance bottlenecks– Bulk data manipulation– Maintenance operations– Multiple applications to the same database– Security (hmmm....)
![Page 16: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/16.jpg)
ORM and ADO.NET Entity Framework
ADO.NET ENTITY FRAMEWORK V1.0It arrived slightly under cooked
![Page 17: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/17.jpg)
ORM and ADO.NET Entity Framework
ORM on the Windows Platform
• Many ORMs out there• No clear “winner” = relatively little adoption of ORM• Developers waiting on Microsoft
![Page 18: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/18.jpg)
ORM and ADO.NET Entity Framework
The future of ORM on Windows
• Entity Framework and LINQ to Entities is our strategic technology– Big investment into Entity Framework 4.0 in VS2010
• Best of LINQ to SQL moves into LINQ to Entities
– Microsoft is using it• Data Services - shipping• Reporting Services• more
• Partners supporting it– Database Vendors – IBM,OpenLink, DataDirect, Devart etc– ORM vendors supporting it
• Entity Framework is not just about ORM
![Page 19: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/19.jpg)
ORM and ADO.NET Entity Framework
ADO.NET Entity Framework
• Tools and services to create an Entity Data Model (EDM)
• Tools and services for consuming an Entity Data Model
![Page 20: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/20.jpg)
ORM and ADO.NET Entity Framework
Entity Data Model
• Application model– Mapped to a persistence store
• Comprised of three layers:– Conceptual (CSDL)– Mapping (MSL)– Storage (SSDL)
• Database agnostic• Comprised of:
– Entities– Associations– Functions
Conceptual
Mapping
Storage
Entity Data Model
![Page 21: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/21.jpg)
ORM and ADO.NET Entity Framework
Consuming the EDM1
3
2
Object Services
Entity Client
The ORM
- optional
![Page 22: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/22.jpg)
ORM and ADO.NET Entity Framework
DEMO: ENTITY FRAMEWORK
![Page 23: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/23.jpg)
ORM and ADO.NET Entity Framework
LINQ recap
• “Bringing relational into the languages”– Eliminating the impedance mismatch (No... Not really )
• LINQ to SQL is like C# to C++• Tidy, Composable, Associations, Shaped results,
Parameterization, Client processing
http://linqpad.net/WhyLINQBeatsSQL.aspx
![Page 24: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/24.jpg)
ORM and ADO.NET Entity Framework
ADO.NET ENTITY FRAMEWORK V2.0An absolutely fantastic release. Did you like it?
![Page 25: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/25.jpg)
ORM and ADO.NET Entity Framework
ADO.NET ENTITY FRAMEWORK V3.0An amazing release. Who could have thought 3.0 could beat 2.0!
![Page 26: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/26.jpg)
ORM and ADO.NET Entity Framework
ADO.NET ENTITY FRAMEWORK V4.0
And in Visual Studio 2010 and .NET Framework 4.0 we get our fourth release building on the success of 1.0, 2.0 and 3.0
![Page 27: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/27.jpg)
ORM and ADO.NET Entity Framework
Lots of new features
• Better Tools and Design Experience• More powerful/flexible runtime• And
– N-Tier– Persistence Ignorance– Code Only
![Page 28: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/28.jpg)
ORM and ADO.NET Entity Framework
Better Tools and Design Experience
• Templated code generation• Model First• Stored Procedures• Pluralization• Complex Types• Better delete and search
![Page 29: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/29.jpg)
ORM and ADO.NET Entity Framework
More powerful/flexible runtime
• Deferred Loading (aka lazy loading)• Foreign Keys surfaced• More complete LINQ implentation• ExecuteStoreQuery• EntityFunctions and SqlFunctions• Improvements to generated SQL
![Page 30: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/30.jpg)
ORM and ADO.NET Entity Framework
N-Tier
• Self Tracking Entities
![Page 31: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/31.jpg)
ORM and ADO.NET Entity Framework
Persistence Ignorance
• First class support for Persistence Ignorance • No modifications to your classes!
![Page 32: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/32.jpg)
ORM and ADO.NET Entity Framework
Code Only
• Create the database from the classes– No model– Convention to config
![Page 33: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/33.jpg)
ORM and ADO.NET Entity Framework
DEMO: CODE GEN, MODEL FIRST, SPS, PERSISTENCE IGNORANCE …
![Page 34: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/34.jpg)
ORM and ADO.NET Entity Framework
Architecturally impactful
• Improved Code Generation• Mode First• Stored Procedures• EntityFunctions and SQLFunctions• Self Tracking Entities• Persistence Ignorance• Code Only
![Page 35: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/35.jpg)
ORM and ADO.NET Entity Framework
IN SUMMARY
![Page 36: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/36.jpg)
ORM and ADO.NET Entity Framework
Objects trump Tables
• Use LINQ • Use an ORM
– I don’t really care which. But Nhibernate and Entity Framework are good candidates
• Use an ORM wisely
![Page 37: What Impact Will Entity Framework Have On Architecture](https://reader033.fdocuments.net/reader033/viewer/2022061201/54798206b4af9fb4158b4858/html5/thumbnails/37.jpg)
ORM and ADO.NET Entity Framework
Resources
• Slides, links and more– http://geekswithblogs.net/iupdateable
• Entity Framework 4.0 Resources– http://bit.ly/ef4resources