SlideShare a Scribd company logo
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

PPT
Spark training-in-bangalore
PDF
Ado.Net
DOCX
DataBase Management System Lab File
PDF
PPTX
Unit 3 lecture-2
PPTX
R language introduction
PPT
Doctrine 2 - Introduction
Spark training-in-bangalore
Ado.Net
DataBase Management System Lab File
Unit 3 lecture-2
R language introduction
Doctrine 2 - Introduction

What's hot (20)

PDF
PPS
Ado.net session04
PPT
List moderate
PPTX
Big Data & Analytics MapReduce/Hadoop – A programmer’s perspective
 
PPT
Xml processing-by-asfak
PPS
Ado.net session01
PPTX
Unit 3 writable collections
PPS
Ado.net session07
PPT
Sedna XML Database: Query Parser & Optimizing Rewriter
DOC
Sql server
PPTX
Summary of "Amazon's Dynamo" for the 2nd nosql summer reading in Tokyo
PPTX
Triplestore and SPARQL
PDF
Apache Hadoop Java API
PDF
Ds lists
PDF
Overloading in Overdrive: A Generic Data-Centric Messaging Library for DDS
PPT
XQuery Triggers in Native XML Database Sedna
PDF
Beyond Map/Reduce: Getting Creative With Parallel Processing
PDF
PDF
R Introduction
PPT
Architecture of Native XML Database Sedna
Ado.net session04
List moderate
Big Data & Analytics MapReduce/Hadoop – A programmer’s perspective
 
Xml processing-by-asfak
Ado.net session01
Unit 3 writable collections
Ado.net session07
Sedna XML Database: Query Parser & Optimizing Rewriter
Sql server
Summary of "Amazon's Dynamo" for the 2nd nosql summer reading in Tokyo
Triplestore and SPARQL
Apache Hadoop Java API
Ds lists
Overloading in Overdrive: A Generic Data-Centric Messaging Library for DDS
XQuery Triggers in Native XML Database Sedna
Beyond Map/Reduce: Getting Creative With Parallel Processing
R Introduction
Architecture of Native XML Database Sedna
Ad

Viewers also liked (20)

PDF
Phan ii quytrinhkythuatkhaithacmuvachamsoc
PPT
Progress 4 C Association Workshop Dalat 04122009
PDF
K51.24.05.2009
PDF
Chuong 09 vb
PPT
Technology Integration
PDF
SharePoint Jumpstart
PPT
Technology In The Classroom
PDF
Tcvn 3769 2004
PDF
Rsn dec2008
PPT
Pres Outline Da Lat En
PPT
ITC Project Toads and Frogs
PPT
CHỌN GIỐNG
PPT
The North Country Trail
PPT
Technology In The Classroom
PDF
Pdf Slideshare R
PPT
PDF
Vegetables. growing asparagus in the home garden
KEY
Blockbuster Everything...
PDF
Excel 2007 bai 2-1
PPT
Hmt Health Claims Brussels 1 December Pw
Phan ii quytrinhkythuatkhaithacmuvachamsoc
Progress 4 C Association Workshop Dalat 04122009
K51.24.05.2009
Chuong 09 vb
Technology Integration
SharePoint Jumpstart
Technology In The Classroom
Tcvn 3769 2004
Rsn dec2008
Pres Outline Da Lat En
ITC Project Toads and Frogs
CHỌN GIỐNG
The North Country Trail
Technology In The Classroom
Pdf Slideshare R
Vegetables. growing asparagus in the home garden
Blockbuster Everything...
Excel 2007 bai 2-1
Hmt Health Claims Brussels 1 December Pw
Ad

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

PPT
L2s 090701234157 Phpapp02
PPTX
Ado.net
PPT
Lecture 6. ADO.NET Overview.
PPT
Introduction to ado
DOCX
Ado dot net complete meterial (1)
PPT
ADO .Net
PDF
Intake 37 linq3
PPT
Ado.net
PPT
Chapter 4 event it theory programming.pptx
PPTX
NHibernate
PPTX
Chapter 3: ado.net
PPTX
05 entity framework
PPT
PPT
Chap14 ado.net
PPT
ADO.NET
PPTX
Ch06 ado.net fundamentals
PDF
Tutorial On Database Management System
PPTX
Linq to sql
PPT
Dbms & prog lang
PPT
Understanding linq
L2s 090701234157 Phpapp02
Ado.net
Lecture 6. ADO.NET Overview.
Introduction to ado
Ado dot net complete meterial (1)
ADO .Net
Intake 37 linq3
Ado.net
Chapter 4 event it theory programming.pptx
NHibernate
Chapter 3: ado.net
05 entity framework
Chap14 ado.net
ADO.NET
Ch06 ado.net fundamentals
Tutorial On Database Management System
Linq to sql
Dbms & prog lang
Understanding linq

More from Shahriar Hyder (9)

PPTX
Effective Communication Skills for Software Engineers
DOCX
A JavaScript Master Class - From the Wows to the WTFs
PPTX
Dependency Inversion Principle
PPTX
Bridge Design Pattern
PPT
Command Design Pattern
PPTX
Taking a Quantum Leap with Html 5 WebSocket
PPTX
Functional Programming Fundamentals
PPT
C# 3.0 Language Innovations
PPT
Introduction to Linq
Effective Communication Skills for Software Engineers
A JavaScript Master Class - From the Wows to the WTFs
Dependency Inversion Principle
Bridge Design Pattern
Command Design Pattern
Taking a Quantum Leap with Html 5 WebSocket
Functional Programming Fundamentals
C# 3.0 Language Innovations
Introduction to Linq

Recently uploaded (20)

PDF
Transforming Manufacturing operations through Intelligent Integrations
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Spectroscopy.pptx food analysis technology
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Advanced Soft Computing BINUS July 2025.pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Modernizing your data center with Dell and AMD
PPT
Teaching material agriculture food technology
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Cloud computing and distributed systems.
PPTX
Big Data Technologies - Introduction.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
NewMind AI Monthly Chronicles - July 2025
Transforming Manufacturing operations through Intelligent Integrations
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Spectral efficient network and resource selection model in 5G networks
Dropbox Q2 2025 Financial Results & Investor Presentation
Spectroscopy.pptx food analysis technology
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Advanced Soft Computing BINUS July 2025.pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Modernizing your data center with Dell and AMD
Teaching material agriculture food technology
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
NewMind AI Weekly Chronicles - August'25 Week I
Network Security Unit 5.pdf for BCA BBA.
Cloud computing and distributed systems.
Big Data Technologies - Introduction.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
NewMind AI Monthly Chronicles - July 2025

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