ado.net 3.0 – entity data model

of 23 /23

Author: lesa

Post on 04-Feb-2016

30 views

Category:

Documents


0 download

Embed Size (px)

DESCRIPTION

ADO.NET 3.0 – Entity Data Model. Gert E.R. Drapers Chief Software Architect Visual Studio Team Edition for Database Professionals Microsoft Corporation http://blogs.msdn.com/gertd. Agenda. ADO.NET Entity Framework Introduction Application Scenarios Direct Mapping - PowerPoint PPT Presentation

TRANSCRIPT

  • ADO.NET 3.0 Entity Data ModelGert E.R. DrapersChief Software ArchitectVisual Studio Team Edition for Database ProfessionalsMicrosoft Corporationhttp://blogs.msdn.com/gertd

  • AgendaADO.NET Entity Framework IntroductionApplication ScenariosDirect MappingFlexible Mapping ScenariosExtensibilityUsage Best PracticesSummary

  • The Entity FrameworkADO.NET ProvidersDatasetADO.NET 2.0 The Entity Data Model Language Integrated Query (LINQ)

  • ADO.NET Data ProvidertADO.NET Data ProviderEntity Framework OverviewADO.NET Data ProviderObject ServicesLINQ to EntitiesStore SchemaConceptualSchemaObjectMetadataO-CMapC-SMap

  • EDMGEN.EXEGenerates the model filesModel.ssdl (Store Schema Definition Language)Describes tables and columns which map to Entities and RelationshipsModel.csdl (Conceptual Schema Definition Language)Describes the Entity Data Model (incl. EntitySets, EntityTypes, Associations & AssociationsSets)Model.msl (Mapping Specification Language)Describes how the Entity Framework maps between the Conceptual Model (CSDL) and the logical Storage Schema (SSDL)Model.cs or Model.vbPartial class implementing the model created

  • Direct MappingScenarioDatabase schema provides appropriate application modelBenefitsRelationshipsCommon Extended Query LanguageCommon Queryable SchemaCommon Metadata ServicesObject ServicesBusiness LogicIdentity ManagementChange TrackingLanguage Integrated Query (LINQ)

  • Flexible MappingScenarioDatabase schema doesn't match application modelBenefitsRicher Application Data ModelInheritanceM:N RelationshipsRicher MappingInheritance options (TPH, TPT, TPC)Stored ProceduresEntities split across tablesDecouples application model from storage schemaMultiple application models for same storeSame application model over different storage schemasIndependent evolution of application model/storage schema

  • ExtensibilityScenario: Building a customizable frameworkBenefitsFlexible run-time mappingsi.e., Language-specific mappingsMapping to "Extensible Schemas"EntityViewsVertical partitioning of framework and extensionsSeparate mappingsDerived typesExtending data classes

  • Best PracticesShould I use Objects or DataRecords?How long should I hold an ObjectContext?Which mapping techniques should I use?When should I used Stored Procedures or Table Valued Functions?How should I extend data classes?When should I write my own data classes?When should I use Custom Serialization?Should I use LINQ, Query Builder Methods, or eSQL?Should I use LINQ to SQL or LINQ to Entities?

  • Objects or DataRecords?Objects (IEnumerable)Strong typingBusiness logicUpdatingExample: Interactive Windows applicationData Records (IExtendedDataReader)Performance for read-only streamingSequential accessAvoid object construction overheadDoesn't require generated classesExample: Directly serializing results to a Web response

  • Holding ObjectContextWeb scenariosTypical pattern: Create, Use, disposeObjectContext holds resourcesConnectionsObject ReferencesUse NoTracking for read-only scenariosWindows Forms scenariosHold as long as application interacts with resultsObjectContext mantains stateIdentity resolutionChange trackingNew ObjectContext for each new queryEnsures data is fresh

  • Mapping TechniquesDatabase viewsCommon access patterns across applicationsOptimization of access paths through Materialized ViewsTable/View mappingsEntity properties map directly to database columnsColumns have same meaning throughout hierarchyEntitySQL views in MSLFlexible mappings expressed in EntitySQLFilter based on conditions, read-only properties, non-equality conditions, computed properties, multiple extents mapped to same tableNative SQL views in SSDLMapping on top of native SQL queriesStore-specific queriesExpose as "EntitySet" to mapping layer

  • Stored Procedures and TVFsStored ProceduresBetter control over operations on data within the databaseTighter control over operations, permissionsProvides level of indirection from storage schemaUse for operations that affect state of the databaseInserts, updates, deletesRequired for updates against ESQL and Native SQL viewsCan return multiple results in one roundtripTabled Valued FunctionsBetter control over access to data within the databaseTighter control over operations, permissionsProvides level of indirection from storage schemaUse for server-side functions that return dataResults of TVF are composable within a query

  • Extending Data ClassesDerivationAdding new persistent fields to a base classDerived typesCustomization extensionsPartial ClassesBusiness logicMethodsCalculated valuesNon-persistent fieldsCustom serialization"Activity" ClassesCommon operations on data classes

  • Custom Data ClassesEntity Framework-generated data classesDerive from Entity Framework base classChange Tracking, RelationshipManagementCommon Notifications, Property ValidationCustom data classesDerive from Entity Framework base classGenerate common patterns Insert common intermediate classDerive from your own base classImplement IEntity/IEntityWithRelationshipsExpose EntityKeyNotify ObjectContext when data changesRelationshipManager property to do relationship fixupAdd attributes for persistent fieldsHow we get O/OC metadata todayInvestigating "Persistence Ignorance" scenarios

  • Custom SerializationDefault serializationSerialize streams of EntitiesDoesn't navigate relationships in order to avoid cyclesCustom serializationSerialize GraphsManage relationship serialization to avoid cyclesSerialize to different shapes"Entity Projections"

  • LINQ, Query Builder, or eSQL?LINQStrongly typed queriesCompile-time checkingEmbedded in your applicationLINQ-Mapped Canonical FunctionsObjectQuery builder methodsQueries built from user inputIterative query buildingStore functionseSQLDynamic/AdHoc queriesPersistent queriesStore functions

  • LINQ to SQL or LINQ to Entities?LINQ to SQLEmphasis on rapid application developmentDirect mappingSingle type hierarchy to single table/view/stored proc/TVFSimple renamingDerive class for update logic/Stored ProceduresDirect mapping to Microsoft SQL Server family of databasesMicrosoft Visual Studio 2008 RTM

  • LINQ to SQL or LINQ to Entities?LINQ to EntitiesFocus on enterprise-grade data scenariosFlexible Mapping to Relational dataMapping a single class across multiple tables/viewsMapping to different types of inheritanceDirectly modeling Many to Many relationshipsMapping to an arbitrary query against the storeCommon model across productsDeclarative stored proceduresAccess to Microsoft SQL Server family and other databases through ADO.NET provider modelMicrosoft Visual Studio 2008 update

  • The LINQ Project

  • SummaryEntity Data Model provides an application-oriented data modelEntities and relationshipsStrong typing, polymorphismClient Views provide flexible mapping to your storage schemaEntities split between tables, Many:Many relationships, mapping to store queries, etc.Entity Framework lets you opt-in according to your requirementsDataReaders/ObjectseSQL/QueryBuilder/LINQGenerated/Custom Data Classes

  • ? Questions ?http://blogs.msdn.com/gertd

    *Microsoft ASP.NET ConnectionsUpdates will be available at http://www.devconnections.com/updates/LasVegas _06/ASP_Connections****************** 2007 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.

    **