ADO.NET Entity Framework in Microsoft Visual Studio 2010 and Microsoft .NET Framework 4<br />Eric Nelson <br />eric.nelson...
Agenda<br />Swift intro to Entity Framework<br />Entity Framework 4.0 Drill Down<br />Lots of demos<br />
Why an ORM? Why Entity Framework?<br />
Why an ORM? Why Entity Framework?<br />
ADO.NET Entity Framework Recap<br />Entity Data Model<br />Tools and services to create an Entity Data Model (EDM)<br />Co...
Model First and Templated Code Generation<br />demo<br />
Entity Framework 1.0 Features<br />Generate model from database schema<br />Very rich mapping layer<br />Inheritance, rena...
Entity Framework 1.0 - Too many pain points<br />The designer!<br />Model First not supported<br />Poor support for Stored...
Entity Framework 4.0<br />
New in ADO.NET Entity Framework 4.0<br />Model-first development<br />Automatic pluralization<br />Foreign keys in models<...
Entity Framework 4.0 - Removing the friction<br />Better Tools and Design Experience<br />More powerful/flexible runtime<b...
Better Tools and Design Experience<br />Model First<br />Templated code generation<br />Stored Procedures<br />Pluralizati...
Model First and Templated Code Generation<br />demo<br />
More powerful/flexible runtime<br />Lazy loading<br />Foreign Keys surfaced<br />More complete LINQ implementation<br />Ex...
Deferred Loading, Generated SQL<br />demo<br />
http://blogs.msdn.com/adonet/archive/2009/08/05/improvements-to-the-generated-sql-in-net-4-0-beta1.aspx<br />
Feature Pack<br />Separate download<br />Contents<br />T4 Template for Persistence Ignorance/POCO<br />T4 Template for sel...
Persistence Ignorance/POCO<br />First class support for Persistence Ignorance <br />No modifications to your classes!<br />
Persistence Ignorance<br />demo<br />
N-Tier (Self Tracking Entities)<br />Service<br />publicclassNorthwindService : INorthwindService<br />{<br />    publicCu...
N-Tier<br />demo<br />
Code Only<br />Create the database from the classes<br />No model<br />Convention to config<br />
Database First / Model First / CodeOnly<br />Database First (EF v1)<br />Model First<br />Code Only<br />
Code Only<br />demo<br />
Entity Framework <br />The designer!<br />No support for Plain Old CLR Objects<br />No Pluralization/Singularization<br />...
Summary<br />Entity Framework 4.0 is rather nice!<br />We continue to listen and improve<br />Resources<br />Entity Framew...
Required Slide<br />© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product...
Upcoming SlideShare
Loading in …5
×

Entity Framework 4 In Microsoft Visual Studio 2010

19,749 views

Published on

Session delivered 15th Feb 2010 using RC of VS2010

Published in: Technology

Entity Framework 4 In Microsoft Visual Studio 2010

  1. 1. ADO.NET Entity Framework in Microsoft Visual Studio 2010 and Microsoft .NET Framework 4<br />Eric Nelson <br />eric.nelson@microsoft.com<br />http://geekswithblogs.net/iupdateable<br />http://twitter.com/ericnel<br />Developer Evangelist<br />Microsoft UK<br />Advert Alert http://ukazure.ning.com<br />
  2. 2. Agenda<br />Swift intro to Entity Framework<br />Entity Framework 4.0 Drill Down<br />Lots of demos<br />
  3. 3. Why an ORM? Why Entity Framework?<br />
  4. 4. Why an ORM? Why Entity Framework?<br />
  5. 5. ADO.NET Entity Framework Recap<br />Entity Data Model<br />Tools and services to create an Entity Data Model (EDM)<br />Conceptual to Mapping to Storage<br />Tools and services for consuming an Entity Data Model<br />LINQ to Entities, Object Services and Entity SQL<br />Together they address the “impedance mismatch” <br />Objects in <br />Applications<br />Conceptual<br />Mapping<br />Storage<br />Rows in <br />Tables<br />
  6. 6. Model First and Templated Code Generation<br />demo<br />
  7. 7. Entity Framework 1.0 Features<br />Generate model from database schema<br />Very rich mapping layer<br />Inheritance, rename, aggregate, filter<br />Simplified CRUD operations<br />LINQ querying*<br />Worked with many databases<br />Database agnostic query language<br />SP support for data retrieval/modification*<br />Designer*<br />Strategic!<br />
  8. 8. Entity Framework 1.0 - Too many pain points<br />The designer!<br />Model First not supported<br />Poor support for Stored Procedures<br />No Pluralization/Singularization<br />Foreign Keys hidden<br />Lazy Loading not supported<br />Missing LINQ Operators vs LINQ to SQL<br />Generated SQL unreadable<br />No support for Plain Old CLR Objects<br />N-Tier difficult<br />
  9. 9. Entity Framework 4.0<br />
  10. 10. New in ADO.NET Entity Framework 4.0<br />Model-first development<br />Automatic pluralization<br />Foreign keys in models<br />POCO class support<br />Lazy loading<br />T4 Code Generation<br />Template customization<br />IObjectSet<br />Virtual SaveChanges<br />ObjectStateManager control<br />Self-tracking entities<br />SQL generation improvements<br />More LINQ operator support<br />LINQ extensibility<br />ExecuteStoreQuery<br />ExecuteStoreCommand<br />SPROC import improvements<br />Model defined functions<br />WPF designer integration<br />Code-Only development (Feature CTP)<br />
  11. 11. Entity Framework 4.0 - Removing the friction<br />Better Tools and Design Experience<br />More powerful/flexible runtime<br />And<br />Persistence Ignorance*<br />N-Tier<br />Code Only*<br />Note:<br />* Delivered in .NET Framework 4 and a separate download <br />
  12. 12. Better Tools and Design Experience<br />Model First<br />Templated code generation<br />Stored Procedures<br />Pluralization/Singularization<br />Complex Types<br />Better delete and search<br />
  13. 13. Model First and Templated Code Generation<br />demo<br />
  14. 14. More powerful/flexible runtime<br />Lazy loading<br />Foreign Keys surfaced<br />More complete LINQ implementation<br />ExecuteStoreQuery<br />EntityFunctions and SqlFunctions<br />Improvements to generated SQL<br />
  15. 15. Deferred Loading, Generated SQL<br />demo<br />
  16. 16. http://blogs.msdn.com/adonet/archive/2009/08/05/improvements-to-the-generated-sql-in-net-4-0-beta1.aspx<br />
  17. 17. Feature Pack<br />Separate download<br />Contents<br />T4 Template for Persistence Ignorance/POCO<br />T4 Template for self-tracking entities (Now part of VS2010 RC)<br />Code-only support<br />When VS2010 is RTM, Feature Pack will be high quality.<br />
  18. 18. Persistence Ignorance/POCO<br />First class support for Persistence Ignorance <br />No modifications to your classes!<br />
  19. 19. Persistence Ignorance<br />demo<br />
  20. 20. N-Tier (Self Tracking Entities)<br />Service<br />publicclassNorthwindService : INorthwindService<br />{<br /> publicCustomerGetCustomer(string id)<br /> {<br />using (varctx = newNorthwindEntities())<br /> {<br />returnctx.Customers.Include(&quot;Orders&quot;)<br /> .Where(c =&gt; c.CustomerID == id)<br /> .SingleOrDefault();<br /> }<br />}<br />publicboolSubmitOrder(OrdernewOrder)<br /> {<br />using (varctx = newNorthwindEntities())<br /> {<br />ctx.Orders.ApplyChanges(newOrder);<br />ValidateOrderGraph(ctx, newOrder);<br />returnctx.SaveChanges() &gt; 0;<br /> }<br />}<br />}<br />Client<br />staticboolValidSTEUpdate(INorthwindService svc)<br />{<br />var customer = svc.GetCustomer(&quot;ALFKI&quot;);<br />// modify contact name of customer<br />customer.ContactName += &quot;+&quot;;<br />// add a new order<br />varnewOrder = newOrder();<br />newOrder.Order_Details.Add(newOrder_Detail() <br />{ <br />ProductID = products.Where(p =&gt; p.ProductName == &quot;Chai&quot;).Single().ProductID,<br /> Quantity = 1<br /> });<br />customer.Orders.Add(newOrder);<br /> return svc.SubmitOrder(newOrder);<br />}<br />Danny Simmons MSDN Article: Building N-Tier Apps with EF4<br />http://code.msdn.microsoft.com/mag200911EF4 http://msdn.microsoft.com/en-gb/magazine/ee335715.aspx<br />
  21. 21. N-Tier<br />demo<br />
  22. 22. Code Only<br />Create the database from the classes<br />No model<br />Convention to config<br />
  23. 23. Database First / Model First / CodeOnly<br />Database First (EF v1)<br />Model First<br />Code Only<br />
  24. 24. Code Only<br />demo<br />
  25. 25. Entity Framework <br />The designer!<br />No support for Plain Old CLR Objects<br />No Pluralization/Singularization<br />Foreign Keys hidden<br />Model First not supported<br />Lazy Loading not supported<br />Missing LINQ Operators vs LINQ to SQL<br />Generated SQL unreadable<br />N-Tier difficult<br />Poor support for Stored Procedures<br />
  26. 26. Summary<br />Entity Framework 4.0 is rather nice!<br />We continue to listen and improve<br />Resources<br />Entity Framework 4.0 Resources http://bit.ly/ef4resources<br />Entity Framework Team Blog<br />http://blogs.msdn.com/adonet/<br />Entity Framework Design Blog http://blogs.msdn.com/efdesign/<br />
  27. 27. Required Slide<br />© 2009 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.<br />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.<br />

×