SlideShare una empresa de Scribd logo
1 de 43
Descargar para leer sin conexión
Real-world Entity Framework

Llewellyn Falco – A Developer’s Developer
Lynn Langit – A DBA and more
Agenda

          Query

          Save

         Patterns
What is Entity Framework 4?
Object Relational Mapper (ORM)
•Included in .NET 4.0
•Developers write .NET code
    • using LINQ
    • generate database access
      code
Generating a Model

DEMO - startING with EF
What did we just do?
• Created a new project in Visual Studio
• Added a new ADO.NET Entity Model
• Generated a model from a database
• Reviewed the generated model
  diagram
• Created an ObjectContext
Programmatically access data by…

ADO.NET             Entity Framework
• Custom DAO        • Complete DAO
• T-SQL             • LINQ
Agenda




         Query
Real-World Problem #1 - Report
• Report for customer ‘Lynn’
• Sent orders
    # 54, #63, #57
• Partially sent orders
    #82: awaiting shoes, pants
    #92: awaiting gloves
• Unshipped orders
    #93 6 items
    #97 5 items
The Report T-SQL
Current Practices- Life without Entity Framework

Code Demo
Report with Entity Framework

Code Demo
Using EF – Writing a Query using LINQ
Compare Extracting Data
Mapping Relationships
 Id   Name Id Number Total Customerid

                         ADO
                                .Ne
                                   t
                                        Customer
Customer                                Id      Invoice
Id      Invoice                         Name    Id
Name    Id                                      Number
        Number             EF                   Total
        Total                                   CustomerId
        CustomerId
Report with Entity Framework

Code Demo - Continued
Smart Objects
               Customer
               GetShipped
               GetUnshipped
               GetPartiallyShiped
 Invoice
 IsShipped
 IsUnshipped
 IsPartiallyShiped
Looking at the T-SQL Generated by EF
•   Use SQL Profiler
•   Create a trace
•   Filter for
    Application:
•   EntityFramework
The N+1 Problem


       1 + 1 + 5 =7
     Customer   Customers   Invoices    Trips to
                 Invoices     Items    Database
More about Loading – Why Lazy Loading
• Lazy is Good and Easy, but
    Lazy isn’t always efficient
    Lazy is always correct
    Sometimes better to use selective eager loading
• Syntax – use .Include("invoices.invoiceItems”)
• More about – lazy loading - here
Constrained Eager Loading

Code Demo
Agenda




         Save
Real-world Problem #2 – CRUD operations
      Warehouse              Process        Load / Create
       Report                Shipment         Customer


                            Load / Create   Load / Create
       Action
                             Invoice Item      Invoice

                  Shipped
Cancelled


      Remove            Set Item
       Item             Shipped
Warehouse
Processing

Code Demo
Using EF – Adding Data using LINQ
With Entity Framework…
• Simplified/ Reduced data access code
    Save Encapsulates
       Delete
       Insert
       Update
       Key relationship
       Order of operations
       Transactions
• Prevents Most SQL Injection
    Sanitizes database inputs
SQL Injection and Entity Framework




    “Little Bobby Tables”
Agenda




         Patterns
Data Usage Patterns   Load Model
                      Manipulate Model
                      Save Model
    Common
                      Preferred
Modularity

Code Demo
Making Entity Framework Testable
 Old Way                   New Way - Testable
 DoSomething()             DoSomething()
 2)Get Data                2)Load Data
 3)Manipulate Data         3)DoSomething(Data)
 4)Render Data

                                         Load()
                                         2)Get Data

                     DoSomething(Data)
                     2)Manipulate Data
                     3)Render Data
Testing Loaders

Code Demo
Common Usage Pattern

                             MyProject.Views     Load Model
      MyProject.Controller
                                                 Manipulate Model
                                                 Save Model

     MyProject.Business
                               MyProject.Rules




     MyProject.Processes
Common Usage Pattern

                             MyProject.Views     Load Model
      MyProject.Controller
                                                 Manipulate Model
                                                 Save Model

     MyProject.Business
                               MyProject.Rules




     MyProject.Processes     MyProject.Loaders
Stored Procedures
•   Security
•   Reduced Access
•   Performance
•   Modularity
•   Containment
•   Maintainability
Mapping Stored Procedures to EF Models
ORM to DB should be 1-1
• Complex mappings obscure the database




                      ?
                      =
Existing Database Problems are
Amplified
•   Primary Keys
•   Wide Tables
•   Bad Names
•   Dead Columns
“Next Steps” for Attendees
• Use Entity Framework
    Write less CRUD code
    Protect against SQL Injection
    Master LINQ
• Use patterns / best practices with EF
    i.e. Loader pattern
    Modularity for testability (mocking)
• Map EF as closely as possible to the database
    Map 1-to-1
    Fix design issues at the database level first
More about learning LINQ – using Koans
• 28 progressive examples to help you learn LINQ
• LinqKoans.codeplex.com
Resources for Attendees
• EF team blog – here

• Julie Lehrman book - here

• Testing EF – video coming soon
   On ApprovalTests YouTube playlist - here

   www.ApprovalTests.com
Related Session(s)
http://www.devteach.com/Schedule.aspx
•SQL361 - Query Tuning Tips for SQL Server
TeachingKidsProgramming.org
 Do a Recipe  Teach a Kid (Ages 10 ++)
 SmallBasic or Java  Free Courseware (recipes)
Contact Information

                  @LlewellynFalco
                  www.ApprovalTests.com

                      @LynnLangit
                      www.LynnLangit.com

Más contenido relacionado

La actualidad más candente

Implementing DDD with C#
Implementing DDD with C#Implementing DDD with C#
Implementing DDD with C#Pascal Laurin
 
Clean architecture with asp.net core by Ardalis
Clean architecture with asp.net core by ArdalisClean architecture with asp.net core by Ardalis
Clean architecture with asp.net core by ArdalisSteven Smith
 
Applying Domain-Driven Design to craft Rich Domain Models
Applying Domain-Driven Design to craft Rich Domain ModelsApplying Domain-Driven Design to craft Rich Domain Models
Applying Domain-Driven Design to craft Rich Domain ModelsAlexander van Trijffel
 
AppliFire Blue Print Design Guidelines
AppliFire Blue Print Design GuidelinesAppliFire Blue Print Design Guidelines
AppliFire Blue Print Design GuidelinesAppliFire Platform
 
JavaScript Frameworks and Java EE – A Great Match
JavaScript Frameworks and Java EE – A Great MatchJavaScript Frameworks and Java EE – A Great Match
JavaScript Frameworks and Java EE – A Great MatchReza Rahman
 
Entity Framework - Object Services
Entity Framework -  Object ServicesEntity Framework -  Object Services
Entity Framework - Object ServicesEyal Vardi
 
Real World Experience: Integrating DB2 with XPages
Real World Experience: Integrating DB2 with XPagesReal World Experience: Integrating DB2 with XPages
Real World Experience: Integrating DB2 with XPagesSteve_Zavocki
 
Architecture Principles CodeStock
Architecture Principles CodeStock Architecture Principles CodeStock
Architecture Principles CodeStock Steve Barbour
 
2010-07-19_rails_tdd_week1
2010-07-19_rails_tdd_week12010-07-19_rails_tdd_week1
2010-07-19_rails_tdd_week1Wolfram Arnold
 
Stuff About CQRS
Stuff About CQRSStuff About CQRS
Stuff About CQRSthinkddd
 
Clean architecture with ddd layering in php
Clean architecture with ddd layering in phpClean architecture with ddd layering in php
Clean architecture with ddd layering in phpLeonardo Proietti
 
CQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architectureCQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architectureThomas Jaskula
 
Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...
Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...
Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...Theo Jungeblut
 
Introductions to Online Machine Learning Algorithms
Introductions to Online Machine Learning AlgorithmsIntroductions to Online Machine Learning Algorithms
Introductions to Online Machine Learning AlgorithmsDataWorks Summit
 
Crafted Design - Sandro Mancuso
Crafted Design - Sandro MancusoCrafted Design - Sandro Mancuso
Crafted Design - Sandro MancusoJAXLondon2014
 
Hibernate in XPages
Hibernate in XPagesHibernate in XPages
Hibernate in XPagesToby Samples
 
Api chaining(tm)
Api chaining(tm)Api chaining(tm)
Api chaining(tm)Owen Rubel
 

La actualidad más candente (17)

Implementing DDD with C#
Implementing DDD with C#Implementing DDD with C#
Implementing DDD with C#
 
Clean architecture with asp.net core by Ardalis
Clean architecture with asp.net core by ArdalisClean architecture with asp.net core by Ardalis
Clean architecture with asp.net core by Ardalis
 
Applying Domain-Driven Design to craft Rich Domain Models
Applying Domain-Driven Design to craft Rich Domain ModelsApplying Domain-Driven Design to craft Rich Domain Models
Applying Domain-Driven Design to craft Rich Domain Models
 
AppliFire Blue Print Design Guidelines
AppliFire Blue Print Design GuidelinesAppliFire Blue Print Design Guidelines
AppliFire Blue Print Design Guidelines
 
JavaScript Frameworks and Java EE – A Great Match
JavaScript Frameworks and Java EE – A Great MatchJavaScript Frameworks and Java EE – A Great Match
JavaScript Frameworks and Java EE – A Great Match
 
Entity Framework - Object Services
Entity Framework -  Object ServicesEntity Framework -  Object Services
Entity Framework - Object Services
 
Real World Experience: Integrating DB2 with XPages
Real World Experience: Integrating DB2 with XPagesReal World Experience: Integrating DB2 with XPages
Real World Experience: Integrating DB2 with XPages
 
Architecture Principles CodeStock
Architecture Principles CodeStock Architecture Principles CodeStock
Architecture Principles CodeStock
 
2010-07-19_rails_tdd_week1
2010-07-19_rails_tdd_week12010-07-19_rails_tdd_week1
2010-07-19_rails_tdd_week1
 
Stuff About CQRS
Stuff About CQRSStuff About CQRS
Stuff About CQRS
 
Clean architecture with ddd layering in php
Clean architecture with ddd layering in phpClean architecture with ddd layering in php
Clean architecture with ddd layering in php
 
CQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architectureCQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architecture
 
Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...
Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...
Clean Code III - Software Craftsmanship at SoCal Code Camp San Diego (07/27/2...
 
Introductions to Online Machine Learning Algorithms
Introductions to Online Machine Learning AlgorithmsIntroductions to Online Machine Learning Algorithms
Introductions to Online Machine Learning Algorithms
 
Crafted Design - Sandro Mancuso
Crafted Design - Sandro MancusoCrafted Design - Sandro Mancuso
Crafted Design - Sandro Mancuso
 
Hibernate in XPages
Hibernate in XPagesHibernate in XPages
Hibernate in XPages
 
Api chaining(tm)
Api chaining(tm)Api chaining(tm)
Api chaining(tm)
 

Similar a Real-world Entity Framework

Lessons Learned Replatforming A Large Machine Learning Application To Apache ...
Lessons Learned Replatforming A Large Machine Learning Application To Apache ...Lessons Learned Replatforming A Large Machine Learning Application To Apache ...
Lessons Learned Replatforming A Large Machine Learning Application To Apache ...Databricks
 
Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts weili_at_slideshare
 
Application Architecture April 2014
Application Architecture April 2014Application Architecture April 2014
Application Architecture April 2014Lars-Erik Kindblad
 
Implementing Test Automation in Agile Projects
Implementing Test Automation in Agile ProjectsImplementing Test Automation in Agile Projects
Implementing Test Automation in Agile ProjectsMichael Palotas
 
Session 2: SQL Server 2012 with Christian Malbeuf
Session 2: SQL Server 2012 with Christian MalbeufSession 2: SQL Server 2012 with Christian Malbeuf
Session 2: SQL Server 2012 with Christian MalbeufCTE Solutions Inc.
 
DevOps for Machine Learning overview en-us
DevOps for Machine Learning overview en-usDevOps for Machine Learning overview en-us
DevOps for Machine Learning overview en-useltonrodriguez11
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO DevsWO Community
 
Implementing Test Automation in Agile Projects
Implementing Test Automation in Agile ProjectsImplementing Test Automation in Agile Projects
Implementing Test Automation in Agile ProjectsDominik Dary
 
BGOUG "Agile Data: revolutionizing database cloning'
BGOUG  "Agile Data: revolutionizing database cloning'BGOUG  "Agile Data: revolutionizing database cloning'
BGOUG "Agile Data: revolutionizing database cloning'Kyle Hailey
 
Introductie Visual Studio ALM 2012
Introductie Visual Studio ALM 2012Introductie Visual Studio ALM 2012
Introductie Visual Studio ALM 2012Delta-N
 
AngularJS - Architecture decisions in a large project 
AngularJS - Architecture decisionsin a large project AngularJS - Architecture decisionsin a large project 
AngularJS - Architecture decisions in a large project Elad Hirsch
 
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...Malin Weiss
 
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...Speedment, Inc.
 
Run Your Oracle BI QA Cycles More Effectively
Run Your Oracle BI QA Cycles More EffectivelyRun Your Oracle BI QA Cycles More Effectively
Run Your Oracle BI QA Cycles More EffectivelyKPI Partners
 
SoCal Code Camp 2011 - ASP.NET 4.5
SoCal Code Camp 2011 - ASP.NET 4.5SoCal Code Camp 2011 - ASP.NET 4.5
SoCal Code Camp 2011 - ASP.NET 4.5Jon Galloway
 

Similar a Real-world Entity Framework (20)

70487.pdf
70487.pdf70487.pdf
70487.pdf
 
Lessons Learned Replatforming A Large Machine Learning Application To Apache ...
Lessons Learned Replatforming A Large Machine Learning Application To Apache ...Lessons Learned Replatforming A Large Machine Learning Application To Apache ...
Lessons Learned Replatforming A Large Machine Learning Application To Apache ...
 
Hybernat and structs, spring classes in mumbai
Hybernat and structs, spring classes in mumbaiHybernat and structs, spring classes in mumbai
Hybernat and structs, spring classes in mumbai
 
Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts
 
Application Architecture April 2014
Application Architecture April 2014Application Architecture April 2014
Application Architecture April 2014
 
Implementing Test Automation in Agile Projects
Implementing Test Automation in Agile ProjectsImplementing Test Automation in Agile Projects
Implementing Test Automation in Agile Projects
 
Session 2: SQL Server 2012 with Christian Malbeuf
Session 2: SQL Server 2012 with Christian MalbeufSession 2: SQL Server 2012 with Christian Malbeuf
Session 2: SQL Server 2012 with Christian Malbeuf
 
Ow
OwOw
Ow
 
DevOps for Machine Learning overview en-us
DevOps for Machine Learning overview en-usDevOps for Machine Learning overview en-us
DevOps for Machine Learning overview en-us
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO Devs
 
Implementing Test Automation in Agile Projects
Implementing Test Automation in Agile ProjectsImplementing Test Automation in Agile Projects
Implementing Test Automation in Agile Projects
 
BGOUG "Agile Data: revolutionizing database cloning'
BGOUG  "Agile Data: revolutionizing database cloning'BGOUG  "Agile Data: revolutionizing database cloning'
BGOUG "Agile Data: revolutionizing database cloning'
 
Application Architecture
Application ArchitectureApplication Architecture
Application Architecture
 
Introductie Visual Studio ALM 2012
Introductie Visual Studio ALM 2012Introductie Visual Studio ALM 2012
Introductie Visual Studio ALM 2012
 
Introductie Visual Studio ALM 2012
Introductie Visual Studio ALM 2012Introductie Visual Studio ALM 2012
Introductie Visual Studio ALM 2012
 
AngularJS - Architecture decisions in a large project 
AngularJS - Architecture decisionsin a large project AngularJS - Architecture decisionsin a large project 
AngularJS - Architecture decisions in a large project 
 
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
 
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
 
Run Your Oracle BI QA Cycles More Effectively
Run Your Oracle BI QA Cycles More EffectivelyRun Your Oracle BI QA Cycles More Effectively
Run Your Oracle BI QA Cycles More Effectively
 
SoCal Code Camp 2011 - ASP.NET 4.5
SoCal Code Camp 2011 - ASP.NET 4.5SoCal Code Camp 2011 - ASP.NET 4.5
SoCal Code Camp 2011 - ASP.NET 4.5
 

Más de Lynn Langit

VariantSpark on AWS
VariantSpark on AWSVariantSpark on AWS
VariantSpark on AWSLynn Langit
 
Serverless Architectures
Serverless ArchitecturesServerless Architectures
Serverless ArchitecturesLynn Langit
 
10+ Years of Teaching Kids Programming
10+ Years of Teaching Kids Programming10+ Years of Teaching Kids Programming
10+ Years of Teaching Kids ProgrammingLynn Langit
 
Blastn plus jupyter on Docker
Blastn plus jupyter on DockerBlastn plus jupyter on Docker
Blastn plus jupyter on DockerLynn Langit
 
Testing in Ballerina Language
Testing in Ballerina LanguageTesting in Ballerina Language
Testing in Ballerina LanguageLynn Langit
 
Teaching Kids to create Alexa Skills
Teaching Kids to create Alexa SkillsTeaching Kids to create Alexa Skills
Teaching Kids to create Alexa SkillsLynn Langit
 
Understanding Jupyter notebooks using bioinformatics examples
Understanding Jupyter notebooks using bioinformatics examplesUnderstanding Jupyter notebooks using bioinformatics examples
Understanding Jupyter notebooks using bioinformatics examplesLynn Langit
 
Genome-scale Big Data Pipelines
Genome-scale Big Data PipelinesGenome-scale Big Data Pipelines
Genome-scale Big Data PipelinesLynn Langit
 
Teaching Kids Programming
Teaching Kids ProgrammingTeaching Kids Programming
Teaching Kids ProgrammingLynn Langit
 
Serverless Reality
Serverless RealityServerless Reality
Serverless RealityLynn Langit
 
Genomic Scale Big Data Pipelines
Genomic Scale Big Data PipelinesGenomic Scale Big Data Pipelines
Genomic Scale Big Data PipelinesLynn Langit
 
VariantSpark - a Spark library for genomics
VariantSpark - a Spark library for genomicsVariantSpark - a Spark library for genomics
VariantSpark - a Spark library for genomicsLynn Langit
 
Bioinformatics Data Pipelines built by CSIRO on AWS
Bioinformatics Data Pipelines built by CSIRO on AWSBioinformatics Data Pipelines built by CSIRO on AWS
Bioinformatics Data Pipelines built by CSIRO on AWSLynn Langit
 
Serverless Reality
Serverless RealityServerless Reality
Serverless RealityLynn Langit
 
Beyond Relational
Beyond RelationalBeyond Relational
Beyond RelationalLynn Langit
 
New AWS Services for Bioinformatics
New AWS Services for BioinformaticsNew AWS Services for Bioinformatics
New AWS Services for BioinformaticsLynn Langit
 
Google Cloud and Data Pipeline Patterns
Google Cloud and Data Pipeline PatternsGoogle Cloud and Data Pipeline Patterns
Google Cloud and Data Pipeline PatternsLynn Langit
 
Scaling Galaxy on Google Cloud Platform
Scaling Galaxy on Google Cloud PlatformScaling Galaxy on Google Cloud Platform
Scaling Galaxy on Google Cloud PlatformLynn Langit
 

Más de Lynn Langit (20)

VariantSpark on AWS
VariantSpark on AWSVariantSpark on AWS
VariantSpark on AWS
 
Serverless Architectures
Serverless ArchitecturesServerless Architectures
Serverless Architectures
 
10+ Years of Teaching Kids Programming
10+ Years of Teaching Kids Programming10+ Years of Teaching Kids Programming
10+ Years of Teaching Kids Programming
 
Blastn plus jupyter on Docker
Blastn plus jupyter on DockerBlastn plus jupyter on Docker
Blastn plus jupyter on Docker
 
Testing in Ballerina Language
Testing in Ballerina LanguageTesting in Ballerina Language
Testing in Ballerina Language
 
Teaching Kids to create Alexa Skills
Teaching Kids to create Alexa SkillsTeaching Kids to create Alexa Skills
Teaching Kids to create Alexa Skills
 
Practical cloud
Practical cloudPractical cloud
Practical cloud
 
Understanding Jupyter notebooks using bioinformatics examples
Understanding Jupyter notebooks using bioinformatics examplesUnderstanding Jupyter notebooks using bioinformatics examples
Understanding Jupyter notebooks using bioinformatics examples
 
Genome-scale Big Data Pipelines
Genome-scale Big Data PipelinesGenome-scale Big Data Pipelines
Genome-scale Big Data Pipelines
 
Teaching Kids Programming
Teaching Kids ProgrammingTeaching Kids Programming
Teaching Kids Programming
 
Practical Cloud
Practical CloudPractical Cloud
Practical Cloud
 
Serverless Reality
Serverless RealityServerless Reality
Serverless Reality
 
Genomic Scale Big Data Pipelines
Genomic Scale Big Data PipelinesGenomic Scale Big Data Pipelines
Genomic Scale Big Data Pipelines
 
VariantSpark - a Spark library for genomics
VariantSpark - a Spark library for genomicsVariantSpark - a Spark library for genomics
VariantSpark - a Spark library for genomics
 
Bioinformatics Data Pipelines built by CSIRO on AWS
Bioinformatics Data Pipelines built by CSIRO on AWSBioinformatics Data Pipelines built by CSIRO on AWS
Bioinformatics Data Pipelines built by CSIRO on AWS
 
Serverless Reality
Serverless RealityServerless Reality
Serverless Reality
 
Beyond Relational
Beyond RelationalBeyond Relational
Beyond Relational
 
New AWS Services for Bioinformatics
New AWS Services for BioinformaticsNew AWS Services for Bioinformatics
New AWS Services for Bioinformatics
 
Google Cloud and Data Pipeline Patterns
Google Cloud and Data Pipeline PatternsGoogle Cloud and Data Pipeline Patterns
Google Cloud and Data Pipeline Patterns
 
Scaling Galaxy on Google Cloud Platform
Scaling Galaxy on Google Cloud PlatformScaling Galaxy on Google Cloud Platform
Scaling Galaxy on Google Cloud Platform
 

Último

Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFMichael Gough
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfAarwolf Industries LLC
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxAna-Maria Mihalceanu
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Karmanjay Verma
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 

Último (20)

Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDF
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdf
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 

Real-world Entity Framework

  • 1. Real-world Entity Framework Llewellyn Falco – A Developer’s Developer Lynn Langit – A DBA and more
  • 2. Agenda Query Save Patterns
  • 3. What is Entity Framework 4? Object Relational Mapper (ORM) •Included in .NET 4.0 •Developers write .NET code • using LINQ • generate database access code
  • 4. Generating a Model DEMO - startING with EF
  • 5. What did we just do? • Created a new project in Visual Studio • Added a new ADO.NET Entity Model • Generated a model from a database • Reviewed the generated model diagram • Created an ObjectContext
  • 6. Programmatically access data by… ADO.NET Entity Framework • Custom DAO • Complete DAO • T-SQL • LINQ
  • 7. Agenda Query
  • 8. Real-World Problem #1 - Report • Report for customer ‘Lynn’ • Sent orders  # 54, #63, #57 • Partially sent orders  #82: awaiting shoes, pants  #92: awaiting gloves • Unshipped orders  #93 6 items  #97 5 items
  • 10. Current Practices- Life without Entity Framework Code Demo
  • 11. Report with Entity Framework Code Demo
  • 12. Using EF – Writing a Query using LINQ
  • 14. Mapping Relationships Id Name Id Number Total Customerid ADO .Ne t Customer Customer Id Invoice Id Invoice Name Id Name Id Number Number EF Total Total CustomerId CustomerId
  • 15. Report with Entity Framework Code Demo - Continued
  • 16. Smart Objects Customer GetShipped GetUnshipped GetPartiallyShiped Invoice IsShipped IsUnshipped IsPartiallyShiped
  • 17. Looking at the T-SQL Generated by EF • Use SQL Profiler • Create a trace • Filter for Application: • EntityFramework
  • 18. The N+1 Problem 1 + 1 + 5 =7 Customer Customers Invoices Trips to Invoices Items Database
  • 19. More about Loading – Why Lazy Loading • Lazy is Good and Easy, but  Lazy isn’t always efficient  Lazy is always correct  Sometimes better to use selective eager loading • Syntax – use .Include("invoices.invoiceItems”) • More about – lazy loading - here
  • 21. Agenda Save
  • 22. Real-world Problem #2 – CRUD operations Warehouse Process Load / Create Report Shipment Customer Load / Create Load / Create Action Invoice Item Invoice Shipped Cancelled Remove Set Item Item Shipped
  • 24. Using EF – Adding Data using LINQ
  • 25. With Entity Framework… • Simplified/ Reduced data access code  Save Encapsulates  Delete  Insert  Update  Key relationship  Order of operations  Transactions • Prevents Most SQL Injection  Sanitizes database inputs
  • 26. SQL Injection and Entity Framework “Little Bobby Tables”
  • 27. Agenda Patterns
  • 28. Data Usage Patterns Load Model Manipulate Model Save Model Common Preferred
  • 30. Making Entity Framework Testable Old Way New Way - Testable DoSomething() DoSomething() 2)Get Data 2)Load Data 3)Manipulate Data 3)DoSomething(Data) 4)Render Data Load() 2)Get Data DoSomething(Data) 2)Manipulate Data 3)Render Data
  • 32. Common Usage Pattern MyProject.Views Load Model MyProject.Controller Manipulate Model Save Model MyProject.Business MyProject.Rules MyProject.Processes
  • 33. Common Usage Pattern MyProject.Views Load Model MyProject.Controller Manipulate Model Save Model MyProject.Business MyProject.Rules MyProject.Processes MyProject.Loaders
  • 34. Stored Procedures • Security • Reduced Access • Performance • Modularity • Containment • Maintainability
  • 36. ORM to DB should be 1-1 • Complex mappings obscure the database ? =
  • 37. Existing Database Problems are Amplified • Primary Keys • Wide Tables • Bad Names • Dead Columns
  • 38. “Next Steps” for Attendees • Use Entity Framework  Write less CRUD code  Protect against SQL Injection  Master LINQ • Use patterns / best practices with EF  i.e. Loader pattern  Modularity for testability (mocking) • Map EF as closely as possible to the database  Map 1-to-1  Fix design issues at the database level first
  • 39. More about learning LINQ – using Koans • 28 progressive examples to help you learn LINQ • LinqKoans.codeplex.com
  • 40. Resources for Attendees • EF team blog – here • Julie Lehrman book - here • Testing EF – video coming soon  On ApprovalTests YouTube playlist - here  www.ApprovalTests.com
  • 42. TeachingKidsProgramming.org Do a Recipe  Teach a Kid (Ages 10 ++) SmallBasic or Java  Free Courseware (recipes)
  • 43. Contact Information @LlewellynFalco www.ApprovalTests.com @LynnLangit www.LynnLangit.com

Notas del editor

  1. Abstract -  Entity framework (an ORM) is fast becoming the way that developers are accessing SqlServer Databases. The meeting of the Developer mind and the DBA mind has long been “contentious”. In this session Lynn will speak for the DBA’s and Llewellyn will speak for the Developers. Are there Best Practices they both can agree on? Maybe there are at least some Worst Practices they can both agree to avoid? Listen in and find out…
  2. http://msdn.microsoft.com/en-us/data/aa937723 Picture credit - http://www.theserverside.net/tt/articles/showarticle.tss?id=IntroducingEntityFramework&asrc=EM_NLN_1469313&uid=5982486
  3. Using other tools to profile – Julie Lehrman MSDN Article - http://msdn.microsoft.com/en-us/magazine/gg490349.aspx
  4. MSDN lazy loading - http://msdn.microsoft.com/en-us/library/bb896272.aspx
  5. What is a Loader Single Interface (Delegate) found in ApprovalUtilities Façade Pattern T Load();
  6. MSDN on how to map - http://msdn.microsoft.com/en-us/library/bb896279.aspx
  7. About Mapping (MSDN) - http://msdn.microsoft.com/en-us/library/bb399232.aspx
  8. Image credit - http://hibou-chatte.blogspot.com/2011/01/please-shop-at-boyds.html
  9. http://www.monafoundation.org/project/Teaching-Kids-Programming/22
  10. Both