Presented by: Scott Guthrie
These are “live” notes and necessarily rough.
Today’s Problem: Data != Objects
Traditional data access includes a mixture of languages (SQL and native code), arguments loosely bound, results loosely typed, compiler cannot help catch mistakes and queries in quotes within the code.
In LINQ, classes describe data. There is encapsulated business validation. A query is a natural part of the language and the compiler provides intellisense and type-checking.
LINQ can query against objects, relational, and XML. Also, LINQ enabled ADO.NET - LINQ to Datasets, LINQ to SQL, LINQ to Entities. Plugin architecture, can create new “LINQ to” modules.
LINQ Basics
Query operators can be used against any .NET collection (IEnumerable)
- Built-in examples: Select, Where, GroupBy, Join, etc.
- Extensibility model supports adding/replacing them
Query Expressions can operate on information sources and apply query operators against them to return IEnumberable sequences. Chain operators together.
Projections
- Take results from expression and modify it in a different way
- Enables “data shaping” in query expressions
Projections w/ Anonymous Types makes the compiler create an object with the properties of the type on the right-hand assignment of the first assignment. Still strongly typed at runtime. Very cool.
LINQ to SQL
- Maps .NET classes to relational SQL data
- translates LINQ queries to SQL execution
- Supports change tracking for insert, update, delete operations
- supports entity-level validation rules
- built on top of ADO.NET and integrates with connection-pooling and transactions
Associations
- Usually expressed with PK/FK
- Relationships inferred from FK
LINQ can implement server-side paging and complicated joins.
LINQ different from embedded SQL in that it is strongly typed and can also query against different data sources, not just relational databases.
LINQ for SQL Architecture Services:
- Change tracking
- Concurrency control
- Object identity
db.SubmitChanges() will generate SQL code to update database. Can drop down and put in your own SQL or stored procedure, but really shouldn’t do this unless really necessary.
Implicit or explicit transaction scope.
BLINQ
- UI scaffold
- Point to DB and it will create CRUD pages
- Generates LINQ for SQL data model
- Easy way to quickly build CRUD pages against data models
- Free download today
LINQ for Entities
- Entity Data Model (EDM) enables rich conceptual modeling of data
- Entities can be split across multiple tables, and support rich inheritance
- Higher level of abstraction
- Full LINQ support over EDM definitions
LINQ to XML
- Declarative construction of XML document
- Support for language integrated queries
- Cleaner, simpler, smaller and faster XML API
- Does XML TextReader for you
There was lots of stuff in this presentation, so check out the slides, especially for the code samples.
Fin.
Post a Comment