SlideShare a Scribd company logo
1 of 17
OR Impedance Mismatch
OR Impedance Mismatch

 •Conflicting type systems
 •Conflicting design goals
    Database system focuses specifically on the storage and retrieval of data, whereas an object system
    focuses specifically on the union of state and behavior for easier programmer manipulation
 •Conflicting architectural style
    Most database products are built to assume a fundamentally client/server style of interaction, assuming the
    database is located elsewhere on the network, and programs accessing the database will be doing so via
    some sort of remote access protocol. Object systems assume the precise opposite, and in fact, perform
    significantly worse when distributed.
 •Differing structural relationships
    Relational data stores track entities in terms of relations between tuples and tuplesets; object-oriented
    systems instead prefer to track entities in terms of classes, compilation of state and behavior that relates to
    one another through IS-A and/or HAS-A style unidirectional connections. Where databases use foreign-key
    relationships to indicate relations, objects use references or pointers




                                                                                                                      2
OR Impedance Mismatch

 •Differing identity constructs
    Object systems use an implicit sense of identity to distinguish between objects of similar state (the
    ubiquitous this pointer or reference), yet databases require that sense of identity to be explicit via primary
    key column or columns. In fact, in modern object-oriented languages an object system cannot be built
    without a sense of object identity, whereas relational tables can have no primary key whatsoever, if
    desired.
 •Transactional boundaries
    Object systems do not have any sense of "transactional demarcation" when working with the objects,
    whereas database instances must in order to deal with the multi-user requirements of a modern
                .
    client/server-based system

 •Query/access capabilities
    Retrieving data stored in a relational database makes use of SQL, a declarative language predicated on
    the mathematical theory of relational algebra and predicate. In object systems, the entire object is required
    in order to navigate from one object to the next, meaning that the entire graph of objects is necessary in
    order to find two disparate parts of data—for a system intended to remain entirely in working memory, this
    is of no concern, but for a system whose principal access is intended to be distributed, as relational
    database are, this can be a crippling problem.




                                                                                                                     3
Object Relational Mapping
Wikipedia defines an ORM as: “a programming technique for
converting data between incompatible type systems in
relational databases and object-oriented programming
languages. This creates, in effect, a "virtual object
database," which can be used from within the programming
language.” An ORM has to provide a facility to map
database tables to domain objects, using a design surface or
wizard. This mapping is in-between your database and
domain model, independent from the source code and the
database. The ORM runtime then converts the commands
issued by the domain model against the mapping into back
end database retrieval and SQL statements. Mapping allows
an application to deal seamlessly with several different
database models, or even databases.

                                                          4
The LINQ Project
      C#             VB            Others…


     .NET Language Integrated Query

   Standard
                  DLinq              XLinq
    Query
                (ADO.NET)         (System.Xml)
   Operators


                                    <book>
                                      <title/>
                                      <author/>
                                      <year/>
                                      <price/>
                                    </book>




    Objects    SQL        WinFS        XML
Data Access In APIs Today

   Sql C onnect i on c = new                Queries in
 Sql C onnect i on( …) ;                      quotes
   c. Open( ) ;
   Sql C m
         om and cm = new Sql C m
                      d              om and( Arguments
         @ SELEC c. N e, c. Phone
          "         T      am                  loosely
                  FR M C
                     O ust om s cer             bound
                  W ER c. C t y = @
                    H E        i      p0"
                                               Results
         );
                                               loosely
   cm Par am er s. AddW t hVal ue( " @po" ,
      d.         et            i
                                                typed
                                              Compiler
 " London" ) ;
    at eader dr = c. Execut e( cm ; cannot help
   D aR                                 d)
   w l e ( dr . R
    hi              ead( ) ) {                   catch
         st r i ng nam = dr . G St r i ng( 0) mistakes
                       e          et          ;
Data Access with DLINQ

 publ i c cl ass C  ust omer       Classes
 {                                 describe
      publ i c i nt I d;             data
                                  Tables are
      publ i c st r i ng N e;
                          am
                                  collections
      publ i c st r i ng Phone;
      …
 }
                                    Query is
 Tabl e<C ust om > cust om s =
                er        er      natural part
 db. Cust om s;
            er                       of the
                                   language
                                      The
 var cont act s =                   compiler
     f r om c i n cust om s
                         er        helps you
DLinq For Relational Data
 Accessing data with DLinq
                              Classes
      public class Customer { … }
                               describe data

  public class Northwind: DataContext  Tables are
                     {              like collections
   public Table<Customer> Customers;
                      …            Strongly typed
  Northwind db = new } Northwind(…connection
                                     );
             var contacts =       Integrated
          from c in db.Customersquery syntax
         where c.City == "London"
     select new { c.Name, c.Phone }; typed
                              Strongly
                                    results
Architecture
f r om c i n db. Cust om s
                        er
w e c. C t y == " London"
  her       i                        Application
sel ect
  new { c. N e, c. Phone }
              am


                       LINQ Query      Objects   SubmitChanges()


                                                            Services:
                                   DLinq                    - Change tracking
                                                            - Concurrency control
                                 (ADO.NET)                  - Object identity


                         SQL Query     Rows      SQL or
                                                 Stored
                                                 Procs
sel ect N e, Phone
          am
f r om cust om s
              er
w e ci t y = ' London'
  her
                                      SQLSer
Key Takeaways
 Language integrated data access
   Maps tables and rows to classes and objects
   Builds on ADO.NET and .NET Transactions
 Mapping
   Encoded in attributes
   Relationships map to properties
   Manually authored or tool generated
 Persistence
   Automatic change tracking
   Updates through SQL or stored procedures
 DataContext
   Strongly typed database
Querying For Objects
Key Takeaways
 Language Integrated Query
   Compile-time type checking, IntelliSense

 SQL-like query syntax
   With support for hierarchy and relationships

 Intelligent object loading
   Deferred or immediate


                                                  12
Updating Objects
Key Takeaways
 Auto-generated updates
  Using optimistic concurrency

 Transactions
  Integrates with System.Transactions

 SQL pass-through
  Returning objects from SQL queries


                                        14
DLinq Summary
 Allows access to relational data as objects

 Supports Language Integrated Query

 Works with existing infrastructure

 Unifies programming model for objects,
 relational and XML

                                               15
When to Use LINQ to SQL?
The primary scenario for using LINQ to SQL is when building
applications with a rapid development cycle and a simple
one-to-one object to relational mapping against the Microsoft
SQL Server family of databases. In other words, when
building an application whose object model is structured very
similarly to the existing database structure, or when a
database for the application does not yet exist and there is
no predisposition against creating a database schema that
mirrors the object model




                                                           16
When to Use LINQ to SQL?
   I want to…                                                    LINQ to SQL is
                                                                 applicable

   Use an ORM solution and my database is 1:1 with my object
   model

   Use an ORM solution with inheritance hierarchies that are
   stored in a single table

   Use my own plain CLR classes instead of using generated
   classes or deriving from a base class or implementing an
   interface

   Leverage LINQ as the way I write queries


   Use an ORM but I want something that is very performant and
   where I can optimize performance through stored procedures
   and compiled queries




                                                                                  17

More Related Content

What's hot

Ado.net session04
Ado.net session04Ado.net session04
Ado.net session04Niit Care
 
Big Data & Analytics MapReduce/Hadoop – A programmer’s perspective
Big Data & Analytics MapReduce/Hadoop – A programmer’s perspectiveBig Data & Analytics MapReduce/Hadoop – A programmer’s perspective
Big Data & Analytics MapReduce/Hadoop – A programmer’s perspectiveEMC
 
Xml processing-by-asfak
Xml processing-by-asfakXml processing-by-asfak
Xml processing-by-asfakAsfak Mahamud
 
Ado.net session01
Ado.net session01Ado.net session01
Ado.net session01Niit Care
 
Unit 3 writable collections
Unit 3 writable collectionsUnit 3 writable collections
Unit 3 writable collectionsvishal choudhary
 
Ado.net session07
Ado.net session07Ado.net session07
Ado.net session07Niit Care
 
Sedna XML Database: Query Parser & Optimizing Rewriter
Sedna XML Database: Query Parser & Optimizing RewriterSedna XML Database: Query Parser & Optimizing Rewriter
Sedna XML Database: Query Parser & Optimizing RewriterIvan Shcheklein
 
Summary of "Amazon's Dynamo" for the 2nd nosql summer reading in Tokyo
Summary of "Amazon's Dynamo" for the 2nd nosql summer reading in TokyoSummary of "Amazon's Dynamo" for the 2nd nosql summer reading in Tokyo
Summary of "Amazon's Dynamo" for the 2nd nosql summer reading in TokyoCLOUDIAN KK
 
Triplestore and SPARQL
Triplestore and SPARQLTriplestore and SPARQL
Triplestore and SPARQLLino Valdivia
 
Apache Hadoop Java API
Apache Hadoop Java APIApache Hadoop Java API
Apache Hadoop Java APIAdam Kawa
 
Overloading in Overdrive: A Generic Data-Centric Messaging Library for DDS
Overloading in Overdrive: A Generic Data-Centric Messaging Library for DDSOverloading in Overdrive: A Generic Data-Centric Messaging Library for DDS
Overloading in Overdrive: A Generic Data-Centric Messaging Library for DDSSumant Tambe
 
XQuery Triggers in Native XML Database Sedna
XQuery Triggers in Native XML Database SednaXQuery Triggers in Native XML Database Sedna
XQuery Triggers in Native XML Database Sednamaria.grineva
 
Beyond Map/Reduce: Getting Creative With Parallel Processing
Beyond Map/Reduce: Getting Creative With Parallel ProcessingBeyond Map/Reduce: Getting Creative With Parallel Processing
Beyond Map/Reduce: Getting Creative With Parallel ProcessingEd Kohlwey
 
Architecture of Native XML Database Sedna
Architecture of Native XML Database SednaArchitecture of Native XML Database Sedna
Architecture of Native XML Database Sednamaria.grineva
 

What's hot (20)

02.adt
02.adt02.adt
02.adt
 
Ado.net session04
Ado.net session04Ado.net session04
Ado.net session04
 
List moderate
List   moderateList   moderate
List moderate
 
Big Data & Analytics MapReduce/Hadoop – A programmer’s perspective
Big Data & Analytics MapReduce/Hadoop – A programmer’s perspectiveBig Data & Analytics MapReduce/Hadoop – A programmer’s perspective
Big Data & Analytics MapReduce/Hadoop – A programmer’s perspective
 
Xml processing-by-asfak
Xml processing-by-asfakXml processing-by-asfak
Xml processing-by-asfak
 
Ado.net session01
Ado.net session01Ado.net session01
Ado.net session01
 
Unit 3 writable collections
Unit 3 writable collectionsUnit 3 writable collections
Unit 3 writable collections
 
Ado.net session07
Ado.net session07Ado.net session07
Ado.net session07
 
Sedna XML Database: Query Parser & Optimizing Rewriter
Sedna XML Database: Query Parser & Optimizing RewriterSedna XML Database: Query Parser & Optimizing Rewriter
Sedna XML Database: Query Parser & Optimizing Rewriter
 
Sql server
Sql serverSql server
Sql server
 
Summary of "Amazon's Dynamo" for the 2nd nosql summer reading in Tokyo
Summary of "Amazon's Dynamo" for the 2nd nosql summer reading in TokyoSummary of "Amazon's Dynamo" for the 2nd nosql summer reading in Tokyo
Summary of "Amazon's Dynamo" for the 2nd nosql summer reading in Tokyo
 
Triplestore and SPARQL
Triplestore and SPARQLTriplestore and SPARQL
Triplestore and SPARQL
 
Apache Hadoop Java API
Apache Hadoop Java APIApache Hadoop Java API
Apache Hadoop Java API
 
Ds lists
Ds listsDs lists
Ds lists
 
Overloading in Overdrive: A Generic Data-Centric Messaging Library for DDS
Overloading in Overdrive: A Generic Data-Centric Messaging Library for DDSOverloading in Overdrive: A Generic Data-Centric Messaging Library for DDS
Overloading in Overdrive: A Generic Data-Centric Messaging Library for DDS
 
XQuery Triggers in Native XML Database Sedna
XQuery Triggers in Native XML Database SednaXQuery Triggers in Native XML Database Sedna
XQuery Triggers in Native XML Database Sedna
 
Beyond Map/Reduce: Getting Creative With Parallel Processing
Beyond Map/Reduce: Getting Creative With Parallel ProcessingBeyond Map/Reduce: Getting Creative With Parallel Processing
Beyond Map/Reduce: Getting Creative With Parallel Processing
 
Map/Reduce intro
Map/Reduce introMap/Reduce intro
Map/Reduce intro
 
R Introduction
R IntroductionR Introduction
R Introduction
 
Architecture of Native XML Database Sedna
Architecture of Native XML Database SednaArchitecture of Native XML Database Sedna
Architecture of Native XML Database Sedna
 

Viewers also liked

Phan ii quytrinhkythuatkhaithacmuvachamsoc
Phan ii quytrinhkythuatkhaithacmuvachamsocPhan ii quytrinhkythuatkhaithacmuvachamsoc
Phan ii quytrinhkythuatkhaithacmuvachamsocHung Pham Thai
 
Progress 4 C Association Workshop Dalat 04122009
Progress 4 C Association Workshop Dalat 04122009Progress 4 C Association Workshop Dalat 04122009
Progress 4 C Association Workshop Dalat 04122009Hung Pham Thai
 
Technology Integration
Technology IntegrationTechnology Integration
Technology Integrationguest5b9bf4
 
SharePoint Jumpstart
SharePoint JumpstartSharePoint Jumpstart
SharePoint JumpstartKelly Cebold
 
Technology In The Classroom
Technology In The ClassroomTechnology In The Classroom
Technology In The Classroomhales4
 
Pres Outline Da Lat En
Pres Outline Da Lat EnPres Outline Da Lat En
Pres Outline Da Lat EnHung Pham Thai
 
ITC Project Toads and Frogs
ITC Project Toads and FrogsITC Project Toads and Frogs
ITC Project Toads and FrogsKuhnbyah
 
The North Country Trail
The North Country TrailThe North Country Trail
The North Country Trailncta
 
Technology In The Classroom
Technology In The ClassroomTechnology In The Classroom
Technology In The Classroomhales4
 
Vegetables. growing asparagus in the home garden
Vegetables. growing asparagus in the home gardenVegetables. growing asparagus in the home garden
Vegetables. growing asparagus in the home gardenHung Pham Thai
 
Blockbuster Everything...
Blockbuster Everything...Blockbuster Everything...
Blockbuster Everything...laurengrossling
 
Hmt Health Claims Brussels 1 December Pw
Hmt Health Claims Brussels 1 December PwHmt Health Claims Brussels 1 December Pw
Hmt Health Claims Brussels 1 December Pwpeterwennstrom
 

Viewers also liked (20)

Phan ii quytrinhkythuatkhaithacmuvachamsoc
Phan ii quytrinhkythuatkhaithacmuvachamsocPhan ii quytrinhkythuatkhaithacmuvachamsoc
Phan ii quytrinhkythuatkhaithacmuvachamsoc
 
Progress 4 C Association Workshop Dalat 04122009
Progress 4 C Association Workshop Dalat 04122009Progress 4 C Association Workshop Dalat 04122009
Progress 4 C Association Workshop Dalat 04122009
 
K51.24.05.2009
K51.24.05.2009K51.24.05.2009
K51.24.05.2009
 
Chuong 09 vb
Chuong 09   vbChuong 09   vb
Chuong 09 vb
 
Technology Integration
Technology IntegrationTechnology Integration
Technology Integration
 
SharePoint Jumpstart
SharePoint JumpstartSharePoint Jumpstart
SharePoint Jumpstart
 
Technology In The Classroom
Technology In The ClassroomTechnology In The Classroom
Technology In The Classroom
 
Tcvn 3769 2004
Tcvn 3769 2004Tcvn 3769 2004
Tcvn 3769 2004
 
Rsn dec2008
Rsn dec2008Rsn dec2008
Rsn dec2008
 
Pres Outline Da Lat En
Pres Outline Da Lat EnPres Outline Da Lat En
Pres Outline Da Lat En
 
ITC Project Toads and Frogs
ITC Project Toads and FrogsITC Project Toads and Frogs
ITC Project Toads and Frogs
 
CHỌN GIỐNG
CHỌN GIỐNGCHỌN GIỐNG
CHỌN GIỐNG
 
The North Country Trail
The North Country TrailThe North Country Trail
The North Country Trail
 
Technology In The Classroom
Technology In The ClassroomTechnology In The Classroom
Technology In The Classroom
 
Pdf Slideshare R
Pdf Slideshare RPdf Slideshare R
Pdf Slideshare R
 
earth
earthearth
earth
 
Vegetables. growing asparagus in the home garden
Vegetables. growing asparagus in the home gardenVegetables. growing asparagus in the home garden
Vegetables. growing asparagus in the home garden
 
Blockbuster Everything...
Blockbuster Everything...Blockbuster Everything...
Blockbuster Everything...
 
Excel 2007 bai 2-1
Excel 2007   bai 2-1Excel 2007   bai 2-1
Excel 2007 bai 2-1
 
Hmt Health Claims Brussels 1 December Pw
Hmt Health Claims Brussels 1 December PwHmt Health Claims Brussels 1 December Pw
Hmt Health Claims Brussels 1 December Pw
 

Similar to Object Relational Mapping with LINQ To SQL

Similar to Object Relational Mapping with LINQ To SQL (20)

L2s 090701234157 Phpapp02
L2s 090701234157 Phpapp02L2s 090701234157 Phpapp02
L2s 090701234157 Phpapp02
 
Ado.net
Ado.netAdo.net
Ado.net
 
Lecture 6. ADO.NET Overview.
Lecture 6. ADO.NET Overview.Lecture 6. ADO.NET Overview.
Lecture 6. ADO.NET Overview.
 
Introduction to ado
Introduction to adoIntroduction to ado
Introduction to ado
 
Ado dot net complete meterial (1)
Ado dot net complete meterial (1)Ado dot net complete meterial (1)
Ado dot net complete meterial (1)
 
ADO .Net
ADO .Net ADO .Net
ADO .Net
 
Intake 37 linq3
Intake 37 linq3Intake 37 linq3
Intake 37 linq3
 
Ado.net
Ado.netAdo.net
Ado.net
 
NHibernate
NHibernateNHibernate
NHibernate
 
Chapter 3: ado.net
Chapter 3: ado.netChapter 3: ado.net
Chapter 3: ado.net
 
05 entity framework
05 entity framework05 entity framework
05 entity framework
 
Ado
AdoAdo
Ado
 
Chap14 ado.net
Chap14 ado.netChap14 ado.net
Chap14 ado.net
 
ADO.NET
ADO.NETADO.NET
ADO.NET
 
Ch06 ado.net fundamentals
Ch06 ado.net fundamentalsCh06 ado.net fundamentals
Ch06 ado.net fundamentals
 
Tutorial On Database Management System
Tutorial On Database Management SystemTutorial On Database Management System
Tutorial On Database Management System
 
Linq to sql
Linq to sqlLinq to sql
Linq to sql
 
Dbms & prog lang
Dbms & prog langDbms & prog lang
Dbms & prog lang
 
Understanding linq
Understanding linqUnderstanding linq
Understanding linq
 
ADO.net control
ADO.net controlADO.net control
ADO.net control
 

More from Shahriar Hyder

Effective Communication Skills for Software Engineers
Effective Communication Skills for Software EngineersEffective Communication Skills for Software Engineers
Effective Communication Skills for Software EngineersShahriar Hyder
 
A JavaScript Master Class - From the Wows to the WTFs
A JavaScript Master Class - From the Wows to the WTFsA JavaScript Master Class - From the Wows to the WTFs
A JavaScript Master Class - From the Wows to the WTFsShahriar Hyder
 
Dependency Inversion Principle
Dependency Inversion PrincipleDependency Inversion Principle
Dependency Inversion PrincipleShahriar Hyder
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design PatternShahriar Hyder
 
Taking a Quantum Leap with Html 5 WebSocket
Taking a Quantum Leap with Html 5 WebSocketTaking a Quantum Leap with Html 5 WebSocket
Taking a Quantum Leap with Html 5 WebSocketShahriar Hyder
 
Functional Programming Fundamentals
Functional Programming FundamentalsFunctional Programming Fundamentals
Functional Programming FundamentalsShahriar Hyder
 
C# 3.0 Language Innovations
C# 3.0 Language InnovationsC# 3.0 Language Innovations
C# 3.0 Language InnovationsShahriar Hyder
 

More from Shahriar Hyder (9)

Effective Communication Skills for Software Engineers
Effective Communication Skills for Software EngineersEffective Communication Skills for Software Engineers
Effective Communication Skills for Software Engineers
 
A JavaScript Master Class - From the Wows to the WTFs
A JavaScript Master Class - From the Wows to the WTFsA JavaScript Master Class - From the Wows to the WTFs
A JavaScript Master Class - From the Wows to the WTFs
 
Dependency Inversion Principle
Dependency Inversion PrincipleDependency Inversion Principle
Dependency Inversion Principle
 
Bridge Design Pattern
Bridge Design PatternBridge Design Pattern
Bridge Design Pattern
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design Pattern
 
Taking a Quantum Leap with Html 5 WebSocket
Taking a Quantum Leap with Html 5 WebSocketTaking a Quantum Leap with Html 5 WebSocket
Taking a Quantum Leap with Html 5 WebSocket
 
Functional Programming Fundamentals
Functional Programming FundamentalsFunctional Programming Fundamentals
Functional Programming Fundamentals
 
C# 3.0 Language Innovations
C# 3.0 Language InnovationsC# 3.0 Language Innovations
C# 3.0 Language Innovations
 
Introduction to Linq
Introduction to LinqIntroduction to Linq
Introduction to Linq
 

Recently uploaded

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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
🐬 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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
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
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
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
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 

Recently uploaded (20)

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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
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
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
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...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 

Object Relational Mapping with LINQ To SQL

  • 2. OR Impedance Mismatch •Conflicting type systems •Conflicting design goals Database system focuses specifically on the storage and retrieval of data, whereas an object system focuses specifically on the union of state and behavior for easier programmer manipulation •Conflicting architectural style Most database products are built to assume a fundamentally client/server style of interaction, assuming the database is located elsewhere on the network, and programs accessing the database will be doing so via some sort of remote access protocol. Object systems assume the precise opposite, and in fact, perform significantly worse when distributed. •Differing structural relationships Relational data stores track entities in terms of relations between tuples and tuplesets; object-oriented systems instead prefer to track entities in terms of classes, compilation of state and behavior that relates to one another through IS-A and/or HAS-A style unidirectional connections. Where databases use foreign-key relationships to indicate relations, objects use references or pointers 2
  • 3. OR Impedance Mismatch •Differing identity constructs Object systems use an implicit sense of identity to distinguish between objects of similar state (the ubiquitous this pointer or reference), yet databases require that sense of identity to be explicit via primary key column or columns. In fact, in modern object-oriented languages an object system cannot be built without a sense of object identity, whereas relational tables can have no primary key whatsoever, if desired. •Transactional boundaries Object systems do not have any sense of "transactional demarcation" when working with the objects, whereas database instances must in order to deal with the multi-user requirements of a modern . client/server-based system •Query/access capabilities Retrieving data stored in a relational database makes use of SQL, a declarative language predicated on the mathematical theory of relational algebra and predicate. In object systems, the entire object is required in order to navigate from one object to the next, meaning that the entire graph of objects is necessary in order to find two disparate parts of data—for a system intended to remain entirely in working memory, this is of no concern, but for a system whose principal access is intended to be distributed, as relational database are, this can be a crippling problem. 3
  • 4. Object Relational Mapping Wikipedia defines an ORM as: “a programming technique for converting data between incompatible type systems in relational databases and object-oriented programming languages. This creates, in effect, a "virtual object database," which can be used from within the programming language.” An ORM has to provide a facility to map database tables to domain objects, using a design surface or wizard. This mapping is in-between your database and domain model, independent from the source code and the database. The ORM runtime then converts the commands issued by the domain model against the mapping into back end database retrieval and SQL statements. Mapping allows an application to deal seamlessly with several different database models, or even databases. 4
  • 5. The LINQ Project C# VB Others… .NET Language Integrated Query Standard DLinq XLinq Query (ADO.NET) (System.Xml) Operators <book> <title/> <author/> <year/> <price/> </book> Objects SQL WinFS XML
  • 6. Data Access In APIs Today Sql C onnect i on c = new Queries in Sql C onnect i on( …) ; quotes c. Open( ) ; Sql C m om and cm = new Sql C m d om and( Arguments @ SELEC c. N e, c. Phone " T am loosely FR M C O ust om s cer bound W ER c. C t y = @ H E i p0" Results ); loosely cm Par am er s. AddW t hVal ue( " @po" , d. et i typed Compiler " London" ) ; at eader dr = c. Execut e( cm ; cannot help D aR d) w l e ( dr . R hi ead( ) ) { catch st r i ng nam = dr . G St r i ng( 0) mistakes e et ;
  • 7. Data Access with DLINQ publ i c cl ass C ust omer Classes { describe publ i c i nt I d; data Tables are publ i c st r i ng N e; am collections publ i c st r i ng Phone; … } Query is Tabl e<C ust om > cust om s = er er natural part db. Cust om s; er of the language The var cont act s = compiler f r om c i n cust om s er helps you
  • 8. DLinq For Relational Data Accessing data with DLinq Classes public class Customer { … } describe data public class Northwind: DataContext Tables are { like collections public Table<Customer> Customers; … Strongly typed Northwind db = new } Northwind(…connection ); var contacts = Integrated from c in db.Customersquery syntax where c.City == "London" select new { c.Name, c.Phone }; typed Strongly results
  • 9. Architecture f r om c i n db. Cust om s er w e c. C t y == " London" her i Application sel ect new { c. N e, c. Phone } am LINQ Query Objects SubmitChanges() Services: DLinq - Change tracking - Concurrency control (ADO.NET) - Object identity SQL Query Rows SQL or Stored Procs sel ect N e, Phone am f r om cust om s er w e ci t y = ' London' her SQLSer
  • 10. Key Takeaways Language integrated data access Maps tables and rows to classes and objects Builds on ADO.NET and .NET Transactions Mapping Encoded in attributes Relationships map to properties Manually authored or tool generated Persistence Automatic change tracking Updates through SQL or stored procedures DataContext Strongly typed database
  • 12. Key Takeaways Language Integrated Query Compile-time type checking, IntelliSense SQL-like query syntax With support for hierarchy and relationships Intelligent object loading Deferred or immediate 12
  • 14. Key Takeaways Auto-generated updates Using optimistic concurrency Transactions Integrates with System.Transactions SQL pass-through Returning objects from SQL queries 14
  • 15. DLinq Summary Allows access to relational data as objects Supports Language Integrated Query Works with existing infrastructure Unifies programming model for objects, relational and XML 15
  • 16. When to Use LINQ to SQL? The primary scenario for using LINQ to SQL is when building applications with a rapid development cycle and a simple one-to-one object to relational mapping against the Microsoft SQL Server family of databases. In other words, when building an application whose object model is structured very similarly to the existing database structure, or when a database for the application does not yet exist and there is no predisposition against creating a database schema that mirrors the object model 16
  • 17. When to Use LINQ to SQL? I want to… LINQ to SQL is applicable Use an ORM solution and my database is 1:1 with my object model Use an ORM solution with inheritance hierarchies that are stored in a single table Use my own plain CLR classes instead of using generated classes or deriving from a base class or implementing an interface Leverage LINQ as the way I write queries Use an ORM but I want something that is very performant and where I can optimize performance through stored procedures and compiled queries 17