SlideShare a Scribd company logo
1 of 29
TGZ.NET
                                               14 Dec 2011




                Entity Framework
                     „I am just a teenanger”

Marcin Dembowski
.NET Developer @ Goyello
Agenda

• We have a database - DbFirst
  • The long history
  • How it works
• Model and Code First
• Plans for future
PROBLEM:   We want to have access from code
ADO.NET
Entity Framework
The Hist(e)ory of Ms EF
•   EDM evolved from E- Relation Modelling (ERM) 1976
•   Chaos ADO.NET
•   Announced at TechED TechED in 2006
•   July 2008 – First release – vs 2008 SP1 .NET 3.5 SP1
•   April 2010 – Second release
•   April 2011 – EF 4.1 with CodeFirst
•   July 2011 – EF 4.1 Update 1 and CTP
•   November 2011 – EF 4.2 – nothing special 
EF – how it works ?

                Management, Tracking,
                   Relationships


             Entity SQL, some kind of facade


                     Our EDMX file

                    Our old ADO.NET

                     Real database
EDMX - metadata
<add name="MyContainer"                                             METADATA
        connectionString=„                            • The Calling Assembly
        metadata=res://*/MyEFM.csdl|                  • Referenced assemblies
                res://*/MyEFM.ssdl|                   • Assemblies in bin
                res://*/MyEFM.msl;
        provider=System.Data.SqlClient;
        provider connection string=&quot;data source=.R22008EXPRESS;
        attachdbfilename=|DataDirectory|RepairCompanyDatabase.mdf;
        integrated security=True;user instance=True;
        multipleactiveresultsets=True;App=EntityFramework&quot;"
        providerName="System.Data.EntityClient" />




NOTE: The Connection String
Inheritance Strategies
•   Table Per Hierarchy (TPH)
•   Table Per Type (TPT)
•   Table Per Concrete Type (TPC)
•   Hybrid Mappings
•   Entity Splitting
Table Per Hierarchy


• All properties in one table


• Additional discriminator column
PROS:    • No JOINS or UNIONS in SQL statements
          • Flat table



 CONS:    • Derived Properties must be nullable
          • Denormalized
          • Poor storage use – many empty fields




TIP:     Table Per Hierarchy (TPH)
Table Per Type


• All properties from base type in one table


• Additional properties in seperate tables
PROS:    • Application is easier to extend




CONS:    • Performance disadvantage
         • Uses JOINS
         • Query can be more complex than required*




TIP:    Table Per Type (TPT)
Table Per Concrete type


• All properties from each type in seperate table


• All tables share the same ID (PK)
PROS:    • Simple Query when querying for specific type




CONS:    • Performance issue when pulling from multiple tables
         • All keys have to be unique accros tables




TIP:    Table Per Concrete type (TPC)
ADO.NET
Entity Framework
EF vs. Other
Feature                                                                                   L2S       EF       NH
Eager and lazy loading configurable per relationship                                       N         N         Y
Good documentation                                                                         Y         Y        N
Easy logging                                                                               Y         N         Y
Mature                                                                                     -         N         Y
Configured by XML                                                                          N       Y/N        N*
Supports Enums                                                                                      N*         Y
Different database providers                                                               N         Y         Y




                                                             http://msdn.microsoft.com/en-us/library/cc853327.aspx
           http://blogs.msdn.com/b/adonet/archive/2008/03/27/ado-net-entity-framework-performance-comparison.aspx
PROS:          • Any next use is faster



CONS:          • First use can take some time

static readonly Func<MyDataModelContainer, int, IQueryable<Post>> compiledQuery




                                                                                  DEFINITION
    = CompiledQuery.Compile<MyDataModelContainer, int, IQueryable<Post>>(

(context,id) => from c in context.PostSet where c.UserId == id select c
);



var post = compiledQuery




                                                                                  USAGE
         .Invoke(context, 1)
         .FirstOrDefault();




TIP:        Use compiled query
PROS:      • Use this only when you will get some data (Lookup tables)



CONS:      • Any changes are not tracked




                                                                   PER ENTITY
 context.UserSet.MergeOption = MergeOption.NoTracking;
 context.PostSet.MergeOption = MergeOption.NoTracking;




TIP:       Set MergeOptions
PROS:        • Removes the n-select problem


CONS:        • Can fetch large data

 from c in context




                                                    STRINGS
         .PostSet
         .Include("PostComment")
         where c.UserId == id select c


 from c in context




                                                    EXPRESSION*
         .PostSet
         .Include(c => c.PostComment)
         where c.UserId == id select c




TIP:      Including related data (Immediate load)
PROS:         • Dynamic Queries
              • Named parameters

CONS:         • Type unsafe – it’s uses strings



var posts = context.PostSet
        .Where("it.Id > @id", new ObjectParameter("id", 1))




                                                                  STRINGS
        .OrderBy("it.Title")
        .Skip("it.Id", "@skip", new ObjectParameter("skip", 3))
        .Top("@limit", new ObjectParameter("limit", 5))




TIP:       Custom queries
SETTINGS
 context.ContextOptions.LazyLoadingEnabled = false;
 context.ContextOptions.ProxyCreationEnabled = false;




 public partial class Post {
   public virtual int Id { get; set; }
   public virtual string Title { get; set; }
   public virtual string Content { get; set; }
   …
   public virtual ICollection<PostComment> PostComment { .. }
 }




TIP:             Configure EF behaviour
PROS:           • When multiple times used SaveChanges()




dbContext.Database.Connection.Open()




                                                           SET
TIP:        Manage connections
• Allows to create TPT

       • Allows to create TPH
                                                a
       • Allows to create database generation script

       • Allows to create difference migration script
              http://visualstudiogallery.msdn.microsoft.com/df3541c3-d833-4b65-b942-989e7ec74c87




TOOL: Entity Framework Tool
ADO.NET
Entity Framework
Tracing

• ToTraceString()

• Tracing provider
http://bit.ly/b3AFXc

• SQL Profiler AnjLab SQL Profiler
http://bit.ly/9Igw78
To sum up…

• Entity Framework
  • Removes Linq 2 SQL – don’t* use L2S
  • Multiple database providers
  • Database/Model/Code First Design

• It’s not so perfect now
  • It’s like a teenanger …
  • Still digging into XML
  • Sometimes you have to use T-SQL instead eSQL
ADO.NET
 Entity Framework
                       Questions       ?
Join us : http://kariera.goyello.com
Thanks for your attention !

Entity Framework
Marcin Dembowski
•   Mail.To("marcin.dembowski")
          .At("goyello").Com()      blog.goyello.com
•   marcindembowski.wordpress.com
•   twitter.com/D3M80L              twitter.com/goyello


                                    facebook.com/goyello


                                    kariera.goyello.com

More Related Content

What's hot

Serialization/deserialization
Serialization/deserializationSerialization/deserialization
Serialization/deserializationYoung Alista
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryPray Desai
 
Java Serialization
Java SerializationJava Serialization
Java Serializationimypraz
 
Entity Framework: Code First and Magic Unicorns
Entity Framework: Code First and Magic UnicornsEntity Framework: Code First and Magic Unicorns
Entity Framework: Code First and Magic UnicornsRichie Rump
 
Sedna XML Database System: Internal Representation
Sedna XML Database System: Internal RepresentationSedna XML Database System: Internal Representation
Sedna XML Database System: Internal RepresentationIvan Shcheklein
 
Java Course 9: Networking and Reflection
Java Course 9: Networking and ReflectionJava Course 9: Networking and Reflection
Java Course 9: Networking and ReflectionAnton Keks
 
Hotsos 2013 - Creating Structure in Unstructured Data
Hotsos 2013 - Creating Structure in Unstructured DataHotsos 2013 - Creating Structure in Unstructured Data
Hotsos 2013 - Creating Structure in Unstructured DataMarco Gralike
 
Java Programming and J2ME: The Basics
Java Programming and J2ME: The BasicsJava Programming and J2ME: The Basics
Java Programming and J2ME: The Basicstosine
 
Java Serialization Deep Dive
Java Serialization Deep DiveJava Serialization Deep Dive
Java Serialization Deep DiveMartijn Dashorst
 
BGOUG 2012 - XML Index Strategies
BGOUG 2012 - XML Index StrategiesBGOUG 2012 - XML Index Strategies
BGOUG 2012 - XML Index StrategiesMarco Gralike
 
Serialization in .NET
Serialization in .NETSerialization in .NET
Serialization in .NETAbhi Arya
 
Easy Data Object Relational Mapping Tool
Easy Data Object Relational Mapping ToolEasy Data Object Relational Mapping Tool
Easy Data Object Relational Mapping ToolHasitha Guruge
 
Introduction to SQL Alchemy - SyPy June 2013
Introduction to SQL Alchemy - SyPy June 2013Introduction to SQL Alchemy - SyPy June 2013
Introduction to SQL Alchemy - SyPy June 2013Roger Barnes
 

What's hot (19)

Serialization/deserialization
Serialization/deserializationSerialization/deserialization
Serialization/deserialization
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
 
Java Serialization
Java SerializationJava Serialization
Java Serialization
 
Migrate
MigrateMigrate
Migrate
 
PostgreSQL - Case Study
PostgreSQL - Case StudyPostgreSQL - Case Study
PostgreSQL - Case Study
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
Entity Framework: Code First and Magic Unicorns
Entity Framework: Code First and Magic UnicornsEntity Framework: Code First and Magic Unicorns
Entity Framework: Code First and Magic Unicorns
 
Java full stack1
Java full stack1Java full stack1
Java full stack1
 
Sedna XML Database System: Internal Representation
Sedna XML Database System: Internal RepresentationSedna XML Database System: Internal Representation
Sedna XML Database System: Internal Representation
 
Java Course 9: Networking and Reflection
Java Course 9: Networking and ReflectionJava Course 9: Networking and Reflection
Java Course 9: Networking and Reflection
 
Hotsos 2013 - Creating Structure in Unstructured Data
Hotsos 2013 - Creating Structure in Unstructured DataHotsos 2013 - Creating Structure in Unstructured Data
Hotsos 2013 - Creating Structure in Unstructured Data
 
Java Programming and J2ME: The Basics
Java Programming and J2ME: The BasicsJava Programming and J2ME: The Basics
Java Programming and J2ME: The Basics
 
Java Serialization Deep Dive
Java Serialization Deep DiveJava Serialization Deep Dive
Java Serialization Deep Dive
 
Apache spark
Apache sparkApache spark
Apache spark
 
Getting started with entity framework
Getting started with entity framework Getting started with entity framework
Getting started with entity framework
 
BGOUG 2012 - XML Index Strategies
BGOUG 2012 - XML Index StrategiesBGOUG 2012 - XML Index Strategies
BGOUG 2012 - XML Index Strategies
 
Serialization in .NET
Serialization in .NETSerialization in .NET
Serialization in .NET
 
Easy Data Object Relational Mapping Tool
Easy Data Object Relational Mapping ToolEasy Data Object Relational Mapping Tool
Easy Data Object Relational Mapping Tool
 
Introduction to SQL Alchemy - SyPy June 2013
Introduction to SQL Alchemy - SyPy June 2013Introduction to SQL Alchemy - SyPy June 2013
Introduction to SQL Alchemy - SyPy June 2013
 

Viewers also liked

Outsourcing – case study of Connectis company, Manfred Meier, S&T
Outsourcing – case study of Connectis company, Manfred Meier, S&TOutsourcing – case study of Connectis company, Manfred Meier, S&T
Outsourcing – case study of Connectis company, Manfred Meier, S&TS&T GROUP
 
Multithreading in C# - pitfalls, mistakes and solutions. Goyello Olivia Tech ...
Multithreading in C# - pitfalls, mistakes and solutions. Goyello Olivia Tech ...Multithreading in C# - pitfalls, mistakes and solutions. Goyello Olivia Tech ...
Multithreading in C# - pitfalls, mistakes and solutions. Goyello Olivia Tech ...Kasia Horsten-Szemro
 
Techniki prezentacji od programisty dla ludzi
Techniki prezentacji od programisty dla ludziTechniki prezentacji od programisty dla ludzi
Techniki prezentacji od programisty dla ludziKasia Horsten-Szemro
 
Umiejętności programistyczne ii aplikacje
Umiejętności programistyczne ii aplikacjeUmiejętności programistyczne ii aplikacje
Umiejętności programistyczne ii aplikacjeKasia Horsten-Szemro
 
Goyello prezentacja mam pomysł i co dalej 2016 01 22
Goyello prezentacja mam pomysł i co dalej 2016 01 22Goyello prezentacja mam pomysł i co dalej 2016 01 22
Goyello prezentacja mam pomysł i co dalej 2016 01 22Kasia Horsten-Szemro
 
Multithreading in C# - pitfalls, mistakes and solutions.
Multithreading in C# - pitfalls, mistakes and solutions.Multithreading in C# - pitfalls, mistakes and solutions.
Multithreading in C# - pitfalls, mistakes and solutions.Marcin Dembowski
 
WebDeveloper - Yesterday, Today, Tomorrow
WebDeveloper - Yesterday, Today, TomorrowWebDeveloper - Yesterday, Today, Tomorrow
WebDeveloper - Yesterday, Today, TomorrowMarcin Dembowski
 
Alpha Recycling Case Study By PGS Software Ltd
Alpha Recycling Case Study By PGS Software LtdAlpha Recycling Case Study By PGS Software Ltd
Alpha Recycling Case Study By PGS Software LtdPGS Software S.A.
 
Umiejętności programistyczne i bycie geekiem to nie magia
Umiejętności programistyczne i bycie geekiem to nie magiaUmiejętności programistyczne i bycie geekiem to nie magia
Umiejętności programistyczne i bycie geekiem to nie magiaKasia Horsten-Szemro
 
Nowe technologie a bezpieczeństwo
Nowe technologie a bezpieczeństwoNowe technologie a bezpieczeństwo
Nowe technologie a bezpieczeństwoKasia Horsten-Szemro
 

Viewers also liked (19)

Outsourcing – case study of Connectis company, Manfred Meier, S&T
Outsourcing – case study of Connectis company, Manfred Meier, S&TOutsourcing – case study of Connectis company, Manfred Meier, S&T
Outsourcing – case study of Connectis company, Manfred Meier, S&T
 
About Britenet
About BritenetAbout Britenet
About Britenet
 
Multithreading in C# - pitfalls, mistakes and solutions. Goyello Olivia Tech ...
Multithreading in C# - pitfalls, mistakes and solutions. Goyello Olivia Tech ...Multithreading in C# - pitfalls, mistakes and solutions. Goyello Olivia Tech ...
Multithreading in C# - pitfalls, mistakes and solutions. Goyello Olivia Tech ...
 
Word tworzenie dokumentów
Word tworzenie dokumentówWord tworzenie dokumentów
Word tworzenie dokumentów
 
Techniki prezentacji od programisty dla ludzi
Techniki prezentacji od programisty dla ludziTechniki prezentacji od programisty dla ludzi
Techniki prezentacji od programisty dla ludzi
 
Umiejętności programistyczne ii aplikacje
Umiejętności programistyczne ii aplikacjeUmiejętności programistyczne ii aplikacje
Umiejętności programistyczne ii aplikacje
 
Goyello prezentacja mam pomysł i co dalej 2016 01 22
Goyello prezentacja mam pomysł i co dalej 2016 01 22Goyello prezentacja mam pomysł i co dalej 2016 01 22
Goyello prezentacja mam pomysł i co dalej 2016 01 22
 
Excel vba
Excel vbaExcel vba
Excel vba
 
Multithreading in C# - pitfalls, mistakes and solutions.
Multithreading in C# - pitfalls, mistakes and solutions.Multithreading in C# - pitfalls, mistakes and solutions.
Multithreading in C# - pitfalls, mistakes and solutions.
 
WebDeveloper - Yesterday, Today, Tomorrow
WebDeveloper - Yesterday, Today, TomorrowWebDeveloper - Yesterday, Today, Tomorrow
WebDeveloper - Yesterday, Today, Tomorrow
 
Alpha Recycling Case Study By PGS Software Ltd
Alpha Recycling Case Study By PGS Software LtdAlpha Recycling Case Study By PGS Software Ltd
Alpha Recycling Case Study By PGS Software Ltd
 
Umiejętności programistyczne i bycie geekiem to nie magia
Umiejętności programistyczne i bycie geekiem to nie magiaUmiejętności programistyczne i bycie geekiem to nie magia
Umiejętności programistyczne i bycie geekiem to nie magia
 
Excel arkusze kalkulacyjne
Excel arkusze kalkulacyjneExcel arkusze kalkulacyjne
Excel arkusze kalkulacyjne
 
Szkolenie social media part3
Szkolenie social media  part3Szkolenie social media  part3
Szkolenie social media part3
 
01 wstep do programowania scratch
01 wstep do programowania   scratch01 wstep do programowania   scratch
01 wstep do programowania scratch
 
Nowe technologie a bezpieczeństwo
Nowe technologie a bezpieczeństwoNowe technologie a bezpieczeństwo
Nowe technologie a bezpieczeństwo
 
Szkolenie social media part2
Szkolenie social media  part2Szkolenie social media  part2
Szkolenie social media part2
 
Szkolenie social media part1
Szkolenie social media  part1Szkolenie social media  part1
Szkolenie social media part1
 
Billennium
BillenniumBillennium
Billennium
 

Similar to Just entity framework

Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)David McCarter
 
Entity Framework v1 and v2
Entity Framework v1 and v2Entity Framework v1 and v2
Entity Framework v1 and v2Eric Nelson
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)David McCarter
 
Entity Framework V1 and V2
Entity Framework V1 and V2Entity Framework V1 and V2
Entity Framework V1 and V2ukdpe
 
Elements for an iOS Backend
Elements for an iOS BackendElements for an iOS Backend
Elements for an iOS BackendLaurent Cerveau
 
.NET Core: a new .NET Platform
.NET Core: a new .NET Platform.NET Core: a new .NET Platform
.NET Core: a new .NET PlatformAlex Thissen
 
ASP.NET MVC and Entity Framework 4
ASP.NET MVC and Entity Framework 4ASP.NET MVC and Entity Framework 4
ASP.NET MVC and Entity Framework 4James Johnson
 
MVC and Entity Framework 4
MVC and Entity Framework 4MVC and Entity Framework 4
MVC and Entity Framework 4James Johnson
 
LINQ-Introduction.ppt
LINQ-Introduction.pptLINQ-Introduction.ppt
LINQ-Introduction.pptssusera8c91a
 
Tamir Dresher - DotNet 7 What's new.pptx
Tamir Dresher - DotNet 7 What's new.pptxTamir Dresher - DotNet 7 What's new.pptx
Tamir Dresher - DotNet 7 What's new.pptxTamir Dresher
 
JavaOne 2012 - CON11234 - Multi device Content Display and a Smart Use of Ann...
JavaOne 2012 - CON11234 - Multi device Content Display and a Smart Use of Ann...JavaOne 2012 - CON11234 - Multi device Content Display and a Smart Use of Ann...
JavaOne 2012 - CON11234 - Multi device Content Display and a Smart Use of Ann...gdigugli
 
What's New for Data?
What's New for Data?What's New for Data?
What's New for Data?ukdpe
 
"Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft...
"Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft..."Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft...
"Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft...Dataconomy Media
 
.NET Core, ASP.NET Core Course, Session 17
.NET Core, ASP.NET Core Course, Session 17.NET Core, ASP.NET Core Course, Session 17
.NET Core, ASP.NET Core Course, Session 17aminmesbahi
 
Doctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHPDoctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHPGuilherme Blanco
 
Entity framework introduction sesion-1
Entity framework introduction   sesion-1Entity framework introduction   sesion-1
Entity framework introduction sesion-1Usama Nada
 
Michael North "Ember.js 2 - Future-friendly ambitious apps, that scale!"
Michael North "Ember.js 2 - Future-friendly ambitious apps, that scale!"Michael North "Ember.js 2 - Future-friendly ambitious apps, that scale!"
Michael North "Ember.js 2 - Future-friendly ambitious apps, that scale!"Fwdays
 
Skillwise - Enhancing dotnet app
Skillwise - Enhancing dotnet appSkillwise - Enhancing dotnet app
Skillwise - Enhancing dotnet appSkillwise Group
 
Think Like Spark: Some Spark Concepts and a Use Case
Think Like Spark: Some Spark Concepts and a Use CaseThink Like Spark: Some Spark Concepts and a Use Case
Think Like Spark: Some Spark Concepts and a Use CaseRachel Warren
 
Polyglot persistence @ netflix (CDE Meetup)
Polyglot persistence @ netflix (CDE Meetup) Polyglot persistence @ netflix (CDE Meetup)
Polyglot persistence @ netflix (CDE Meetup) Roopa Tangirala
 

Similar to Just entity framework (20)

Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
 
Entity Framework v1 and v2
Entity Framework v1 and v2Entity Framework v1 and v2
Entity Framework v1 and v2
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
 
Entity Framework V1 and V2
Entity Framework V1 and V2Entity Framework V1 and V2
Entity Framework V1 and V2
 
Elements for an iOS Backend
Elements for an iOS BackendElements for an iOS Backend
Elements for an iOS Backend
 
.NET Core: a new .NET Platform
.NET Core: a new .NET Platform.NET Core: a new .NET Platform
.NET Core: a new .NET Platform
 
ASP.NET MVC and Entity Framework 4
ASP.NET MVC and Entity Framework 4ASP.NET MVC and Entity Framework 4
ASP.NET MVC and Entity Framework 4
 
MVC and Entity Framework 4
MVC and Entity Framework 4MVC and Entity Framework 4
MVC and Entity Framework 4
 
LINQ-Introduction.ppt
LINQ-Introduction.pptLINQ-Introduction.ppt
LINQ-Introduction.ppt
 
Tamir Dresher - DotNet 7 What's new.pptx
Tamir Dresher - DotNet 7 What's new.pptxTamir Dresher - DotNet 7 What's new.pptx
Tamir Dresher - DotNet 7 What's new.pptx
 
JavaOne 2012 - CON11234 - Multi device Content Display and a Smart Use of Ann...
JavaOne 2012 - CON11234 - Multi device Content Display and a Smart Use of Ann...JavaOne 2012 - CON11234 - Multi device Content Display and a Smart Use of Ann...
JavaOne 2012 - CON11234 - Multi device Content Display and a Smart Use of Ann...
 
What's New for Data?
What's New for Data?What's New for Data?
What's New for Data?
 
"Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft...
"Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft..."Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft...
"Source Code Abstracts Classification Using CNN", Vadim Markovtsev, Lead Soft...
 
.NET Core, ASP.NET Core Course, Session 17
.NET Core, ASP.NET Core Course, Session 17.NET Core, ASP.NET Core Course, Session 17
.NET Core, ASP.NET Core Course, Session 17
 
Doctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHPDoctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHP
 
Entity framework introduction sesion-1
Entity framework introduction   sesion-1Entity framework introduction   sesion-1
Entity framework introduction sesion-1
 
Michael North "Ember.js 2 - Future-friendly ambitious apps, that scale!"
Michael North "Ember.js 2 - Future-friendly ambitious apps, that scale!"Michael North "Ember.js 2 - Future-friendly ambitious apps, that scale!"
Michael North "Ember.js 2 - Future-friendly ambitious apps, that scale!"
 
Skillwise - Enhancing dotnet app
Skillwise - Enhancing dotnet appSkillwise - Enhancing dotnet app
Skillwise - Enhancing dotnet app
 
Think Like Spark: Some Spark Concepts and a Use Case
Think Like Spark: Some Spark Concepts and a Use CaseThink Like Spark: Some Spark Concepts and a Use Case
Think Like Spark: Some Spark Concepts and a Use Case
 
Polyglot persistence @ netflix (CDE Meetup)
Polyglot persistence @ netflix (CDE Meetup) Polyglot persistence @ netflix (CDE Meetup)
Polyglot persistence @ netflix (CDE Meetup)
 

Recently uploaded

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
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
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
 
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
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
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
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
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
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 

Recently uploaded (20)

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!
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
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
 
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
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
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
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
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
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 

Just entity framework

  • 1. TGZ.NET 14 Dec 2011 Entity Framework „I am just a teenanger” Marcin Dembowski .NET Developer @ Goyello
  • 2. Agenda • We have a database - DbFirst • The long history • How it works • Model and Code First • Plans for future
  • 3. PROBLEM: We want to have access from code
  • 5. The Hist(e)ory of Ms EF • EDM evolved from E- Relation Modelling (ERM) 1976 • Chaos ADO.NET • Announced at TechED TechED in 2006 • July 2008 – First release – vs 2008 SP1 .NET 3.5 SP1 • April 2010 – Second release • April 2011 – EF 4.1 with CodeFirst • July 2011 – EF 4.1 Update 1 and CTP • November 2011 – EF 4.2 – nothing special 
  • 6. EF – how it works ? Management, Tracking, Relationships Entity SQL, some kind of facade Our EDMX file Our old ADO.NET Real database
  • 8. <add name="MyContainer" METADATA connectionString=„ • The Calling Assembly metadata=res://*/MyEFM.csdl| • Referenced assemblies res://*/MyEFM.ssdl| • Assemblies in bin res://*/MyEFM.msl; provider=System.Data.SqlClient; provider connection string=&quot;data source=.R22008EXPRESS; attachdbfilename=|DataDirectory|RepairCompanyDatabase.mdf; integrated security=True;user instance=True; multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> NOTE: The Connection String
  • 9. Inheritance Strategies • Table Per Hierarchy (TPH) • Table Per Type (TPT) • Table Per Concrete Type (TPC) • Hybrid Mappings • Entity Splitting
  • 10. Table Per Hierarchy • All properties in one table • Additional discriminator column
  • 11. PROS: • No JOINS or UNIONS in SQL statements • Flat table CONS: • Derived Properties must be nullable • Denormalized • Poor storage use – many empty fields TIP: Table Per Hierarchy (TPH)
  • 12. Table Per Type • All properties from base type in one table • Additional properties in seperate tables
  • 13. PROS: • Application is easier to extend CONS: • Performance disadvantage • Uses JOINS • Query can be more complex than required* TIP: Table Per Type (TPT)
  • 14. Table Per Concrete type • All properties from each type in seperate table • All tables share the same ID (PK)
  • 15. PROS: • Simple Query when querying for specific type CONS: • Performance issue when pulling from multiple tables • All keys have to be unique accros tables TIP: Table Per Concrete type (TPC)
  • 17. EF vs. Other Feature L2S EF NH Eager and lazy loading configurable per relationship N N Y Good documentation Y Y N Easy logging Y N Y Mature - N Y Configured by XML N Y/N N* Supports Enums N* Y Different database providers N Y Y http://msdn.microsoft.com/en-us/library/cc853327.aspx http://blogs.msdn.com/b/adonet/archive/2008/03/27/ado-net-entity-framework-performance-comparison.aspx
  • 18. PROS: • Any next use is faster CONS: • First use can take some time static readonly Func<MyDataModelContainer, int, IQueryable<Post>> compiledQuery DEFINITION = CompiledQuery.Compile<MyDataModelContainer, int, IQueryable<Post>>( (context,id) => from c in context.PostSet where c.UserId == id select c ); var post = compiledQuery USAGE .Invoke(context, 1) .FirstOrDefault(); TIP: Use compiled query
  • 19. PROS: • Use this only when you will get some data (Lookup tables) CONS: • Any changes are not tracked PER ENTITY context.UserSet.MergeOption = MergeOption.NoTracking; context.PostSet.MergeOption = MergeOption.NoTracking; TIP: Set MergeOptions
  • 20. PROS: • Removes the n-select problem CONS: • Can fetch large data from c in context STRINGS .PostSet .Include("PostComment") where c.UserId == id select c from c in context EXPRESSION* .PostSet .Include(c => c.PostComment) where c.UserId == id select c TIP: Including related data (Immediate load)
  • 21. PROS: • Dynamic Queries • Named parameters CONS: • Type unsafe – it’s uses strings var posts = context.PostSet .Where("it.Id > @id", new ObjectParameter("id", 1)) STRINGS .OrderBy("it.Title") .Skip("it.Id", "@skip", new ObjectParameter("skip", 3)) .Top("@limit", new ObjectParameter("limit", 5)) TIP: Custom queries
  • 22. SETTINGS context.ContextOptions.LazyLoadingEnabled = false; context.ContextOptions.ProxyCreationEnabled = false; public partial class Post { public virtual int Id { get; set; } public virtual string Title { get; set; } public virtual string Content { get; set; } … public virtual ICollection<PostComment> PostComment { .. } } TIP: Configure EF behaviour
  • 23. PROS: • When multiple times used SaveChanges() dbContext.Database.Connection.Open() SET TIP: Manage connections
  • 24. • Allows to create TPT • Allows to create TPH a • Allows to create database generation script • Allows to create difference migration script http://visualstudiogallery.msdn.microsoft.com/df3541c3-d833-4b65-b942-989e7ec74c87 TOOL: Entity Framework Tool
  • 26. Tracing • ToTraceString() • Tracing provider http://bit.ly/b3AFXc • SQL Profiler AnjLab SQL Profiler http://bit.ly/9Igw78
  • 27. To sum up… • Entity Framework • Removes Linq 2 SQL – don’t* use L2S • Multiple database providers • Database/Model/Code First Design • It’s not so perfect now • It’s like a teenanger … • Still digging into XML • Sometimes you have to use T-SQL instead eSQL
  • 28. ADO.NET Entity Framework Questions ? Join us : http://kariera.goyello.com
  • 29. Thanks for your attention ! Entity Framework Marcin Dembowski • Mail.To("marcin.dembowski") .At("goyello").Com() blog.goyello.com • marcindembowski.wordpress.com • twitter.com/D3M80L twitter.com/goyello facebook.com/goyello kariera.goyello.com