SlideShare ist ein Scribd-Unternehmen logo
1 von 75
www.sungard.com/consulting
C# 3.0 and LINQ: Tech Talk
Michael Heydt
Senior Manager, NYC FST
SunGard Consulting Services
October 2008
Agenda
 New C# 3.0 Constructs
 What is and why use LINQ?
 LINQ “Flavors”
 Architecture
 Examples / Demos
 Adoption
 Strengths and Weaknesses
 Closing
C# 3.0 New Constructs
 Automatic Properties
 Object and collection Initializers
 Inferred types
 Anonymous types
 Partial Methods
 Lambda methods
 Extension methods
 Query expressions
 Expression Trees
Automatic Properties
 Reduces coding on most property declarations
 Used by LINQ to handle projection into anonymous
classes
 As a matter of fact, this is critical to anonymous class
definition
Automatic Properties
Object and Collection Initializers
 Allow assignment of fields or properties of an object
at creation time without having to explicitly invoke a
constructor
 Used to define and initialize properties in anonymous
classes by LINQ
– Anonymous types are difficult, if not impossible, to initialize
without them
– Potential or exponential combinations of constructors
 Is very handy for collection initialization
Object and Collection Initializers
Object and Collection Initializers
 Collection Initialization
– Could not do this before:
Inferred Types
 The type of the variables is inferred from the data
assigned to it
 Utilizes the “var” keyword
 Strongly typed, not like in JavaScript
 Required to support LINQ creating anonymous types
as query results using automatic property initialization
 Can greatly simplify code as query results fields can
be changed without having to recode an intermediate
query results class
 Local only
– Cannot be a member or returned from a method
– Compiler cannot infer outside of local context
Inferred Types
Anonymous Types
 A type automatically inferred and created from object
initializers
 Very useful for projections in query results
 Requires inferred types
 Compiler generates a class under the covers
– And default equivalence methods
– Types are considered the same if there are the same
properties and types
 Class has no methods
Anonymous Types
Partial Methods
 Allows definition of a method, and someone else to
implement
 If not implemented, no IL is generated
 Useful for customizing generated code
 A good example is pre and post validation calls
 Used extensively in the LINQ to SQL designer for
property changing and data validation events
Partial Methods
 Partial method declarations must begin with the
contextual keyword partial and the method must
return void.
 Partial methods can have ref but not out parameters.
 Partial methods are implicitly private, and therefore
they cannot be virtual.
 Partial methods cannot be extern, because the
presence of the body determines whether they are
defining or implementing.
 Partial methods can have static and unsafe modifiers.
Partial Methods
 Partial methods can be generic. Constraints are put
on the defining partial method declaration, and may
optionally be repeated on the implementing one.
Parameter and type parameter names do not have to
be the same in the implementing declaration as in the
defining one.
 You cannot make a delegate to a partial method.
Partial Methods
Lambda Methods
 Integral part of LINQ for specifying queries
 Replace C# 2.0 anonymous delegates
 Gives cleaner syntax for defining delegates
– No need to declare a delegate
– Just define the anonymous method at the point you want to
use it
 Leads to great reductions in code complexity
 Format:
– ( parameters ) => { code };
Lambda Methods
Lambda Methods in a Query
Extension Methods
 A means of defining extensions to existing types
 Allows the appearance of adding new methods to
classes which you don’t have access to the source
 Also used extensively for code generation of
extensibility points
 Used by LINQ to add query methods to existing
framework classes via System.Link assembly
 Declared within static classes using the this keyword
 Can be used to extend sealed classes
Extension Methods
Query Expressions
 Query expressions add SQL like syntax to the
language
 Allows specification of queries without using external
tools or syntax
 Components
– From: Defines what data to start with
– Where: Conditional selection
– Select: Projects the result set
 Supports concepts of joins
– Use multiple “from”’s
– Basically creates nested loops (but a little more elaborate)
Query Expressions
Query Expressions - Example
Query Expressions - Example
Expression Trees
 Query expressions are converted into expression
trees
 An expression tree is a data structure representing
an expression
 You can also build expressions trees dynamically
Expression Trees
What is LInQ?
 LInQ = Language Integrated Query
 Internal DSL to .NET Languages for querying objects
 Many consider it an ORM. It is not an ORM
– But LINQ 2 SQL is an extension that provides ORM
capabilities
 It is much more than an ORM
– Integrated query language: runtime and compiler
– Query Optimization
– Object “projection”
 LINQ syntax looks like SQL, but it is much different
What is LINQ?
 It provides for allows query across any enumerable
object collections
– Just about any IEnumerable<T> can be used in queries
– If the backing store is not understood by the compiler, you
can build a “provider” to explain it.
 Provides a standard means of querying collections of
CLR objects, databases (RDBMS) and XML
 Provides for compile-time query development and
syntax checking which leads to less errors
What is LInQ’s Value Proposition?
 No context shift when needing to query collections of
objects to find the object that you want
 Not just an ORM
– LInQ to SQL does do that, but it really is about managing
query, construction and update of objects independent of
storage (memory, document, file or RDBMS)
 An attempt to provide a single means of query,
instead of:
– SQL for RDBMS
– XPath and XQuery for XML
– Custom code for objects
 Identification of query errors at compile time instead
of run-time
 Rapid development of queries through tool support
How can LInQ Make you more Effective?
 Quicker time to deployment
– Rapid development
 Less errors
– Type safe query based upon object and database metadata
 Performance
– Optimized at the provider level
– Integrated into the language and runtime, so no context shift
at runtime
 Single Model for Query
– Similar query structure for all data types
 Less code
– Write less query code
– Also can be used to facilitate object construction which can
greatly reduce code base
Competition (1)
 Nhibernate
– Open source ORM tool, very popular, based on Hibernate
– Proprietary query language, no language integration
– Unweildy XML configuration files
– Realy only competes with LINQ to SQL
 CSLA
– .NET framework for object distribution and database
mapping offered by Rocky Lhotka
– Has some traction, but tries to solve many issues and is
relatively weak in ORM capabilities
– Kind of an ORM, but no real built in query
Competition (2)
 ActiveRecord
– Design pattern for representing rows of tables in and ORM
– Comes from Fowler, very popular in Ruby on Rails
– Limited to operations on single tables
– Primary implementation is Castle ActiveRecord
– No integrated query
 Rhino-Commons
– Open source extensions to Castle ActiveRecord (and Rhino
Mocks)
– Big part of the Alt.NET toolset
– Makes ActiveRecord even easier
– Also no query
Competition (3)
 Microsoft Entity Framework
– Microsoft’s higher level data abstraction model
– Uses LInQ under the covers for query and physical table
mapping
– First Generation
– Uses LINQ for query, but real functionality is in providing
multi-database and object partitioning across multiple
physical sources
LINQ Ecosystem
Flavors of LInQ
 LInQ to Objects
– Can query any IEnumerable set of object(s)
– Uses runtime metadata
 LInQ to SQL
– Requires adornment of objects with attributes to provide
mapping to RDBMS
 LInQ to DataTable
– Provides ability to query data returned from ADO.NET via
DataTable object without having to use the built in and
difficult to use query constructs
 LInQ to XML
– XDocument class is LInQ aware, allowing query of XML with
LInQ syntax instead of Xpath
 LInQ to Entities
– Provides query across Entity Framework Objects
LInQ Architecture (1)
 Required extensions to the CLR languages for:
– Lambda functions
– Partial Methods
– Extension methods
– Collection initializers
– Type inference
– Object Initializers
– Automatic Properties
– Anonymous Types
– Expression Trees
LInQ Architecture (2)
 Query structure - Comprehension Model
– From (where is the data coming from)
– Where (filter out on a criteria)
– Select (and select only the data you need)
– Join, group, orderby, …
 This is an internal DSL that is translated into method
calls
LInQ Architecture (3)
 Provider model (the context)
– Can root queries and be used to
 Track object changes
 Execute transactions
 Generate native queries
 Defer execution or eager load data
– Important note:
 Change tracking is optimistic, and
 Requires projection of the full table objects (all
columns). Partial classes are not supported as
missing data may be changed by a third party.
LInQ Architecture (4)
 Lambda Expressions
– Comprehension is converted to the compiler to this format
 Query is typically not executed until…
– LInQ query IS NOT executed at declaration
– The variable is simply a holder for the expression
– Query IS started when the variable is iterated
 This is very important!
– It can be confusing at first
How do you use LInQ?
 Typically, you write a query in comprehension mode
– The compiler converts it to Lamba format
 In LinQ to objects
– A series of decorators is created that feeds… data from one
to the next, each triggered by enumeration
 In LInQ to SQL
– SQL is created and data is mapped to CLR objects
– Chain of decorators may be handled explicitly by the SQL
 In LInQ to XML
– XPath is generated to manipulate the DOM
 Objects are then “Projected” into results
– Can be a strongly typed class, or an anonymous class
– Can contain all properties of the selected objects, or just a
subset
LInQ Query Structure
All the same Query
Comprehension Query
Lambda Queries
What’s Going On?
A progressive filtering of data through the parts of the query
Triggered on the enumerators
Local Query Execution and Deferral
The query becomes a set of enumerators
decorated by a different type of functionality
and criteria
Subqueries
Subqueries
LINQ to SQL
 Operates using a data context object
– Entry point to the database
– Performs change tracking
 Attribute base declaration of mapping of classes to
database tables
 Automatic identification of primary/foreign keys for
relationships
LINQ to SQL
 If using the designer, you get:
– automatic creation of extension point for data validation and
property change
– Ability to map insert/delete/update/query to stored
procedures
– Automatic handling of updates of key relationships
– Automatic transaction processing
– Server side paging
If you don’t use the designer
 You can manually annotate classes
– And you must implement the other features like property
change notification yourself
 Or you can also use XML configuration files
– But there is not a “fluent” interface at this point
LINQ to SQL
 DataContext class can be extended with partial
classes to:
– Override default generation of SQL into stored procs
– Override default generation of SQL into custom SQL
– Objects returned by either of these will also participate in
change management
 This is very powerful as it allows:
– Rapid development of queries first using comprehension
queries
– Later migration of queries into stored procs
– Data access code will remain the same
– Data validation code will still be valid in either context
LINQ to SQL
 Other items of importance
– AsQueryable vs AsEnumerable
– Optimistic locking / ChangeConflicts
 Coupling
– DBML tight couples to database, but is easy
– XML loose couples, but you have to code more
 Stored procedures?
– Can be used for CRUD on DBML objects
– Or called directly as methods on the data context
DBML
Generated Code (1)
Generated Code (2)
Using XML Configuration
LINQ to XML
 System.Xml.Linq namespace
 XDocument class
– Provides new XML API that is LINQ aware
– Other classes: XElement, XAttribute, XNode
 You can:
– Create XML documents from the results of queries
– Query XML documents and return XML or objects
 Can be used to provide a natural query language to
XML documents instead of Xpath/Xquery
LINQ to XML Example – DB to XML
Another
XML to Objects
LInQ Demonstration(s)
 A basic query structure on strings (linq to objects)
 Query across objects
– summing data
– grouping and projecting
 Mapping objects to RDBMS
 RDBMS query
 RDBMS relationships (lazy and eager load)
 RDBMS update
 Multi-result / multi-shape query
 Data binding to anonymous query results
 Simplification of XML manipulation
– Query data
– Create documents
Maturity
 Available for 3+ years in CTP form
 Released in .NET 3.0 (~ fall 2007)
 Rock solid with Linq to Objects, SQL Server
 No current support for Oracle from either MS or
Oracle (there is a codeplex project)
Strengths and Weaknesses
Strengths
 Standard object query
language
 Tool integration
 Pervasive
 Deferred execution
 Great model for
manipulating objects
instead of explicit code
 Easier configuration
compared to other tools
Weaknesses
 Not good support for ad-
hoc queries
 Currently only supports
SQL Server
 It is a new tool to learn
 Different from SQL
 Tight coupling to SQL
database
Adopting LInQ
 Start with query over objects
 Move to XML query / creating XML objects
 Use for rapid development, query development, unit
testing (agile development)
 Teach to developers and data analysts
 Create role of “business object designer” to work with
DBA’s to build data access layers in LInQ combined
with the efforts of the DBA’s.
 Release dal’s to programmers to use as a unified
object model.
 Migrate queries to CRUD stored procedures
Futures
 Parallel LInQ
– http://channel9.msdn.com/shows/Going+Deep/Inside-
Parallel-Extensions-for-NET-2008-CTP-Part-1/
Learning LInQ
 Books
– Apress: Pro LINQ: Language Integrated Query in C# 2008
– Apress: Pro LINQ Object Relational Mapping in C# 2008
– Oreilly: LINQ: The Future of Data Access in C# 3.0
 Web sites
– Scott Guthrie: http://weblogs.asp.net/scottgu
– Bill Wagner: http://srtsolutions.com/blogs/billwagner/
– www.hookedonlinq.com
 Podcasts
– Dotnetrocks.com
– DNRTV.com
Tools
 Visual LINQ: http://code.msdn.microsoft.com/vlinq
 LINQPad: http://www.linqpad.net/
 LINQ Debug Visualizer:
– http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-
sql-debug-visualizer.aspx
Q&A
 Solicit general customer questions about LInQ (be
prepared for these – think ahead of them)
– I’m scared of not using stored procs…
– I’m not using that level of .NET yet…
– How does this fit with legacy systems?
– What about my DBA’s?
– Who else is using LInQ? What have their experiences
been?
– How does LInQ fit into agile?
 Proactively solicit information on LInQ from customer
about how they can use LInQ
– Look for a few strategic inroads to follow… Such as:
– Training / mentoring
– Proof of concepts
– Ask them how they think they can use it
Contact
Michael Heydt
Senior Manager
(610) 772-5556 Cell
michael.heydt@sungard.com
mike@heydt.org
www.42spikes.com
CONFIDENTIALITY STATEMENT
Copyright © 2008 by SunGard Data Systems Inc. (or its subsidiaries, “SunGard”). All rights reserved. No parts
of this document may be reproduced, transmitted or stored electronically without SunGard’s prior written
permission.
This document contains SunGard's confidential or proprietary information. By accepting this document, you
agree that: (A)(1) if a pre-existing contract containing disclosure and use restrictions exists between your
company and SunGard, you and your company will use this information subject to the terms of the pre-existing
contract; or (2) if no such pre-existing contract exists, you and your Company agree to protect this information
and not reproduce or disclose the information in any way; and (B) SunGard makes no warranties, express or
implied, in this document, and SunGard shall not be liable for damages of any kind arising out of use of this
document.
About SunGard Consulting Services
SunGard Consulting Services’ deep understanding of business processes in financial services and energy,
together with our expertise in information technology and knowledge of SunGard products, helps us mitigate
project risk and provide a single point of accountability for SunGard projects that differentiates us from other
consulting organizations.
Elevators
 The LINQ Project is a codename for a set of
extensions to the .NET Framework that encompass
language-integrated query, set, and transform
operations. It extends C# and Visual Basic with native
language syntax for queries and provides class
libraries to take advantage of these capabilities.
 LINQ defines a set of query operators that can be used to query,
project and filter data in arrays, enumerable classes, XML,
relational database, and third party data sources. While it allows
any data source to be queried, it requires that the data be
encapsulated as objects. So, if the data source does not
natively store data as objects, the data must be mapped to the
object domain. Queries written using the query operators are
executed either by the LINQ query processing engine or, via an
extension mechanism, handed over to LINQ providers which
either implement a separate query processing engine or
translate to a different format to be executed on a separate data
store (such as on a database server as SQL queries). The
results of a query are returned as a collection of in-memory
objects that can be enumerated.
Group By
 Important to note that this really returns a dictionary
Notes
 Lazy load required EntityRef
 XML Mapping files can be used
 LINQ grammer is not the same as SQL
 Right outer joins must be flipped to left

Weitere ähnliche Inhalte

Was ist angesagt?

Advanced Document Similarity With Apache Lucene
Advanced Document Similarity With Apache LuceneAdvanced Document Similarity With Apache Lucene
Advanced Document Similarity With Apache LuceneAlessandro Benedetti
 
Haystack London - Search Quality Evaluation, Tools and Techniques
Haystack London - Search Quality Evaluation, Tools and Techniques Haystack London - Search Quality Evaluation, Tools and Techniques
Haystack London - Search Quality Evaluation, Tools and Techniques Andrea Gazzarini
 
Building reactive systems with Akka
Building reactive systems with AkkaBuilding reactive systems with Akka
Building reactive systems with AkkaKristof Jozsa
 
[2016/2017] Architectural languages
[2016/2017] Architectural languages[2016/2017] Architectural languages
[2016/2017] Architectural languagesIvano Malavolta
 
Neural Architectures for Named Entity Recognition
Neural Architectures for Named Entity RecognitionNeural Architectures for Named Entity Recognition
Neural Architectures for Named Entity RecognitionRrubaa Panchendrarajan
 
Beyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software ArchitectureBeyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software ArchitectureJayaram Sankaranarayanan
 
The Evolution of Scala
The Evolution of ScalaThe Evolution of Scala
The Evolution of ScalaMartin Odersky
 
Evaluating Your Learning to Rank Model: Dos and Don’ts in Offline/Online Eval...
Evaluating Your Learning to Rank Model: Dos and Don’ts in Offline/Online Eval...Evaluating Your Learning to Rank Model: Dos and Don’ts in Offline/Online Eval...
Evaluating Your Learning to Rank Model: Dos and Don’ts in Offline/Online Eval...Sease
 
Search Quality Evaluation to Help Reproducibility : an Open Source Approach
Search Quality Evaluation to Help Reproducibility : an Open Source ApproachSearch Quality Evaluation to Help Reproducibility : an Open Source Approach
Search Quality Evaluation to Help Reproducibility : an Open Source ApproachAlessandro Benedetti
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to ScalaRahul Jain
 
9 subprograms
9 subprograms9 subprograms
9 subprogramsjigeno
 
Text categorization with Lucene and Solr
Text categorization with Lucene and SolrText categorization with Lucene and Solr
Text categorization with Lucene and SolrTommaso Teofili
 
Tech Days 2015: A quick tour of Ada 2012
Tech Days 2015: A quick tour of Ada 2012Tech Days 2015: A quick tour of Ada 2012
Tech Days 2015: A quick tour of Ada 2012AdaCore
 
Scalaマクロ入門 bizr20170217
Scalaマクロ入門 bizr20170217 Scalaマクロ入門 bizr20170217
Scalaマクロ入門 bizr20170217 dcubeio
 

Was ist angesagt? (20)

Advanced Document Similarity With Apache Lucene
Advanced Document Similarity With Apache LuceneAdvanced Document Similarity With Apache Lucene
Advanced Document Similarity With Apache Lucene
 
Haystack London - Search Quality Evaluation, Tools and Techniques
Haystack London - Search Quality Evaluation, Tools and Techniques Haystack London - Search Quality Evaluation, Tools and Techniques
Haystack London - Search Quality Evaluation, Tools and Techniques
 
Building reactive systems with Akka
Building reactive systems with AkkaBuilding reactive systems with Akka
Building reactive systems with Akka
 
Preparing for Scala 3
Preparing for Scala 3Preparing for Scala 3
Preparing for Scala 3
 
Simplicitly
SimplicitlySimplicitly
Simplicitly
 
[2016/2017] Architectural languages
[2016/2017] Architectural languages[2016/2017] Architectural languages
[2016/2017] Architectural languages
 
Linq in C#
Linq in C#Linq in C#
Linq in C#
 
Neural Architectures for Named Entity Recognition
Neural Architectures for Named Entity RecognitionNeural Architectures for Named Entity Recognition
Neural Architectures for Named Entity Recognition
 
Beyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software ArchitectureBeyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software Architecture
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
The Evolution of Scala
The Evolution of ScalaThe Evolution of Scala
The Evolution of Scala
 
Presentation on java
Presentation  on  javaPresentation  on  java
Presentation on java
 
Evaluating Your Learning to Rank Model: Dos and Don’ts in Offline/Online Eval...
Evaluating Your Learning to Rank Model: Dos and Don’ts in Offline/Online Eval...Evaluating Your Learning to Rank Model: Dos and Don’ts in Offline/Online Eval...
Evaluating Your Learning to Rank Model: Dos and Don’ts in Offline/Online Eval...
 
Search Quality Evaluation to Help Reproducibility : an Open Source Approach
Search Quality Evaluation to Help Reproducibility : an Open Source ApproachSearch Quality Evaluation to Help Reproducibility : an Open Source Approach
Search Quality Evaluation to Help Reproducibility : an Open Source Approach
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
9 subprograms
9 subprograms9 subprograms
9 subprograms
 
Text categorization with Lucene and Solr
Text categorization with Lucene and SolrText categorization with Lucene and Solr
Text categorization with Lucene and Solr
 
Tech Days 2015: A quick tour of Ada 2012
Tech Days 2015: A quick tour of Ada 2012Tech Days 2015: A quick tour of Ada 2012
Tech Days 2015: A quick tour of Ada 2012
 
Scalaマクロ入門 bizr20170217
Scalaマクロ入門 bizr20170217 Scalaマクロ入門 bizr20170217
Scalaマクロ入門 bizr20170217
 

Ähnlich wie C# 3.0 and LINQ Tech Talk

C#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New FeaturesC#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New Featurestechfreak
 
Linq To The Enterprise
Linq To The EnterpriseLinq To The Enterprise
Linq To The EnterpriseDaniel Egan
 
New c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNew c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNico Ludwig
 
New c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNew c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNico Ludwig
 
LINQ 2 SQL Presentation To Palmchip And Trg, Technology Resource Group
LINQ 2 SQL Presentation To Palmchip  And Trg, Technology Resource GroupLINQ 2 SQL Presentation To Palmchip  And Trg, Technology Resource Group
LINQ 2 SQL Presentation To Palmchip And Trg, Technology Resource GroupShahzad
 
Introducing object oriented programming (oop)
Introducing object oriented programming (oop)Introducing object oriented programming (oop)
Introducing object oriented programming (oop)Hemlathadhevi Annadhurai
 
Sumo Logic QuickStart Webinar - Jan 2016
Sumo Logic QuickStart Webinar - Jan 2016Sumo Logic QuickStart Webinar - Jan 2016
Sumo Logic QuickStart Webinar - Jan 2016Sumo Logic
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9google
 
Object- Relational Persistence in Smalltalk
Object- Relational Persistence in SmalltalkObject- Relational Persistence in Smalltalk
Object- Relational Persistence in SmalltalkESUG
 
Sumo Logic Quick Start - Feb 2016
Sumo Logic Quick Start - Feb 2016Sumo Logic Quick Start - Feb 2016
Sumo Logic Quick Start - Feb 2016Sumo Logic
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)David McCarter
 
Onion Architecture with S#arp
Onion Architecture with S#arpOnion Architecture with S#arp
Onion Architecture with S#arpGary Pedretti
 
Sumo Logic QuickStart
Sumo Logic QuickStartSumo Logic QuickStart
Sumo Logic QuickStartSumo Logic
 
Unboxing ASP.NET Core
Unboxing ASP.NET CoreUnboxing ASP.NET Core
Unboxing ASP.NET CoreKevin Leung
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)David McCarter
 

Ähnlich wie C# 3.0 and LINQ Tech Talk (20)

C#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New FeaturesC#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New Features
 
Linq To The Enterprise
Linq To The EnterpriseLinq To The Enterprise
Linq To The Enterprise
 
New c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNew c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_iv
 
New c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNew c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_iv
 
Entity Framework 4
Entity Framework 4Entity Framework 4
Entity Framework 4
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
LINQ 2 SQL Presentation To Palmchip And Trg, Technology Resource Group
LINQ 2 SQL Presentation To Palmchip  And Trg, Technology Resource GroupLINQ 2 SQL Presentation To Palmchip  And Trg, Technology Resource Group
LINQ 2 SQL Presentation To Palmchip And Trg, Technology Resource Group
 
Introducing object oriented programming (oop)
Introducing object oriented programming (oop)Introducing object oriented programming (oop)
Introducing object oriented programming (oop)
 
L06 Using Design Patterns
L06 Using Design PatternsL06 Using Design Patterns
L06 Using Design Patterns
 
Sumo Logic QuickStart Webinar - Jan 2016
Sumo Logic QuickStart Webinar - Jan 2016Sumo Logic QuickStart Webinar - Jan 2016
Sumo Logic QuickStart Webinar - Jan 2016
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9
 
70487.pdf
70487.pdf70487.pdf
70487.pdf
 
Object- Relational Persistence in Smalltalk
Object- Relational Persistence in SmalltalkObject- Relational Persistence in Smalltalk
Object- Relational Persistence in Smalltalk
 
Sumo Logic Quick Start - Feb 2016
Sumo Logic Quick Start - Feb 2016Sumo Logic Quick Start - Feb 2016
Sumo Logic Quick Start - Feb 2016
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
 
Onion Architecture with S#arp
Onion Architecture with S#arpOnion Architecture with S#arp
Onion Architecture with S#arp
 
Java basics
Java basicsJava basics
Java basics
 
Sumo Logic QuickStart
Sumo Logic QuickStartSumo Logic QuickStart
Sumo Logic QuickStart
 
Unboxing ASP.NET Core
Unboxing ASP.NET CoreUnboxing ASP.NET Core
Unboxing ASP.NET Core
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
 

Mehr von Michael Heydt

Natural User Interfaces in a Nutshel
Natural User Interfaces in a NutshelNatural User Interfaces in a Nutshel
Natural User Interfaces in a NutshelMichael Heydt
 
Continuous and Seamless Applications
Continuous and Seamless ApplicationsContinuous and Seamless Applications
Continuous and Seamless ApplicationsMichael Heydt
 
Using Azure for Computationally Intensive Workloads
Using Azure for Computationally Intensive WorkloadsUsing Azure for Computationally Intensive Workloads
Using Azure for Computationally Intensive WorkloadsMichael Heydt
 
NUX Presentation from TechMixer Birmingham 2011
NUX Presentation from TechMixer Birmingham 2011NUX Presentation from TechMixer Birmingham 2011
NUX Presentation from TechMixer Birmingham 2011Michael Heydt
 
Presentation on Cloud Mashups
Presentation on Cloud MashupsPresentation on Cloud Mashups
Presentation on Cloud MashupsMichael Heydt
 
Agile india 2014 Presentation
Agile india 2014 PresentationAgile india 2014 Presentation
Agile india 2014 PresentationMichael Heydt
 

Mehr von Michael Heydt (7)

Natural User Interfaces in a Nutshel
Natural User Interfaces in a NutshelNatural User Interfaces in a Nutshel
Natural User Interfaces in a Nutshel
 
Continuous and Seamless Applications
Continuous and Seamless ApplicationsContinuous and Seamless Applications
Continuous and Seamless Applications
 
Using Azure for Computationally Intensive Workloads
Using Azure for Computationally Intensive WorkloadsUsing Azure for Computationally Intensive Workloads
Using Azure for Computationally Intensive Workloads
 
NUX Presentation from TechMixer Birmingham 2011
NUX Presentation from TechMixer Birmingham 2011NUX Presentation from TechMixer Birmingham 2011
NUX Presentation from TechMixer Birmingham 2011
 
Presentation on Cloud Mashups
Presentation on Cloud MashupsPresentation on Cloud Mashups
Presentation on Cloud Mashups
 
Agile india 2014 Presentation
Agile india 2014 PresentationAgile india 2014 Presentation
Agile india 2014 Presentation
 
Social Machines
Social MachinesSocial Machines
Social Machines
 

Kürzlich hochgeladen

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
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
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
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
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 

Kürzlich hochgeladen (20)

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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...
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

C# 3.0 and LINQ Tech Talk

  • 1. www.sungard.com/consulting C# 3.0 and LINQ: Tech Talk Michael Heydt Senior Manager, NYC FST SunGard Consulting Services October 2008
  • 2. Agenda  New C# 3.0 Constructs  What is and why use LINQ?  LINQ “Flavors”  Architecture  Examples / Demos  Adoption  Strengths and Weaknesses  Closing
  • 3. C# 3.0 New Constructs  Automatic Properties  Object and collection Initializers  Inferred types  Anonymous types  Partial Methods  Lambda methods  Extension methods  Query expressions  Expression Trees
  • 4. Automatic Properties  Reduces coding on most property declarations  Used by LINQ to handle projection into anonymous classes  As a matter of fact, this is critical to anonymous class definition
  • 6. Object and Collection Initializers  Allow assignment of fields or properties of an object at creation time without having to explicitly invoke a constructor  Used to define and initialize properties in anonymous classes by LINQ – Anonymous types are difficult, if not impossible, to initialize without them – Potential or exponential combinations of constructors  Is very handy for collection initialization
  • 7. Object and Collection Initializers
  • 8. Object and Collection Initializers  Collection Initialization – Could not do this before:
  • 9. Inferred Types  The type of the variables is inferred from the data assigned to it  Utilizes the “var” keyword  Strongly typed, not like in JavaScript  Required to support LINQ creating anonymous types as query results using automatic property initialization  Can greatly simplify code as query results fields can be changed without having to recode an intermediate query results class  Local only – Cannot be a member or returned from a method – Compiler cannot infer outside of local context
  • 11. Anonymous Types  A type automatically inferred and created from object initializers  Very useful for projections in query results  Requires inferred types  Compiler generates a class under the covers – And default equivalence methods – Types are considered the same if there are the same properties and types  Class has no methods
  • 13. Partial Methods  Allows definition of a method, and someone else to implement  If not implemented, no IL is generated  Useful for customizing generated code  A good example is pre and post validation calls  Used extensively in the LINQ to SQL designer for property changing and data validation events
  • 14. Partial Methods  Partial method declarations must begin with the contextual keyword partial and the method must return void.  Partial methods can have ref but not out parameters.  Partial methods are implicitly private, and therefore they cannot be virtual.  Partial methods cannot be extern, because the presence of the body determines whether they are defining or implementing.  Partial methods can have static and unsafe modifiers.
  • 15. Partial Methods  Partial methods can be generic. Constraints are put on the defining partial method declaration, and may optionally be repeated on the implementing one. Parameter and type parameter names do not have to be the same in the implementing declaration as in the defining one.  You cannot make a delegate to a partial method.
  • 17. Lambda Methods  Integral part of LINQ for specifying queries  Replace C# 2.0 anonymous delegates  Gives cleaner syntax for defining delegates – No need to declare a delegate – Just define the anonymous method at the point you want to use it  Leads to great reductions in code complexity  Format: – ( parameters ) => { code };
  • 19. Lambda Methods in a Query
  • 20. Extension Methods  A means of defining extensions to existing types  Allows the appearance of adding new methods to classes which you don’t have access to the source  Also used extensively for code generation of extensibility points  Used by LINQ to add query methods to existing framework classes via System.Link assembly  Declared within static classes using the this keyword  Can be used to extend sealed classes
  • 22. Query Expressions  Query expressions add SQL like syntax to the language  Allows specification of queries without using external tools or syntax  Components – From: Defines what data to start with – Where: Conditional selection – Select: Projects the result set  Supports concepts of joins – Use multiple “from”’s – Basically creates nested loops (but a little more elaborate)
  • 26. Expression Trees  Query expressions are converted into expression trees  An expression tree is a data structure representing an expression  You can also build expressions trees dynamically
  • 28. What is LInQ?  LInQ = Language Integrated Query  Internal DSL to .NET Languages for querying objects  Many consider it an ORM. It is not an ORM – But LINQ 2 SQL is an extension that provides ORM capabilities  It is much more than an ORM – Integrated query language: runtime and compiler – Query Optimization – Object “projection”  LINQ syntax looks like SQL, but it is much different
  • 29. What is LINQ?  It provides for allows query across any enumerable object collections – Just about any IEnumerable<T> can be used in queries – If the backing store is not understood by the compiler, you can build a “provider” to explain it.  Provides a standard means of querying collections of CLR objects, databases (RDBMS) and XML  Provides for compile-time query development and syntax checking which leads to less errors
  • 30. What is LInQ’s Value Proposition?  No context shift when needing to query collections of objects to find the object that you want  Not just an ORM – LInQ to SQL does do that, but it really is about managing query, construction and update of objects independent of storage (memory, document, file or RDBMS)  An attempt to provide a single means of query, instead of: – SQL for RDBMS – XPath and XQuery for XML – Custom code for objects  Identification of query errors at compile time instead of run-time  Rapid development of queries through tool support
  • 31. How can LInQ Make you more Effective?  Quicker time to deployment – Rapid development  Less errors – Type safe query based upon object and database metadata  Performance – Optimized at the provider level – Integrated into the language and runtime, so no context shift at runtime  Single Model for Query – Similar query structure for all data types  Less code – Write less query code – Also can be used to facilitate object construction which can greatly reduce code base
  • 32. Competition (1)  Nhibernate – Open source ORM tool, very popular, based on Hibernate – Proprietary query language, no language integration – Unweildy XML configuration files – Realy only competes with LINQ to SQL  CSLA – .NET framework for object distribution and database mapping offered by Rocky Lhotka – Has some traction, but tries to solve many issues and is relatively weak in ORM capabilities – Kind of an ORM, but no real built in query
  • 33. Competition (2)  ActiveRecord – Design pattern for representing rows of tables in and ORM – Comes from Fowler, very popular in Ruby on Rails – Limited to operations on single tables – Primary implementation is Castle ActiveRecord – No integrated query  Rhino-Commons – Open source extensions to Castle ActiveRecord (and Rhino Mocks) – Big part of the Alt.NET toolset – Makes ActiveRecord even easier – Also no query
  • 34. Competition (3)  Microsoft Entity Framework – Microsoft’s higher level data abstraction model – Uses LInQ under the covers for query and physical table mapping – First Generation – Uses LINQ for query, but real functionality is in providing multi-database and object partitioning across multiple physical sources
  • 36. Flavors of LInQ  LInQ to Objects – Can query any IEnumerable set of object(s) – Uses runtime metadata  LInQ to SQL – Requires adornment of objects with attributes to provide mapping to RDBMS  LInQ to DataTable – Provides ability to query data returned from ADO.NET via DataTable object without having to use the built in and difficult to use query constructs  LInQ to XML – XDocument class is LInQ aware, allowing query of XML with LInQ syntax instead of Xpath  LInQ to Entities – Provides query across Entity Framework Objects
  • 37. LInQ Architecture (1)  Required extensions to the CLR languages for: – Lambda functions – Partial Methods – Extension methods – Collection initializers – Type inference – Object Initializers – Automatic Properties – Anonymous Types – Expression Trees
  • 38. LInQ Architecture (2)  Query structure - Comprehension Model – From (where is the data coming from) – Where (filter out on a criteria) – Select (and select only the data you need) – Join, group, orderby, …  This is an internal DSL that is translated into method calls
  • 39. LInQ Architecture (3)  Provider model (the context) – Can root queries and be used to  Track object changes  Execute transactions  Generate native queries  Defer execution or eager load data – Important note:  Change tracking is optimistic, and  Requires projection of the full table objects (all columns). Partial classes are not supported as missing data may be changed by a third party.
  • 40. LInQ Architecture (4)  Lambda Expressions – Comprehension is converted to the compiler to this format  Query is typically not executed until… – LInQ query IS NOT executed at declaration – The variable is simply a holder for the expression – Query IS started when the variable is iterated  This is very important! – It can be confusing at first
  • 41. How do you use LInQ?  Typically, you write a query in comprehension mode – The compiler converts it to Lamba format  In LinQ to objects – A series of decorators is created that feeds… data from one to the next, each triggered by enumeration  In LInQ to SQL – SQL is created and data is mapped to CLR objects – Chain of decorators may be handled explicitly by the SQL  In LInQ to XML – XPath is generated to manipulate the DOM  Objects are then “Projected” into results – Can be a strongly typed class, or an anonymous class – Can contain all properties of the selected objects, or just a subset
  • 43. All the same Query Comprehension Query Lambda Queries
  • 44. What’s Going On? A progressive filtering of data through the parts of the query Triggered on the enumerators
  • 45. Local Query Execution and Deferral The query becomes a set of enumerators decorated by a different type of functionality and criteria
  • 48. LINQ to SQL  Operates using a data context object – Entry point to the database – Performs change tracking  Attribute base declaration of mapping of classes to database tables  Automatic identification of primary/foreign keys for relationships
  • 49. LINQ to SQL  If using the designer, you get: – automatic creation of extension point for data validation and property change – Ability to map insert/delete/update/query to stored procedures – Automatic handling of updates of key relationships – Automatic transaction processing – Server side paging
  • 50. If you don’t use the designer  You can manually annotate classes – And you must implement the other features like property change notification yourself  Or you can also use XML configuration files – But there is not a “fluent” interface at this point
  • 51. LINQ to SQL  DataContext class can be extended with partial classes to: – Override default generation of SQL into stored procs – Override default generation of SQL into custom SQL – Objects returned by either of these will also participate in change management  This is very powerful as it allows: – Rapid development of queries first using comprehension queries – Later migration of queries into stored procs – Data access code will remain the same – Data validation code will still be valid in either context
  • 52. LINQ to SQL  Other items of importance – AsQueryable vs AsEnumerable – Optimistic locking / ChangeConflicts  Coupling – DBML tight couples to database, but is easy – XML loose couples, but you have to code more  Stored procedures? – Can be used for CRUD on DBML objects – Or called directly as methods on the data context
  • 53. DBML
  • 57.
  • 58. LINQ to XML  System.Xml.Linq namespace  XDocument class – Provides new XML API that is LINQ aware – Other classes: XElement, XAttribute, XNode  You can: – Create XML documents from the results of queries – Query XML documents and return XML or objects  Can be used to provide a natural query language to XML documents instead of Xpath/Xquery
  • 59. LINQ to XML Example – DB to XML
  • 62. LInQ Demonstration(s)  A basic query structure on strings (linq to objects)  Query across objects – summing data – grouping and projecting  Mapping objects to RDBMS  RDBMS query  RDBMS relationships (lazy and eager load)  RDBMS update  Multi-result / multi-shape query  Data binding to anonymous query results  Simplification of XML manipulation – Query data – Create documents
  • 63. Maturity  Available for 3+ years in CTP form  Released in .NET 3.0 (~ fall 2007)  Rock solid with Linq to Objects, SQL Server  No current support for Oracle from either MS or Oracle (there is a codeplex project)
  • 64. Strengths and Weaknesses Strengths  Standard object query language  Tool integration  Pervasive  Deferred execution  Great model for manipulating objects instead of explicit code  Easier configuration compared to other tools Weaknesses  Not good support for ad- hoc queries  Currently only supports SQL Server  It is a new tool to learn  Different from SQL  Tight coupling to SQL database
  • 65. Adopting LInQ  Start with query over objects  Move to XML query / creating XML objects  Use for rapid development, query development, unit testing (agile development)  Teach to developers and data analysts  Create role of “business object designer” to work with DBA’s to build data access layers in LInQ combined with the efforts of the DBA’s.  Release dal’s to programmers to use as a unified object model.  Migrate queries to CRUD stored procedures
  • 66. Futures  Parallel LInQ – http://channel9.msdn.com/shows/Going+Deep/Inside- Parallel-Extensions-for-NET-2008-CTP-Part-1/
  • 67. Learning LInQ  Books – Apress: Pro LINQ: Language Integrated Query in C# 2008 – Apress: Pro LINQ Object Relational Mapping in C# 2008 – Oreilly: LINQ: The Future of Data Access in C# 3.0  Web sites – Scott Guthrie: http://weblogs.asp.net/scottgu – Bill Wagner: http://srtsolutions.com/blogs/billwagner/ – www.hookedonlinq.com  Podcasts – Dotnetrocks.com – DNRTV.com
  • 68. Tools  Visual LINQ: http://code.msdn.microsoft.com/vlinq  LINQPad: http://www.linqpad.net/  LINQ Debug Visualizer: – http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to- sql-debug-visualizer.aspx
  • 69. Q&A  Solicit general customer questions about LInQ (be prepared for these – think ahead of them) – I’m scared of not using stored procs… – I’m not using that level of .NET yet… – How does this fit with legacy systems? – What about my DBA’s? – Who else is using LInQ? What have their experiences been? – How does LInQ fit into agile?  Proactively solicit information on LInQ from customer about how they can use LInQ – Look for a few strategic inroads to follow… Such as: – Training / mentoring – Proof of concepts – Ask them how they think they can use it
  • 70. Contact Michael Heydt Senior Manager (610) 772-5556 Cell michael.heydt@sungard.com mike@heydt.org www.42spikes.com
  • 71. CONFIDENTIALITY STATEMENT Copyright © 2008 by SunGard Data Systems Inc. (or its subsidiaries, “SunGard”). All rights reserved. No parts of this document may be reproduced, transmitted or stored electronically without SunGard’s prior written permission. This document contains SunGard's confidential or proprietary information. By accepting this document, you agree that: (A)(1) if a pre-existing contract containing disclosure and use restrictions exists between your company and SunGard, you and your company will use this information subject to the terms of the pre-existing contract; or (2) if no such pre-existing contract exists, you and your Company agree to protect this information and not reproduce or disclose the information in any way; and (B) SunGard makes no warranties, express or implied, in this document, and SunGard shall not be liable for damages of any kind arising out of use of this document. About SunGard Consulting Services SunGard Consulting Services’ deep understanding of business processes in financial services and energy, together with our expertise in information technology and knowledge of SunGard products, helps us mitigate project risk and provide a single point of accountability for SunGard projects that differentiates us from other consulting organizations.
  • 72. Elevators  The LINQ Project is a codename for a set of extensions to the .NET Framework that encompass language-integrated query, set, and transform operations. It extends C# and Visual Basic with native language syntax for queries and provides class libraries to take advantage of these capabilities.
  • 73.  LINQ defines a set of query operators that can be used to query, project and filter data in arrays, enumerable classes, XML, relational database, and third party data sources. While it allows any data source to be queried, it requires that the data be encapsulated as objects. So, if the data source does not natively store data as objects, the data must be mapped to the object domain. Queries written using the query operators are executed either by the LINQ query processing engine or, via an extension mechanism, handed over to LINQ providers which either implement a separate query processing engine or translate to a different format to be executed on a separate data store (such as on a database server as SQL queries). The results of a query are returned as a collection of in-memory objects that can be enumerated.
  • 74. Group By  Important to note that this really returns a dictionary
  • 75. Notes  Lazy load required EntityRef  XML Mapping files can be used  LINQ grammer is not the same as SQL  Right outer joins must be flipped to left