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
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
ORM and ADO.NET Entity Framework
Agenda
• ORM Overview and Impact• Entity Framework V1 recap • Entity Framework V4 overview• Impact of embracing Entity Framework
ORM and ADO.NET Entity Framework
ORM OVERVIEW“Not your fathers ORM”
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
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?
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
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
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
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
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”
ORM and ADO.NET Entity Framework
IMPACT OF ADOPTING AN ORM
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?
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.
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”
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....)
ORM and ADO.NET Entity Framework
ADO.NET ENTITY FRAMEWORK V1.0It arrived slightly under cooked
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
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
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
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
ORM and ADO.NET Entity Framework
Consuming the EDM1
3
2
Object Services
Entity Client
The ORM
- optional
ORM and ADO.NET Entity Framework
DEMO: ENTITY FRAMEWORK
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
ORM and ADO.NET Entity Framework
ADO.NET ENTITY FRAMEWORK V2.0An absolutely fantastic release. Did you like it?
ORM and ADO.NET Entity Framework
ADO.NET ENTITY FRAMEWORK V3.0An amazing release. Who could have thought 3.0 could beat 2.0!
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
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
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
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
ORM and ADO.NET Entity Framework
N-Tier
• Self Tracking Entities
ORM and ADO.NET Entity Framework
Persistence Ignorance
• First class support for Persistence Ignorance • No modifications to your classes!
ORM and ADO.NET Entity Framework
Code Only
• Create the database from the classes– No model– Convention to config
ORM and ADO.NET Entity Framework
DEMO: CODE GEN, MODEL FIRST, SPS, PERSISTENCE IGNORANCE …
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
ORM and ADO.NET Entity Framework
IN SUMMARY
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
ORM and ADO.NET Entity Framework
Resources
• Slides, links and more– http://geekswithblogs.net/iupdateable
• Entity Framework 4.0 Resources– http://bit.ly/ef4resources