SlideShare une entreprise Scribd logo
1  sur  21
Dev303: Leap Ahead in Productivity with LINQ & Entity Framework Ronald Widha @RonaldWidhaTeam Lead Infusion Development
Required Slide Complete an evaluation on CommNet and enter to win an HTC HD2!
Agenda Pattern #1: Smart Client Pattern #2: 3 Tier Architecture Domain Driven Design Pattern #3: Domain Modelling Entity Data Model Entity Framework 4 Entity Framework 4 cool features (POCO, code only)
Presentation Tier Data Smart Client
Presentation Tier Business         Data 3 Tier Architecture
Demo: RAD and 3 Tier
Domain Driven Design “an approach to developing software for complex needs by deeply connecting the implementation to an evolving model of the core business concepts.”
Domain Driven Design Tackling complexity How: Talk to the business! Focus on the core business domain  Design system based on a model
The concept Entity & Value Objects Aggregate Roots Repositories Value Objects Value Objects Repository Aggregate Root Entity Entity Value Objects
Keep it in sync with reality Business rules change: REFACTOR! Names change: REFACTOR!
Presentation Tier Business         Data Domain Models
Linq to Sql Isn’t flexible enough for domain modelling 1-1 table mapping Table per Hierarchy No provider model Awesome for data access
Entity Data Model An abstract conceptual model of data Based on Entity Relationship Model by Dr. Peter Chen (1976) Entities and Relationships Entity types Association types Navigation properties Sounds familiar??
The Entity Framework 4 The next layer up in the ADO.Net stack First product to implement EDM Entity Data Model design tools Strongly typed LINQ access Declarative mapping to the database The next version to Entity Framework 1 from .Net 3.5 Available in .Net 4.0
Demo: Domain Driven approach using Entity Framework
Full control Just basic POCO: Plain Old CLR Objects Persistence Ignorance Turn off code generation from EDMX
Demo: Domain Driven approach using Entity Framework POCO
POCO and Other EF Features Different ways of mapping: Table per class, Table per type, Table per hierarchy Mapping with stored procedures Explicit Loading ObjectContext.LoadProperty(someObject, x => x.property) Lazy Loading Property as virtual Uses proxy instance at runtime
Code-only design No model Metadata is inferred from classes Convention by Default Configuration Tweak configuration Create database at runtime
Last Notes Don’t take the demo as best practice There are a lot more to Domain Driven Design that what’s shown here There are a lot more we can do to improve the demo code (Unit of work!) EF4 is perfect to enable Domain Driven approach
question & answer

Contenu connexe

Plus de Ronald Widha

DV01 Ten Things You Always Wanted to Know About Windows Azure But Were Afraid...
DV01 Ten Things You Always Wanted to Know About Windows Azure But Were Afraid...DV01 Ten Things You Always Wanted to Know About Windows Azure But Were Afraid...
DV01 Ten Things You Always Wanted to Know About Windows Azure But Were Afraid...Ronald Widha
 
DV03 Smooth Migration to Windows Azure
DV03 Smooth Migration to Windows AzureDV03 Smooth Migration to Windows Azure
DV03 Smooth Migration to Windows AzureRonald Widha
 
Tech-out's Hack-a-day
Tech-out's Hack-a-dayTech-out's Hack-a-day
Tech-out's Hack-a-dayRonald Widha
 
ASI202 Everything you want to know about Windows Azure but were afraid to ask
ASI202 Everything you want to know about Windows Azure but were afraid to askASI202 Everything you want to know about Windows Azure but were afraid to ask
ASI202 Everything you want to know about Windows Azure but were afraid to askRonald Widha
 
DPR202 Open Data for the Open Web
DPR202 Open Data for the Open WebDPR202 Open Data for the Open Web
DPR202 Open Data for the Open WebRonald Widha
 
iPad in the Enterprise
iPad in the EnterpriseiPad in the Enterprise
iPad in the EnterpriseRonald Widha
 

Plus de Ronald Widha (7)

DV01 Ten Things You Always Wanted to Know About Windows Azure But Were Afraid...
DV01 Ten Things You Always Wanted to Know About Windows Azure But Were Afraid...DV01 Ten Things You Always Wanted to Know About Windows Azure But Were Afraid...
DV01 Ten Things You Always Wanted to Know About Windows Azure But Were Afraid...
 
DV03 Smooth Migration to Windows Azure
DV03 Smooth Migration to Windows AzureDV03 Smooth Migration to Windows Azure
DV03 Smooth Migration to Windows Azure
 
Tech-out's Hack-a-day
Tech-out's Hack-a-dayTech-out's Hack-a-day
Tech-out's Hack-a-day
 
ASI202 Everything you want to know about Windows Azure but were afraid to ask
ASI202 Everything you want to know about Windows Azure but were afraid to askASI202 Everything you want to know about Windows Azure but were afraid to ask
ASI202 Everything you want to know about Windows Azure but were afraid to ask
 
DPR202 Open Data for the Open Web
DPR202 Open Data for the Open WebDPR202 Open Data for the Open Web
DPR202 Open Data for the Open Web
 
iPad in the Enterprise
iPad in the EnterpriseiPad in the Enterprise
iPad in the Enterprise
 
Android
AndroidAndroid
Android
 

Dernier

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 

Dernier (20)

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 

Dev303 Leap In Productivity With Linq And Entity Framework 4

  • 1. Dev303: Leap Ahead in Productivity with LINQ & Entity Framework Ronald Widha @RonaldWidhaTeam Lead Infusion Development
  • 2. Required Slide Complete an evaluation on CommNet and enter to win an HTC HD2!
  • 3. Agenda Pattern #1: Smart Client Pattern #2: 3 Tier Architecture Domain Driven Design Pattern #3: Domain Modelling Entity Data Model Entity Framework 4 Entity Framework 4 cool features (POCO, code only)
  • 4. Presentation Tier Data Smart Client
  • 5. Presentation Tier Business Data 3 Tier Architecture
  • 6. Demo: RAD and 3 Tier
  • 7. Domain Driven Design “an approach to developing software for complex needs by deeply connecting the implementation to an evolving model of the core business concepts.”
  • 8. Domain Driven Design Tackling complexity How: Talk to the business! Focus on the core business domain Design system based on a model
  • 9. The concept Entity & Value Objects Aggregate Roots Repositories Value Objects Value Objects Repository Aggregate Root Entity Entity Value Objects
  • 10. Keep it in sync with reality Business rules change: REFACTOR! Names change: REFACTOR!
  • 11. Presentation Tier Business Data Domain Models
  • 12. Linq to Sql Isn’t flexible enough for domain modelling 1-1 table mapping Table per Hierarchy No provider model Awesome for data access
  • 13. Entity Data Model An abstract conceptual model of data Based on Entity Relationship Model by Dr. Peter Chen (1976) Entities and Relationships Entity types Association types Navigation properties Sounds familiar??
  • 14. The Entity Framework 4 The next layer up in the ADO.Net stack First product to implement EDM Entity Data Model design tools Strongly typed LINQ access Declarative mapping to the database The next version to Entity Framework 1 from .Net 3.5 Available in .Net 4.0
  • 15. Demo: Domain Driven approach using Entity Framework
  • 16. Full control Just basic POCO: Plain Old CLR Objects Persistence Ignorance Turn off code generation from EDMX
  • 17. Demo: Domain Driven approach using Entity Framework POCO
  • 18. POCO and Other EF Features Different ways of mapping: Table per class, Table per type, Table per hierarchy Mapping with stored procedures Explicit Loading ObjectContext.LoadProperty(someObject, x => x.property) Lazy Loading Property as virtual Uses proxy instance at runtime
  • 19. Code-only design No model Metadata is inferred from classes Convention by Default Configuration Tweak configuration Create database at runtime
  • 20. Last Notes Don’t take the demo as best practice There are a lot more to Domain Driven Design that what’s shown here There are a lot more we can do to improve the demo code (Unit of work!) EF4 is perfect to enable Domain Driven approach
  • 22. Required Slide Speakers, TechEd 2010 is not producing a DVD. Please announce that attendees can access session recordings at TechEd Online. www.microsoft.com/teched Sessions On-Demand & Community www.microsoft.com/learning Microsoft Certification & Training Resources http://microsoft.com/technet Resources for IT Professionals Twitter @RonaldWidha http://blogs.msdn.com/adonet/ Resources for Developers Resources

Notes de l'éditeur

  1. Hi My name is Ronald Widha, team lead, infusionTwitterPlease don’t forget to fill up the assessment sheet, I’d love your feedback, especially praisesWelcome to “Leap Ahead in Productivity with Linq & Entity Framework”This a 300 level (advanced) talk, which assume you have some knowledge on entity framework, and general data access patterns
  2. So I’m sure all of you have built applications which interacts with database beforeSo leap in productivityHow can you be more productive than thisPerfect for rapid application developmentBut is it really productive?Productivity to me is more than just starting fastBut also to keep the same pace as the project goes more and more complex
  3. You have heard thisPresentation tierBusiness tier: these managers and services focused on the use cases. The implementation of the methods are normally calls to the data tierData tier: which in turn talks to the infrastructureIt’s data centric applicationA smart guy name Martin Fowler calls this: Transaction scripts.Because the business tier consists of transactional procedural script
  4. Each of the managers are reusableObject oriented? Yes Manager/Services are objectsWe have the data encapsulated as objectsBut why isn’t the behaviors of the object get attached to the object itself.For e.g I want to be able to say ron.friends.add(photographer)Without the behavior, photographer camera objects are just data wrappersWhat’s wrong with that?Throughout time, as business rules gets more complicated, these rules will be scattered everywhereAgain, our focus is to get productivity by Managing complexity
  5. What is it?2 books talks about this: Martin Fowler introduced the concept in his bookEric Evans covers the detail on How domain modelling can and should be done
  6. Tackling complexityHow?Talk to the businessGet the core business domain knowledge and apply that to the design of your applicationTry and get rid of any impedance mismatch between how the business view a problem,With how we the engineers solve the problem
  7. So again we want to focus on the domain. So we look for ways to represent these concepts in our system designEntity: an object in the domain model that is identified by its id. E.g same name, different id, different personValue objects: an object that doesn’t have any ID, and solely identified by its characteristics e.g if 2 address objects are the sameRepositories: a way to retreive entitiesAggregate roots: We want to be able to navigate from one entity to the nextPhotographer.cameras iterate through all the cameras owned by the photographerthe root entity where everything else is related to. The only one that has repositoryI have an address, I have a job, I’m speaking in a conference. Therefore I’m the aggregate root
  8. UI, Business Tier, Data AccessDomain Objects business objects with have behaviors You should be able to navigate from one domain objects to another by accessing its propertiesIt’s no longer data centric, you care about the business concepts. The domain knowledge
  9. 1-1 table mapping: doesn’t provide a flexible domain modellingCan’t hide the join table for the many to many relationshipOnce you have inheritance, it gets even trickier, linq to sql only support table per hierarchyAll that parent, child objects need to be stored into 1 tableNo provider model: if you don’t use sql server, you’re out of luckIt’s excellent tool for writng data centric application, but when you’re doing domain modell, you’re starting to push it to its limitsAnd if you don’t use any object relational mapping framework like linq to sql, and use t-sql, boy, it’s hard!-------Abstract concept above the data: entityRing a bell? Entities?It has relationshipsIt has navigation properties.What does that mean: you can navigate from parent entity to the childIf I want to get my camera’s manufacturer name, I don’t do inner joins between relational tableI don’t write queries using linq with where clausesWith navigation properties: Photographer.camera.manufacturer.name
  10. - Next layer up above data- It implements the Entity Data Model concept, which is compatible with Domain Driven mentalityIt has full design tools, and the experience is as rich as Linq to SQLIt has linq capabilitiesCan handle different kinds of mappings to the database, not just 1-1You can hide that join table if you wanted toYou can have differnet kinds of inheritance modelTable per hierarchy, table per type, table per classIf you want to know more you can talk to me afterwards at the speakers lounge
  11. At this point you might ask what is the difference between Entity Framework and Linq to SQLYes you can have more flexible mapping, but it’s still tightly coupled right?
  12. So this is the cool thing, unlike linq to sql, the class is all in your control.You can create Entities using just POCO: Plain Old CLR objects, in other words: normal .net object without any framework specific base classesThis is also known as Persistence IgnoranceEntities should not know about the infrastructure/databaseIt is just a domain model and that is it. Nothing more.The idea is, you should be able to switch between Entity Framework to any other data access technology if you want to.How to do that, turn off the code generationSo you have full control over the classThe mapping between the object and the EDMX will be based on conventionIt tries to match the property name with the model namePOCO Generatorhttp://visualstudiogallery.msdn.microsoft.com/en-us/23df0450-5677-4926-96cc-173d02752313
  13. Just like linq to sql, you can force to fetch related objects manually for optimizationJust like linq to sql, you can also leave it up to query related objects as it neededLoading the photographer class, will not have to load all the cameras until they are neededAll you have to do is mark the properties as virtualThe way it works, it replaces the property with a proxy class at runtimeSimilar way to how Nhibernate does it.Custom mapping, mapping with stored proc
  14. Before we end the session, I want you to check out the code only designIf you’re a hardcore code junky like me, and don’t like using the mouseDon’t care about the database and want to fully ignore the persistence layerEverything is convention basedIt uses the name of the property and match it with the column nameYou can tweak it as you go alongOn runtime you can check if the database existIf it’s not,You can just generate the database from the classA similar approach to Azure storage approach (for those who attended Tuesday’s session of Windows Azure). Check if table exist, create if it doesn’t
  15. Access session recordings at tech ed onlineMore videos about entity frameworkPDC09 walkthrough upcoming Entity Framework 4 featuresTwitterDon’t forget to fill up your Evaluation sheet