SlideShare ist ein Scribd-Unternehmen logo
1 von 32
Not quite a sales pitch for C# 3.0 and .NET's LINQ ,[object Object],[object Object],[object Object],[object Object],[object Object], :=
Why LINQ? Because: Data != Objects Aka the Bermuda Triangle of data processing Objects XML Relations
What’s LINQ? ,[object Object],[object Object]
Database access in pre-LINQ era SqlConnection c = new SqlConnection(…); c.Open();  SqlCommand cmd = new SqlCommand( @“SELECT c.Name, c.Phone   FROM Customers c   WHERE c.City = @p0” ); cmd.Parameters[“@po”] = “London”;  DataReader dr = c.Execute(cmd);  while (dr.Read()) { string name = r.GetString(0); string phone = r.GetString(1); DateTime date = r.GetDateTime(2); } r.Close(); Queries in quotes Arguments loosely bound Results loosely typed Compiler cannot help catch mistakes
Database access with LINQ to SQL 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 real objects Query is natural part of the language Results are strongly typed
XML access in pre-LINQ era public static double XmlOrder2Total(XmlDocument doc) { static string ons = &quot;http://www.vertical.com/Order&quot;; double total = 0.0; XmlElement o = (XmlElement)doc.GetElementsByTagName(&quot;Order&quot;, ons).Item(0); foreach (XmlElement x in o.GetElementsByTagName(&quot;Item&quot;, ons)) { XmlNode priceNode = x.GetElementsByTagName(&quot;Price&quot;, ons).Item(0); XmlNode quantityNode = x.GetElementsByTagName(&quot;Quantity&quot;, ons).Item(0); double priceValue = Double.Parse(priceNode.InnerText); int quantityValue = Int32.Parse(quantityNode.InnerText); total += priceValue * quantityValue; } return total; } Imperative aggregation Low-level namespace model Verbose query API Tedious conversions
XML access with LINQ to XML public static double XmlOrder2Total(XElement o) { static XNamespace ons = &quot;http://www.vertical.com/Order&quot;; return (from item in o.Elements(ons + &quot;Item&quot;) select (double)item.Element(ons + &quot;Price&quot;) * (int)item.Element(ons + &quot;Quantity&quot;) ).Sum(); } Functional aggregation Designated type for namespaces SQL/XQuery like query syntax Concise accessors
Language INtegrated Query (LINQ) LINQ provides one programming model for all types of data (objects, SQL, XML, DataSets) LINQ enabled data sources LINQ To Objects Objects LINQ To XML <book> <title/> <author/> <price/> </book> XML LINQ enabled ADO.NET LINQ To Datasets LINQ To SQL LINQ To Entities Relational Others… VB C# .NET Language-Integrated Query
.NET through the ages
The evolution of C# C# 1.0 C# 2.0 C# 3.0 Components on a Managed Runtime Generics Language Integrated Query
C# 3.0 design goals ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
C# 3.0 language innovations var contacts = from c in customers where c.City == &quot;Redmond&quot; select new { c.Name, c.Phone }; var contacts = customers .Where(c => c.City == &quot;Redmond&quot;) .Select(c => new { c.Name, c.Phone }); Extension methods Lambda expressions Query expressions Object initializers Anonymous types Local variable type inference
Local variable type inference Not to be confused with Pascal
Object initializers Field or property assignments
Anonymous types class ??? { public string Name; public int Age; } ???
Anonymous types class ??? { public string Name; public string Phone; } public class Customer { public string Name; public Address Address; public string Phone; … } public class Contact { public string Name; public string Phone; } Customer c = GetCustomer(…); Contact x = new Contact { Name = c.Name, Phone = c.Phone }; Customer c = GetCustomer(…); var x = new { c.Name, c.Phone }; Customer c = GetCustomer(…); var x = new { Name = c.Name, Phone = c.Phone }; Projection style initializer
Lambda expressions – motivating example Delegate type (function type) Higher-order function
Lambda expressions (not yet) Non-anonymous function
Lambda expressions (C# 1.0/2.0)
Lambda expressions (C# 3.0 sugar) Lambda expression
Lambda expressions (w/ type inference) Lambda expression
Extension methods Static method with “this” argument Invoke It like an instance method
Query expressions ,[object Object],[object Object],from c in customers where c.City ==  &quot;Redmond&quot; select new { c.Name, c.Phone }; customers .Where(c => c.City ==  &quot;Redmond&quot; ) .Select(c => new { c.Name, c.Phone });
Query expressions from   id   in   source {  from   id   in   source | join   id   in   source   on   expr   equals   expr  [  into   id  ] | let   id  =  expr  | where   condition  | orderby   ordering ,  ordering , … } select   expr  |  group   expr   by   key [  into   id   query  ] Starts with  from Zero or more  from ,  join ,  let ,  where , or  orderby Ends with  select  or  group by Optional  into  continuation
Standard Query Operators Restriction Where Projection Select, SelectMany Ordering OrderBy, ThenBy Grouping GroupBy Quantifiers Any, All Partitioning Take, Skip, TakeWhile, SkipWhile Sets Distinct, Union, Intersect, Except Elements First, FirstOrDefault, ElementAt Aggregation Count, Sum, Min, Max, Average Conversion ToArray, ToList, ToDictionary Casting OfType<T>
Extension methods and queries namespace System.Linq { public static class Enumerable { public static IEnumerable<T> Where<T>(this IEnumerable<T> source, Func<T, bool> predicate) {  …  } public static IEnumerable<S> Select<T, S>(this IEnumerable<T> source, Func<T, S> selector) {  …  } … } } using System.Linq; Extension methods IEnumerable<string> contacts = customers.Where(c => c.State == &quot;WA&quot;).Select(c => c.Name); Brings extensions  into scope obj.Foo(x, y)  ???.Foo(obj, x, y) IntelliSense!
Expression trees
LINQ architecture System.Linq.Enumerable Delegate based Source implements IEnumerable<T> System.Linq.Queryable Expression tree based Source implements IQueryable<T> SQL DataSets Objects Others…
LINQ to SQL Architecture Enumerate SQL Query or SProc Rows Objects SubmitChanges() DML  or SProcs Application LINQ to SQL from c in db.Customers where c.City == &quot;London&quot; select c.CompanyName SELECT CompanyName FROM Customer WHERE City = 'London' db.Customers.Add(c1); c2.City = “Seattle&quot;; db.Customers.Remove(c3); INSERT INTO Customer … UPDATE Customer … DELETE FROM Customer …
Summary – LINQ contributions ,[object Object],[object Object],[object Object],[object Object]
Summary – Related open issues ,[object Object],[object Object],[object Object],[object Object]
Demo

Weitere ähnliche Inhalte

Was ist angesagt?

46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1AmIt Prasad
 
Object Oriented Programming with C++
Object Oriented Programming with C++Object Oriented Programming with C++
Object Oriented Programming with C++Rokonuzzaman Rony
 
CS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionCS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionEelco Visser
 
Moving Average Filter in C
Moving Average Filter in CMoving Average Filter in C
Moving Average Filter in CColin
 
Functions in C++
Functions in C++Functions in C++
Functions in C++home
 
Functional programming with FSharp
Functional programming with FSharpFunctional programming with FSharp
Functional programming with FSharpDaniele Pozzobon
 
Tokens expressionsin C++
Tokens expressionsin C++Tokens expressionsin C++
Tokens expressionsin C++HalaiHansaika
 
CS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesCS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesEelco Visser
 

Was ist angesagt? (20)

C++ theory
C++ theoryC++ theory
C++ theory
 
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1
 
C++
C++C++
C++
 
Object Oriented Programming with C++
Object Oriented Programming with C++Object Oriented Programming with C++
Object Oriented Programming with C++
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
CS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionCS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definition
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Moving Average Filter in C
Moving Average Filter in CMoving Average Filter in C
Moving Average Filter in C
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
C++ Language
C++ LanguageC++ Language
C++ Language
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Functional programming with FSharp
Functional programming with FSharpFunctional programming with FSharp
Functional programming with FSharp
 
C++ Templates 2
C++ Templates 2C++ Templates 2
C++ Templates 2
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Tokens expressionsin C++
Tokens expressionsin C++Tokens expressionsin C++
Tokens expressionsin C++
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
CS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesCS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic Services
 
C Theory
C TheoryC Theory
C Theory
 

Andere mochten auch

Andere mochten auch (7)

Lange Netter 06032008 Slideshared
Lange Netter 06032008   SlidesharedLange Netter 06032008   Slideshared
Lange Netter 06032008 Slideshared
 
Nbp 2 Min Pitch
Nbp   2 Min PitchNbp   2 Min Pitch
Nbp 2 Min Pitch
 
Chicago email trail (1)
Chicago email trail (1)Chicago email trail (1)
Chicago email trail (1)
 
Bomber
BomberBomber
Bomber
 
Hola
HolaHola
Hola
 
otbojta
otbojtaotbojta
otbojta
 
Iwb introduction
Iwb introductionIwb introduction
Iwb introduction
 

Ähnlich wie Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05

Share pointtechies linqtosp-andsbs
Share pointtechies linqtosp-andsbsShare pointtechies linqtosp-andsbs
Share pointtechies linqtosp-andsbsShakir Majeed Khan
 
Visual studio 2008
Visual studio 2008Visual studio 2008
Visual studio 2008Luis Enrique
 
devLink - What's New in C# 4?
devLink - What's New in C# 4?devLink - What's New in C# 4?
devLink - What's New in C# 4?Kevin Pilch
 
Whats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPontoWhats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPontoPaulo Morgado
 
Embedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaEmbedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaJevgeni Kabanov
 
Introduction To Csharp
Introduction To CsharpIntroduction To Csharp
Introduction To Csharpg_hemanth17
 
Introduction to-csharp-1229579367461426-1
Introduction to-csharp-1229579367461426-1Introduction to-csharp-1229579367461426-1
Introduction to-csharp-1229579367461426-1Sachin Singh
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharpRaga Vahini
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharpSatish Verma
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharpsinghadarsh
 
Introduction to CSharp
Introduction to CSharpIntroduction to CSharp
Introduction to CSharpMody Farouk
 
Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Juan Pablo
 
Linq Sanjay Vyas
Linq   Sanjay VyasLinq   Sanjay Vyas
Linq Sanjay Vyasrsnarayanan
 

Ähnlich wie Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05 (20)

LINQ
LINQLINQ
LINQ
 
Greg Demo Slides
Greg Demo SlidesGreg Demo Slides
Greg Demo Slides
 
Share pointtechies linqtosp-andsbs
Share pointtechies linqtosp-andsbsShare pointtechies linqtosp-andsbs
Share pointtechies linqtosp-andsbs
 
PostThis
PostThisPostThis
PostThis
 
Visual studio 2008
Visual studio 2008Visual studio 2008
Visual studio 2008
 
Understanding linq
Understanding linqUnderstanding linq
Understanding linq
 
devLink - What's New in C# 4?
devLink - What's New in C# 4?devLink - What's New in C# 4?
devLink - What's New in C# 4?
 
Introduction to Linq
Introduction to LinqIntroduction to Linq
Introduction to Linq
 
Linq intro
Linq introLinq intro
Linq intro
 
Whats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPontoWhats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPonto
 
Embedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaEmbedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for Java
 
Introduction To Csharp
Introduction To CsharpIntroduction To Csharp
Introduction To Csharp
 
Introduction to-csharp-1229579367461426-1
Introduction to-csharp-1229579367461426-1Introduction to-csharp-1229579367461426-1
Introduction to-csharp-1229579367461426-1
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharp
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharp
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharp
 
Introduction to CSharp
Introduction to CSharpIntroduction to CSharp
Introduction to CSharp
 
Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#
 
Linq Sanjay Vyas
Linq   Sanjay VyasLinq   Sanjay Vyas
Linq Sanjay Vyas
 
Cs30 New
Cs30 NewCs30 New
Cs30 New
 

Mehr von CHOOSE

Dissecting State-of-the-Art Android Malware Using Static and Dynamic Analysis
Dissecting State-of-the-Art Android Malware Using Static and Dynamic AnalysisDissecting State-of-the-Art Android Malware Using Static and Dynamic Analysis
Dissecting State-of-the-Art Android Malware Using Static and Dynamic AnalysisCHOOSE
 
Continuous Architecting of Stream-Based Systems
Continuous Architecting of Stream-Based SystemsContinuous Architecting of Stream-Based Systems
Continuous Architecting of Stream-Based SystemsCHOOSE
 
Modelling and Programming: Isn&rsquo;t it all the same?
Modelling and Programming: Isn&rsquo;t it all the same?Modelling and Programming: Isn&rsquo;t it all the same?
Modelling and Programming: Isn&rsquo;t it all the same?CHOOSE
 
Practical Models in Practice
Practical Models in PracticePractical Models in Practice
Practical Models in PracticeCHOOSE
 
Services and Models in a Large IT System
Services and Models in a Large IT SystemServices and Models in a Large IT System
Services and Models in a Large IT SystemCHOOSE
 
Choose'10: Uwe Zdun - Compliance in service-oriented architectures: A model-d...
Choose'10: Uwe Zdun - Compliance in service-oriented architectures: A model-d...Choose'10: Uwe Zdun - Compliance in service-oriented architectures: A model-d...
Choose'10: Uwe Zdun - Compliance in service-oriented architectures: A model-d...CHOOSE
 
Choose'10: Jean-Marie Favre - Domain and Technique Specific Languages – A Jou...
Choose'10: Jean-Marie Favre - Domain and Technique Specific Languages – A Jou...Choose'10: Jean-Marie Favre - Domain and Technique Specific Languages – A Jou...
Choose'10: Jean-Marie Favre - Domain and Technique Specific Languages – A Jou...CHOOSE
 
Choose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk
Choose'10: Stephane Ducasse - Powerful DSL engineering in SmalltalkChoose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk
Choose'10: Stephane Ducasse - Powerful DSL engineering in SmalltalkCHOOSE
 
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of TonguesChoose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of TonguesCHOOSE
 
Ralph Jocham The Risks Of Scrum Handout
Ralph Jocham The Risks Of Scrum HandoutRalph Jocham The Risks Of Scrum Handout
Ralph Jocham The Risks Of Scrum HandoutCHOOSE
 
Ralph Jocham The Risks Of Scrum
Ralph Jocham The Risks Of ScrumRalph Jocham The Risks Of Scrum
Ralph Jocham The Risks Of ScrumCHOOSE
 
Denker - Pharo: Present and Future - 2009-07-14
Denker - Pharo: Present and Future - 2009-07-14Denker - Pharo: Present and Future - 2009-07-14
Denker - Pharo: Present and Future - 2009-07-14CHOOSE
 
Hausi Müller - Towards Self-Adaptive Software-Intensive Systems
Hausi Müller - Towards Self-Adaptive Software-Intensive SystemsHausi Müller - Towards Self-Adaptive Software-Intensive Systems
Hausi Müller - Towards Self-Adaptive Software-Intensive SystemsCHOOSE
 
2008 02 01 Zeller
2008 02 01 Zeller2008 02 01 Zeller
2008 02 01 ZellerCHOOSE
 

Mehr von CHOOSE (14)

Dissecting State-of-the-Art Android Malware Using Static and Dynamic Analysis
Dissecting State-of-the-Art Android Malware Using Static and Dynamic AnalysisDissecting State-of-the-Art Android Malware Using Static and Dynamic Analysis
Dissecting State-of-the-Art Android Malware Using Static and Dynamic Analysis
 
Continuous Architecting of Stream-Based Systems
Continuous Architecting of Stream-Based SystemsContinuous Architecting of Stream-Based Systems
Continuous Architecting of Stream-Based Systems
 
Modelling and Programming: Isn&rsquo;t it all the same?
Modelling and Programming: Isn&rsquo;t it all the same?Modelling and Programming: Isn&rsquo;t it all the same?
Modelling and Programming: Isn&rsquo;t it all the same?
 
Practical Models in Practice
Practical Models in PracticePractical Models in Practice
Practical Models in Practice
 
Services and Models in a Large IT System
Services and Models in a Large IT SystemServices and Models in a Large IT System
Services and Models in a Large IT System
 
Choose'10: Uwe Zdun - Compliance in service-oriented architectures: A model-d...
Choose'10: Uwe Zdun - Compliance in service-oriented architectures: A model-d...Choose'10: Uwe Zdun - Compliance in service-oriented architectures: A model-d...
Choose'10: Uwe Zdun - Compliance in service-oriented architectures: A model-d...
 
Choose'10: Jean-Marie Favre - Domain and Technique Specific Languages – A Jou...
Choose'10: Jean-Marie Favre - Domain and Technique Specific Languages – A Jou...Choose'10: Jean-Marie Favre - Domain and Technique Specific Languages – A Jou...
Choose'10: Jean-Marie Favre - Domain and Technique Specific Languages – A Jou...
 
Choose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk
Choose'10: Stephane Ducasse - Powerful DSL engineering in SmalltalkChoose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk
Choose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk
 
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of TonguesChoose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
 
Ralph Jocham The Risks Of Scrum Handout
Ralph Jocham The Risks Of Scrum HandoutRalph Jocham The Risks Of Scrum Handout
Ralph Jocham The Risks Of Scrum Handout
 
Ralph Jocham The Risks Of Scrum
Ralph Jocham The Risks Of ScrumRalph Jocham The Risks Of Scrum
Ralph Jocham The Risks Of Scrum
 
Denker - Pharo: Present and Future - 2009-07-14
Denker - Pharo: Present and Future - 2009-07-14Denker - Pharo: Present and Future - 2009-07-14
Denker - Pharo: Present and Future - 2009-07-14
 
Hausi Müller - Towards Self-Adaptive Software-Intensive Systems
Hausi Müller - Towards Self-Adaptive Software-Intensive SystemsHausi Müller - Towards Self-Adaptive Software-Intensive Systems
Hausi Müller - Towards Self-Adaptive Software-Intensive Systems
 
2008 02 01 Zeller
2008 02 01 Zeller2008 02 01 Zeller
2008 02 01 Zeller
 

Kürzlich hochgeladen

MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 

Kürzlich hochgeladen (20)

MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 

Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05

  • 1.
  • 2. Why LINQ? Because: Data != Objects Aka the Bermuda Triangle of data processing Objects XML Relations
  • 3.
  • 4. Database access in pre-LINQ era SqlConnection c = new SqlConnection(…); c.Open(); SqlCommand cmd = new SqlCommand( @“SELECT c.Name, c.Phone FROM Customers c WHERE c.City = @p0” ); cmd.Parameters[“@po”] = “London”; DataReader dr = c.Execute(cmd); while (dr.Read()) { string name = r.GetString(0); string phone = r.GetString(1); DateTime date = r.GetDateTime(2); } r.Close(); Queries in quotes Arguments loosely bound Results loosely typed Compiler cannot help catch mistakes
  • 5. Database access with LINQ to SQL 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 real objects Query is natural part of the language Results are strongly typed
  • 6. XML access in pre-LINQ era public static double XmlOrder2Total(XmlDocument doc) { static string ons = &quot;http://www.vertical.com/Order&quot;; double total = 0.0; XmlElement o = (XmlElement)doc.GetElementsByTagName(&quot;Order&quot;, ons).Item(0); foreach (XmlElement x in o.GetElementsByTagName(&quot;Item&quot;, ons)) { XmlNode priceNode = x.GetElementsByTagName(&quot;Price&quot;, ons).Item(0); XmlNode quantityNode = x.GetElementsByTagName(&quot;Quantity&quot;, ons).Item(0); double priceValue = Double.Parse(priceNode.InnerText); int quantityValue = Int32.Parse(quantityNode.InnerText); total += priceValue * quantityValue; } return total; } Imperative aggregation Low-level namespace model Verbose query API Tedious conversions
  • 7. XML access with LINQ to XML public static double XmlOrder2Total(XElement o) { static XNamespace ons = &quot;http://www.vertical.com/Order&quot;; return (from item in o.Elements(ons + &quot;Item&quot;) select (double)item.Element(ons + &quot;Price&quot;) * (int)item.Element(ons + &quot;Quantity&quot;) ).Sum(); } Functional aggregation Designated type for namespaces SQL/XQuery like query syntax Concise accessors
  • 8. Language INtegrated Query (LINQ) LINQ provides one programming model for all types of data (objects, SQL, XML, DataSets) LINQ enabled data sources LINQ To Objects Objects LINQ To XML <book> <title/> <author/> <price/> </book> XML LINQ enabled ADO.NET LINQ To Datasets LINQ To SQL LINQ To Entities Relational Others… VB C# .NET Language-Integrated Query
  • 10. The evolution of C# C# 1.0 C# 2.0 C# 3.0 Components on a Managed Runtime Generics Language Integrated Query
  • 11.
  • 12. C# 3.0 language innovations var contacts = from c in customers where c.City == &quot;Redmond&quot; select new { c.Name, c.Phone }; var contacts = customers .Where(c => c.City == &quot;Redmond&quot;) .Select(c => new { c.Name, c.Phone }); Extension methods Lambda expressions Query expressions Object initializers Anonymous types Local variable type inference
  • 13. Local variable type inference Not to be confused with Pascal
  • 14. Object initializers Field or property assignments
  • 15. Anonymous types class ??? { public string Name; public int Age; } ???
  • 16. Anonymous types class ??? { public string Name; public string Phone; } public class Customer { public string Name; public Address Address; public string Phone; … } public class Contact { public string Name; public string Phone; } Customer c = GetCustomer(…); Contact x = new Contact { Name = c.Name, Phone = c.Phone }; Customer c = GetCustomer(…); var x = new { c.Name, c.Phone }; Customer c = GetCustomer(…); var x = new { Name = c.Name, Phone = c.Phone }; Projection style initializer
  • 17. Lambda expressions – motivating example Delegate type (function type) Higher-order function
  • 18. Lambda expressions (not yet) Non-anonymous function
  • 20. Lambda expressions (C# 3.0 sugar) Lambda expression
  • 21. Lambda expressions (w/ type inference) Lambda expression
  • 22. Extension methods Static method with “this” argument Invoke It like an instance method
  • 23.
  • 24. Query expressions from id in source { from id in source | join id in source on expr equals expr [ into id ] | let id = expr | where condition | orderby ordering , ordering , … } select expr | group expr by key [ into id query ] Starts with from Zero or more from , join , let , where , or orderby Ends with select or group by Optional into continuation
  • 25. Standard Query Operators Restriction Where Projection Select, SelectMany Ordering OrderBy, ThenBy Grouping GroupBy Quantifiers Any, All Partitioning Take, Skip, TakeWhile, SkipWhile Sets Distinct, Union, Intersect, Except Elements First, FirstOrDefault, ElementAt Aggregation Count, Sum, Min, Max, Average Conversion ToArray, ToList, ToDictionary Casting OfType<T>
  • 26. Extension methods and queries namespace System.Linq { public static class Enumerable { public static IEnumerable<T> Where<T>(this IEnumerable<T> source, Func<T, bool> predicate) { … } public static IEnumerable<S> Select<T, S>(this IEnumerable<T> source, Func<T, S> selector) { … } … } } using System.Linq; Extension methods IEnumerable<string> contacts = customers.Where(c => c.State == &quot;WA&quot;).Select(c => c.Name); Brings extensions into scope obj.Foo(x, y)  ???.Foo(obj, x, y) IntelliSense!
  • 28. LINQ architecture System.Linq.Enumerable Delegate based Source implements IEnumerable<T> System.Linq.Queryable Expression tree based Source implements IQueryable<T> SQL DataSets Objects Others…
  • 29. LINQ to SQL Architecture Enumerate SQL Query or SProc Rows Objects SubmitChanges() DML or SProcs Application LINQ to SQL from c in db.Customers where c.City == &quot;London&quot; select c.CompanyName SELECT CompanyName FROM Customer WHERE City = 'London' db.Customers.Add(c1); c2.City = “Seattle&quot;; db.Customers.Remove(c3); INSERT INTO Customer … UPDATE Customer … DELETE FROM Customer …
  • 30.
  • 31.
  • 32. Demo

Hinweis der Redaktion

  1. Suppose you are an academic Haskell and Prolog nerd as well as a grammar hacker with a sympathy for the real IT world (which equals Cobol, SQL, C++, and more recently, VB, C#, XML). Temporarily bored by the academic treadmill and Haskell&apos;s purity, you end up working at Microsoft for some time, which is good timing because Microsoft&apos;s LINQ is just taking shape. (I worked in the SQL/XML/LINQ teams at Microsoft, Redmond, 2005-2007.) What is LINQ? Here is my short, unofficial explanation: LINQ (for Language-INtegrated Query) is a programming technology designed to keep it&apos;s head above water in the Bermuda triangle of data processing (X/O/R); technically, it is a combination of some cheap OO and functional programming language extensions, an almost unrecognizable stretch of Haskell&apos;s list comprehensions, a clever exploit of interface polymorphism, a statically typed + quotation-free form of meta-programming possibly cooler than Lisp, and some noteworthy bits of generative tools and APIs. The functional part of LINQ is immensely important; it&apos;s good to see that functional programming is getting into the mainstream. The benefits are clearly not limited to data processing; we will also see major benefits in parallel and distributed programming. My talk touches upon all of the above: it is some mix of LINQ demo, Microsoft retrospection, technical background, technological outlook, and research agenda.