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

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 

Recently uploaded (20)

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.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