Entity Framework 4 In Microsoft Visual Studio 2010 - ericnel
- 1. ADO.NET Entity Framework in Microsoft Visual Studio 2010 and Microsoft .NET Framework 4Eric Nelson eric.nelson@microsoft.comhttp://geekswithblogs.net/iupdateable(or http://bit.ly/ericnelson )http://twitter.com/ericnelhttp://twitter.com/ukmsdnDeveloper EvangelistMicrosoft UK
- 2. Were you on twitter last Dec?http://twitter.com/ericnel
- 4. Object Relational MappingMany ORMs out thereNo clear “winner” = relatively little adoption of ORMDevelopers waiting on MicrosoftThen we shipped two ... hmmmLINQ to SQL in Visual Studio 2008ADO.NET Entity Framework in Visual Studio 2008 SP1
- 5. ADO.NET Entity Framework RecapEntity Data ModelTools and services to create an Entity Data Model (EDM)Conceptual to Mapping to StorageTools and services for consuming an Entity Data ModelLINQ to Entities, Object Services and Entity SQLTogether they address the “impedance mismatch” Objects in ApplicationsConceptualMappingStorageRows in Tables
- 6. Entity Framework 1.0Too many pain pointsThe designer!Model First not supportedPoor support for Stored ProceduresNo Pluralization/SingularizationForeign Keys hiddenLazy Loading not supportedMissing LINQ Operators vs LINQ to SQLGenerated SQL unreadableNo support for Plain Old CLR ObjectsN-Tier difficult
- 7. Entity Framework 4.0Removing the frictionBetter Tools and Design ExperienceMore powerful/flexible runtimeAndPersistence Ignorance*Code Only*N-Tier*Note:* Delivered in .NET Framework 4 and a separate download
- 8. Better Tools and Design ExperienceModel FirstTemplated code generationStored ProceduresPluralization/SingularizationComplex TypesBetter delete and search
- 10. More powerful/flexible runtimeLazy Loading (Deferred Loading in Beta 1 )Foreign Keys surfacedMore complete LINQ implementationExecuteStoreQueryEntityFunctions and SqlFunctionsImprovements to generated SQL
- 19. Entity Framework The designer!No support for Plain Old CLR ObjectsNo Pluralization/SingularizationForeign Keys hiddenModel First not supportedLazy Loading not supportedMissing LINQ Operators vs LINQ to SQLGenerated SQL unreadableN-Tier difficultPoor support for Stored Procedures
- 20. SummaryEntity Framework 4.0 is rather nice!We continue to listen and improveResourcesInstall VS2010 Beta 2 http://bit.ly/vs2010b2My blog for EF 4 posts http://bit.ly/ericnelsonChannel 9 Screencasts on EF4 http://bit.ly/ch9ukdevteamEntity Framework 4.0 Resources http://bit.ly/ef4resourcesEntity Framework Team Blog http://blogs.msdn.com/adonet/Entity Framework Design Blog http://blogs.msdn.com/efdesign/
Editor's Notes
- 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
- 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...