What impact will the Entity Framework and Entity Data Model have on application architecture?<br />Eric Nelson<br />Micros...
Agenda<br />ORM Overview and Impact<br />Entity Framework V1 recap <br />Entity Framework V4 overview<br />Impact of embra...
ORM Overview<br />“Not your fathers ORM” <br />
Why did the industry create ORMs?<br />We started with data in the 70s<br />The first RDBMS were data centric<br />Overtim...
One approach – the Object Database<br />
The “winning approach” – Object Relational Mapping<br />Technique for working with relational data as if they were objects...
What good comes from adopting an ORM<br />Developer productivity<br />Less code<br />Better code than the “average” develo...
ORM and Code Gen<br />ORMs are highly configurable code gen tools <br />Made normally by someone else<br />We like code ge...
ORM is not...<br />The answer to life the universe and everything<br />The absolute fastest way to do everything<br />Supp...
ORM is the Vietnam of Computer Science<br />Ted Neward<br />“there is no good solution to the object/relational mapping pr...
Impact of adopting an ORM<br />
Impact of adopting an ORM<br />Start with Behaviour or start with Data?<br />Code firstor Map first?<br />Database Indepen...
Behaviour in the database?<br />RDBMS can model data and behaviour<br />Stored Procedures<br />Triggers<br />Views<br />Us...
Stored Procedures are evil?<br />From the world of Java<br />All about portability and vendor neutrality<br />Stored Proce...
Stored Procedures and ORMS<br />Some ORMs offer little or no support<br />Some offer great support<br />CUDvs CRUD<br />Fu...
ADO.NET Entity Framework v1.0<br />It arrived slightly under cooked <br />
ORM on the Windows Platform<br />Many ORMs out there<br />No clear “winner” = relatively little adoption of ORM<br />Devel...
The future of ORM on Windows<br />Entity Framework and LINQ to Entities is our strategic technology<br />Big investment in...
ADO.NET Entity Framework<br />Tools and services to create an Entity Data Model (EDM)<br />Tools and services for consumin...
Entity Data Model<br />Entity Data Model<br />Application model<br />Mapped to a persistence store<br />Comprised of three...
Consuming the EDM<br />1<br />2<br />The ORM<br />- optional<br />Object Services<br />3<br />Entity Client<br />
Demo:  Entity Framework<br />
LINQ recap<br />“Bringing relational into the languages”<br />Eliminating the impedance mismatch (No... Not really )<br /...
ADO.NET Entity Framework v2.0<br />An absolutely fantastic release. Did you like it?<br />
ADO.NET Entity Framework v3.0<br />An amazing release. Who could have thought 3.0 could beat 2.0!<br />
ADO.NET Entity Framework v4.0<br />And in Visual Studio 2010 and .NET Framework 4.0 we get our fourth release building on ...
Lots of new features<br />Better Tools and Design Experience<br />More powerful/flexible runtime<br />And<br />N-Tier<br /...
Better Tools and Design Experience<br />Templated code generation<br />Model First<br />Stored Procedures<br />Pluralizati...
More powerful/flexible runtime<br />Deferred Loading (aka lazy loading)<br />Foreign Keys surfaced<br />More complete LINQ...
N-Tier<br />Self Tracking Entities<br />
Persistence Ignorance<br />First class support for Persistence Ignorance <br />No modifications to your classes!<br />
Code Only<br />Create the database from the classes<br />No model<br />Convention to config<br />
Demo:  Code Gen, MODEL First, SPs, Persistence Ignorance …<br />
Architecturally impactful<br />Improved Code Generation<br />Mode First<br />Stored Procedures<br />EntityFunctions and SQ...
In Summary<br />
Objects trump Tables<br />Use LINQ <br />Use an ORM<br />I don’t really care which. But Nhibernate and Entity Framework ar...
Resources<br />Slides, links and more<br />http://geekswithblogs.net/iupdateable<br />Entity Framework 4.0 Resources<br />...
Upcoming SlideShare
Loading in …5
×

What Impact Will Entity Framework Have On Architecture

4,205 views

Published on

(Near) Final deck for Software Architect 2009. Download is now enabled.

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
4,205
On SlideShare
0
From Embeds
0
Number of Embeds
245
Actions
Shares
0
Downloads
101
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • http://en.wikipedia.org/wiki/Object-relational_impedance_mismatchhttp://www.agiledata.org/essays/impedanceMismatch.htmlTechnical and Culturalhttp://en.wikipedia.org/wiki/Abstraction_layerhttp://en.wikipedia.org/wiki/Abstraction_(computer_science)
  • Started in 70sODBMS 19852004 rise with open sourcedb4o
  • http://en.wikipedia.org/wiki/Abstraction_layerhttp://en.wikipedia.org/wiki/Abstraction_(computer_science)
  • DRY http://en.wikipedia.org/wiki/Don%27t_repeat_yourself YAGNI http://en.wikipedia.org/wiki/You_ain%27t_gonna_need_itLeaky http://en.wikipedia.org/wiki/Leaky_abstraction Joel http://www.joelonsoftware.com/articles/LeakyAbstractions.html Rebuff http://www.advogato.org/person/Bram/diary.html?start=43
  • http://www.codinghorror.com/blog/archives/000621.htmlA rebuff http://www.codeproject.com/KB/architecture/ORM_Vietnam.aspx
  • Anti in the MS camp http://weblogs.asp.net/fbouma/archive/2003/11/18/38178.aspx
  • LLBLGen Pro http://www.llblgen.com/Nhibernatehttp://www.hibernate.org/343.htmlEntitySpaceshttp://www.entityspaces.net/Portal/Default.aspxOpen Access http://www.telerik.com/products/orm.aspxDevForcehttp://www.ideablade.com/XPO http://www.devexpress.com/Products/NET/ORM/Lightspeedhttp://www.mindscape.co.nz/products/LightSpeed/default.aspxPlus many, many moreOf 31 .NET ORMs in 2003, 9 lasted to 2008
  • DevForce now target Entity Framework, replacing their ownLLBLGen v3 will target Entity Framework as well as their ownDevart Entity Developer
  • Talking Points: When we talk about the Entity Framework, we’re actually talking about two things: The Entity Data Model (EDM) The Entity Framework It’s important to delineate the two as separate, but complementing technologies The EDM is a set of layers that make up your application’s model, as well as it’s mapping to an underlying data store. Made up of three files: CSDL (Conceptual Schema Definition Language) MSL (Mapping Specification Language) SSDL (Storage Schema Definition Language) This separation of concerns allows great flexibility: Model your application the way you want regardless of the state/structure of its underlying data store Normalize your database as much as you need without worrying about affecting the interface of the application’s object model The EDM represents a re-useable application model that can be leveraged from within many applications/environments and persisted across numerous databases. The Entity Data Model is RDMS agnostic, and numerous database vendors are currently developing providers: Oracle, DB2, MySQL, PostgreSQL, VistaDB, SQLite, Sybase, Informix, etc. The Entity Data Model primarily of three main concepts: Entities, which represent your domain objects. Associations, which represent a relationship between two entities. Functions, which represent stored procedures or UDFs in your database that can be mapped to model-level functionality. Because there will be plenty of situations where you’ll need to use stored procedures, the Entity Data Model allows you to map functions in your model to a store procedure in your database. This is useful because you can leverage a stored procedure without having to write ADO.NET code to call it, you can simply call a function on your model. EDM functions are represented as methods on your ObjectContext class.
  • Estimated Time: 3 minutesTalking Points: This diagram helps to illustrate how each of the Entity Framework’s query options relate to each other. At the core of it all is the database-specific provider. This layer is what translates the query into the SQL flavor required for the underlying data source. Above that is the Entity Client API, which takes the Entity Framework query and passes in down to the database specific provider. If you want to use the Entity Client API directly, you see that you’re only query option is Entity SQL, and because it sits below Object Services, you don’t get any of its benefits. If you want to materialize your queries as objects, and get things like change tracking, identity mapping, relationship loading, etc. then you would use object services, that delegates its queries down to the Entity Client layer. When using Object Services you can leverage both Entity SQL and LINQ to make your queries.
  • Code GenIn V1 we had EntityClassGenerator which could be configured using eventsHard (it used CodeDom)Inflexible (not much control)In V2 we will haveTemplatedEntityClassGenerator and will ship default T4 templatesCustomization via ToolsUses Workflow FoundationComplex typesPluralizationPublic abstract PluralizationServiceDefault implementation is English OnlyDefault rules:EntityTypes / ComplexTypes are singularizedEntitySets are pluralizedNavigation Properties based on cardinalityStored ProceduresStored Procedures as functionsMapping support for stored procedure resultComplex type as return typeScalar and void return typeEntity CUD using Stored ProceduresNo need to have SPs for all CUD
  • Foreign KeysIndependent Association – v1 Product p = new Product { ID = 1,       Name = "Bovril",       Category = context.Categories                        .Single(c => c.Name == "Food") }; context.SaveChanges(); FK Association – v2 Product p = new Product     {         ID = 1,         Name = "Bovril",         CategoryID = 13     };     context.Products.AddObject(p);     context.SaveChanges();Deferred LoadingCan do lazy loadContext.deferredloading=true Model Level using ESQL<Function Name=“CustomerFullName” ReturnType=“String”><Parameter Name=“customer” Type=“MyModel.customer”> <DefiningExpression>customer.FirstName + ‘ ‘ + customer.LastName </DefiningExpression> </Function>Enables from c in ctx.Customers select c.FullName()CLR Level [EdmFunction("MyModel", "CustomerFullName")] public static string FullName(this customer c) { return String.Format("{0} {1}", c.FirstName, c.LastName); }Enables Console.WriteLine(c.FullName());Inline Functions in ESQL using Northwind;function AmountPurchased(c Customer) as Sum (c.Sales.Amt)function AmountReturned(c Customer) as Sum (c.Returns.Amt)function AmountConsumed(c Customer) as                                                                     AmountPurchased(c) – AmountReturned(c)select AmountConsumed(c) from Customers as c;
  • Code OnlyNo XML files, no model!Convention to configE.g. Convention: xxxID to a primary key, schema=dboE.g. Config: On map to schema sys and class property to table column[TableMapping(Schema=“sys”,TableName=“MyDBTable”][ColumnMapping(PropertyName=“MyClassProp1”, ColumnName=“table_column1”)][Key(PropertyName=“MyClassProp1”)]public objectset<MyThing> MyThings...
  • What Impact Will Entity Framework Have On Architecture

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

    ×