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