Escolar Documentos
Profissional Documentos
Cultura Documentos
OR Impedance Mismatch
2
OR Impedance Mismatch
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…
Standard
DLinq XLinq
Query
(ADO.NET) (System.Xml)
Operators
<book>
<title/>
<author/>
<year/>
<price/>
</book>
Queries in
SqlConnection c = new SqlConnection(…);
c.Open(); quotes
SqlCommand cmd = new SqlCommand(
@"SELECT c.Name, c.Phone Arguments
FROM Customers c loosely bound
WHERE c.City = @p0"
);
Results
cmd.Parameters.AddWithValue("@po",
loosely typed
"London");
DataReader dr = c.Execute(cmd); Compiler
while (dr.Read()) { cannot help
string name = dr.GetString(0); catch
string phone = dr.GetString(1); mistakes
Data Access with DLINQ
Services:
DLinq - Change tracking
- Concurrency control
(ADO.NET) - Object identity
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
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
17