L2s 090701234157 Phpapp02

7,803 views
7,760 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
7,803
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • 09/13/09 07:13 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • 09/13/09 07:13 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • 09/13/09 07:13 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • 09/13/09 07:13 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • 09/13/09 07:13 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • 09/13/09 07:13 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • 09/13/09 07:13 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • 09/13/09 07:13 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • 09/13/09 07:13 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • 09/13/09 07:13 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • 09/13/09 07:13 ©2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • L2s 090701234157 Phpapp02

    1. 1. OR Impedance Mismatch
    2. 2. OR Impedance Mismatch <ul><li>Conflicting type systems </li></ul><ul><li>Conflicting design goals </li></ul><ul><ul><li>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 </li></ul></ul><ul><li>Conflicting architectural style </li></ul><ul><ul><li>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. </li></ul></ul><ul><li>Differing structural relationships </li></ul><ul><ul><li>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 </li></ul></ul>
    3. 3. OR Impedance Mismatch <ul><li>Differing identity constructs </li></ul><ul><ul><li>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. </li></ul></ul><ul><li>Transactional boundaries </li></ul><ul><ul><li>Object systems do not have any sense of &quot;transactional demarcation&quot; 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 . </li></ul></ul><ul><li>Query/access capabilities </li></ul><ul><ul><li>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. </li></ul></ul>
    4. 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 &quot;virtual object database,&quot; 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.
    5. 5. The LINQ Project Standard Query Operators DLinq (ADO.NET) XLinq (System.Xml) .NET Language Integrated Query C# VB Others… Objects <book> <title/> <author/> <year/> <price/> </book> XML SQL WinFS
    6. 6. Data Access In APIs Today SqlConnection c = new SqlConnection(…); c.Open(); SqlCommand cmd = new SqlCommand( @&quot;SELECT c.Name, c.Phone FROM Customers c WHERE c.City = @p0&quot; ); cmd.Parameters.AddWithValue(&quot;@po&quot;, &quot;London&quot;); DataReader dr = c.Execute(cmd); while (dr.Read()) { string name = dr.GetString(0); string phone = dr.GetString(1); DateTime date = dr.GetDateTime(2); } dr.Close(); Queries in quotes Arguments loosely bound Results loosely typed Compiler cannot help catch mistakes
    7. 7. Data Access with DLINQ public class Customer { public int Id; public string Name; public string Phone; … } Table<Customer> customers = db.Customers; var contacts = from c in customers where c.City == &quot;London&quot; select new { c.Name, c.Phone }; Classes describe data Tables are collections Query is natural part of the language The compiler helps you out
    8. 8. DLinq For Relational Data public class Customer { … } public class Northwind: DataContext { public Table<Customer> Customers; … } Northwind db = new Northwind( … ); var contacts = from c in db.Customers where c.City == &quot;London&quot; select new { c.Name, c.Phone }; Accessing data with DLinq Classes describe data Strongly typed connection Integrated query syntax Strongly typed results Tables are like collections
    9. 9. Architecture LINQ Query Objects SubmitChanges() SQL Query from c in db.Customers where c.City == &quot;London&quot; select new { c.Name, c.Phone } select Name, Phone from customers where city = 'London' Rows SQL or Stored Procs DLinq (ADO.NET) SQLServer Application Services: - Change tracking - Concurrency control - Object identity
    10. 10. Key Takeaways <ul><li>Language integrated data access </li></ul><ul><ul><li>Maps tables and rows to classes and objects </li></ul></ul><ul><ul><li>Builds on ADO.NET and .NET Transactions </li></ul></ul><ul><li>Mapping </li></ul><ul><ul><li>Encoded in attributes </li></ul></ul><ul><ul><li>Relationships map to properties </li></ul></ul><ul><ul><li>Manually authored or tool generated </li></ul></ul><ul><li>Persistence </li></ul><ul><ul><li>Automatic change tracking </li></ul></ul><ul><ul><li>Updates through SQL or stored procedures </li></ul></ul><ul><li>DataContext </li></ul><ul><ul><li>Strongly typed database </li></ul></ul>
    11. 11. Querying For Objects
    12. 12. Key Takeaways <ul><li>Language Integrated Query </li></ul><ul><ul><li>Compile-time type checking, IntelliSense </li></ul></ul><ul><li>SQL-like query syntax </li></ul><ul><ul><li>With support for hierarchy and relationships </li></ul></ul><ul><li>Intelligent object loading </li></ul><ul><ul><li>Deferred or immediate </li></ul></ul>
    13. 13. Updating Objects
    14. 14. Key Takeaways <ul><li>Auto-generated updates </li></ul><ul><ul><li>Using optimistic concurrency </li></ul></ul><ul><li>Transactions </li></ul><ul><ul><li>Integrates with System.Transactions </li></ul></ul><ul><li>SQL pass-through </li></ul><ul><ul><li>Returning objects from SQL queries </li></ul></ul>
    15. 15. DLinq Summary <ul><li>Allows access to relational data as objects </li></ul><ul><li>Supports Language Integrated Query </li></ul><ul><li>Works with existing infrastructure </li></ul><ul><li>Unifies programming model for objects, relational and XML </li></ul>
    16. 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
    17. 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

    ×