SlideShare a Scribd company logo
What LINQ is aboutor, Playingwith LINQ, MongoDB, and someold new patterns for developers.or, How to injectfunctionalparadigms in imperativelanguagesor, parallelism made easy.WebWorkersCamp, 03/07/2010Pierre Couzy – Microsoft France
Who are you ?Worked in the Microsoft space for 20 yearsSpeaker, trainer, developer, architect, …Primarilyinterested in Web topicsIdentity, architecture, WS-*, interop, cloud, …Recentinterop/OSS activityWorked on drupal for Sql server projectWorks on automateddrupaltesting on WindowsSpeaker at major PHP eventsDrupalCon, PHP Forum, Symfony liveblog.couzy.com / pierre.couzy@microsoft.com
AgendaLINQMore LINQLINQ for MongoDBGoingParallelGoingDistributedQ&ADisclosure: This session is heavily Microsoft-Biased (which is to be expected, I work there)
LINQ : Why ?C# is an imperativelanguageWhichisniceExcept for a few thingsSplitting data manipulation betweenyour code and your data storeCoding data manipulationApplying new manipulation patterns to existing data
Clumsyc#example
Whatwe’dlikeisExpress more intent, lessimplementationEasy compositionStrongtypingThis issubject to hot debateBe as declarative as possible within the limitsimposed by C#
From C# to LINQ
Things to noticeLazyevaluationIf westepintothis code, wesee LINQ triggers itsmagic on demandEasy compositionIf weadd new clauses after the LINQ expression isbuilt but beforeit’sconsumed, wesimplymerge the additions to the existing expressionSo far, we’veworked on objectsWhichis how manynaive LINQ implementationswork : synchronously pipelining methods calls on collectionsLINQ has an interesting twistExpression trees
Expression Trees and IQueryableLet’stake the sameexample and introduceAsQueryable()Uponexecution, wecan notice the compiler didn’teatour LINQ expressionIt’sstill in there, using a tree format (an AbstractSymbolTree)That treewillberesolvedatruntimeIn the Linq to Objects case, wegetexactly the samebehaviour. The iteration pattern maystillbeyield-based, but thisisleft to IQueryable’simplementationdetails.
Playingwith expression treesLet’stackleLinq To SQLMy expression treeisnowpushed to the database layerIf I want to block the flow to SQL, I just have to insert a new node in the tree.Whichallows me to balance thingsUsing C# patterns and methodswhen I wantthemPushing to the databasewhatitdoes best
IQueryable goodiesSo, if I wantmythings to be LINQ aware, I caneitherBuildsomemethods and let the IEnumerable<T> do its pure objectmagic (I stillgetlazyeval)Or, playwithIQueryableAnd do myowninterpretation of the treeLet’sseeMongoDB in LINQ
Strongly-typed interaction when querying and updating collections.Improved interface to send common Mongo commands (creating indices, getting all the existing dbs and collections, etc.).Ultra-fast de/serialization of BSON to .Net CLR types and back.LINQ-to-MongoSupport for Mono
LINQ PatternsHaving a LINQ Expression isnice: youbasicallydelegate the execution to someoneelse’s codePlus, your LINQ Expressions have every good aspect youusuallyexpectfromfunctionalprogramming (ie, they are closures).So, they are perfectlysuited to parallelisationAll you have to do isaddanothernode to the expression treeDemo : AsParallel()
WritingMapReduce in LINQ public static IQueryable<R>  MapReduce<S,M,K,R>(this IQueryable<S> source,                                 Expression<Func<S,IEnumerable<M>>> mapper,                                 Expression<Func<M,K>> keySelector,                                 Expression<Func<K,IEnumerable<M>,R>> reducer){    return source.SelectMany(mapper).GroupBy(keySelector, reducer);}Notice that the callingsyntax : Source.MapReduce(lMapper, lKeySelector, lReducer)issimply a new nodethatcanbeinserted in a larger expression tree.This MapReducemethodcanrun on N coresusing PLINQ, or on X machines (and N cores per machine) usingDryadLINQ
Collection<T> collection;boolIsLegal(Key k);	string Hash(Key);var results = from c in collection 	where IsLegal(c.key) 	select new { Hash(c.key), c.value};DryadLINQ = LINQ + DryadVertexcodeQueryplan(Dryad job)DatacollectionC#C#C#C#results
Parallel executionvar logentries =        from line in logswhere !line.StartsWith("#")select new LogEntry(line);var user =         from access in logentrieswhere access.user.EndsWith(@"\ulfar")select access;var accesses =from access in usergroup access by access.page into pagesselect new UserPageCount("ulfar", pages.Key, pages.Count());var htmAccesses =from access in accesseswhere access.page.EndsWith(".htm")orderby access.count descendingselect access;
Thanks.

More Related Content

PPTX
From Python to smartphones: neural nets @ Saint-Gobain, François Sausset
PDF
Flow based programming an overview
PDF
Introduction to Pyramid
PDF
Persian MNIST in 5 Minutes
PDF
NoFlo - Flow-Based Programming for Node.js
PDF
Hcplphx920
PPTX
Reactive programming for javascript
PDF
Parallel programming using python
From Python to smartphones: neural nets @ Saint-Gobain, François Sausset
Flow based programming an overview
Introduction to Pyramid
Persian MNIST in 5 Minutes
NoFlo - Flow-Based Programming for Node.js
Hcplphx920
Reactive programming for javascript
Parallel programming using python

Viewers also liked (9)

PPTX
EventMachine
PPTX
1 query processing
PPT
Query execution
PPTX
RxJs - Reactive Extensions for JavaScript
PDF
MySQL Query Optimization (Basics)
PDF
Using Netezza Query Plan to Improve Performace
PDF
Apache Hive Hook
PDF
Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...
PDF
Presto - Hadoop Conference Japan 2014
EventMachine
1 query processing
Query execution
RxJs - Reactive Extensions for JavaScript
MySQL Query Optimization (Basics)
Using Netezza Query Plan to Improve Performace
Apache Hive Hook
Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...
Presto - Hadoop Conference Japan 2014
Ad

Similar to What linq is about (20)

DOCX
TechDayConf Edition 1 - 2020
PDF
Open source Technology
PDF
CNCF, State of Serverless & Project Nuclio
PDF
Metaflow: The ML Infrastructure at Netflix
PPTX
Pair-Programming with AI to achieve more efficient code in .NET
PPTX
.NET per la Data Science e oltre
PPT
What does OOP stand for?
PPTX
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
PPTX
A Linux Enthusiast's Perspective on Microsoft OSS & Azure
PDF
Wondershare Filmora 14.3.2 Crack + License Key Free Download
PDF
2025-03-20 - How to use AI to your advantage - AI-Driven Development.pdf
PDF
AOMEI Backupper Crack 2025 FREE Download
PDF
Wondershare PDFelement Pro Crack FREE Download
PDF
From hello world to goodbye code
PPTX
CI back to basis
PDF
LAMP is so yesterday, MEAN is so tomorrow! :)
PPTX
Build 2019 Recap
PPTX
Mini .net conf 2020
PPTX
Going open source with small teams
PPTX
ConFoo Montreal - Microservices for building an IDE - The innards of JetBrain...
TechDayConf Edition 1 - 2020
Open source Technology
CNCF, State of Serverless & Project Nuclio
Metaflow: The ML Infrastructure at Netflix
Pair-Programming with AI to achieve more efficient code in .NET
.NET per la Data Science e oltre
What does OOP stand for?
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
A Linux Enthusiast's Perspective on Microsoft OSS & Azure
Wondershare Filmora 14.3.2 Crack + License Key Free Download
2025-03-20 - How to use AI to your advantage - AI-Driven Development.pdf
AOMEI Backupper Crack 2025 FREE Download
Wondershare PDFelement Pro Crack FREE Download
From hello world to goodbye code
CI back to basis
LAMP is so yesterday, MEAN is so tomorrow! :)
Build 2019 Recap
Mini .net conf 2020
Going open source with small teams
ConFoo Montreal - Microservices for building an IDE - The innards of JetBrain...
Ad

More from LeTesteur (11)

PPT
Drupal en environnement microsoft
PPTX
Développer et déployer WordPress en environnement microsoft
PPTX
Développer et déployer une application php maintenable
PPTX
Web dev open door
PPTX
Joomla Days 2011 Lyon
PPTX
Drupal in the cloud with Windows Azure
PPTX
Php sous Windows - webcamps Paris
PPTX
Web Matrix (Microsoft WebCamps Paris)
PPTX
PHP Forum 2010 : Php et microsoft
PPTX
Eclipse day paris
PPTX
Comment approcherlecloud
Drupal en environnement microsoft
Développer et déployer WordPress en environnement microsoft
Développer et déployer une application php maintenable
Web dev open door
Joomla Days 2011 Lyon
Drupal in the cloud with Windows Azure
Php sous Windows - webcamps Paris
Web Matrix (Microsoft WebCamps Paris)
PHP Forum 2010 : Php et microsoft
Eclipse day paris
Comment approcherlecloud

Recently uploaded (20)

PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Getting Started with Data Integration: FME Form 101
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Spectroscopy.pptx food analysis technology
PDF
Encapsulation theory and applications.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
A Presentation on Artificial Intelligence
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Approach and Philosophy of On baking technology
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Tartificialntelligence_presentation.pptx
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Encapsulation_ Review paper, used for researhc scholars
Getting Started with Data Integration: FME Form 101
Building Integrated photovoltaic BIPV_UPV.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
NewMind AI Weekly Chronicles - August'25-Week II
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Spectroscopy.pptx food analysis technology
Encapsulation theory and applications.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
A Presentation on Artificial Intelligence
20250228 LYD VKU AI Blended-Learning.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Machine learning based COVID-19 study performance prediction
Approach and Philosophy of On baking technology
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Tartificialntelligence_presentation.pptx
Group 1 Presentation -Planning and Decision Making .pptx
MIND Revenue Release Quarter 2 2025 Press Release
Accuracy of neural networks in brain wave diagnosis of schizophrenia

What linq is about

  • 1. What LINQ is aboutor, Playingwith LINQ, MongoDB, and someold new patterns for developers.or, How to injectfunctionalparadigms in imperativelanguagesor, parallelism made easy.WebWorkersCamp, 03/07/2010Pierre Couzy – Microsoft France
  • 2. Who are you ?Worked in the Microsoft space for 20 yearsSpeaker, trainer, developer, architect, …Primarilyinterested in Web topicsIdentity, architecture, WS-*, interop, cloud, …Recentinterop/OSS activityWorked on drupal for Sql server projectWorks on automateddrupaltesting on WindowsSpeaker at major PHP eventsDrupalCon, PHP Forum, Symfony liveblog.couzy.com / pierre.couzy@microsoft.com
  • 3. AgendaLINQMore LINQLINQ for MongoDBGoingParallelGoingDistributedQ&ADisclosure: This session is heavily Microsoft-Biased (which is to be expected, I work there)
  • 4. LINQ : Why ?C# is an imperativelanguageWhichisniceExcept for a few thingsSplitting data manipulation betweenyour code and your data storeCoding data manipulationApplying new manipulation patterns to existing data
  • 6. Whatwe’dlikeisExpress more intent, lessimplementationEasy compositionStrongtypingThis issubject to hot debateBe as declarative as possible within the limitsimposed by C#
  • 8. Things to noticeLazyevaluationIf westepintothis code, wesee LINQ triggers itsmagic on demandEasy compositionIf weadd new clauses after the LINQ expression isbuilt but beforeit’sconsumed, wesimplymerge the additions to the existing expressionSo far, we’veworked on objectsWhichis how manynaive LINQ implementationswork : synchronously pipelining methods calls on collectionsLINQ has an interesting twistExpression trees
  • 9. Expression Trees and IQueryableLet’stake the sameexample and introduceAsQueryable()Uponexecution, wecan notice the compiler didn’teatour LINQ expressionIt’sstill in there, using a tree format (an AbstractSymbolTree)That treewillberesolvedatruntimeIn the Linq to Objects case, wegetexactly the samebehaviour. The iteration pattern maystillbeyield-based, but thisisleft to IQueryable’simplementationdetails.
  • 10. Playingwith expression treesLet’stackleLinq To SQLMy expression treeisnowpushed to the database layerIf I want to block the flow to SQL, I just have to insert a new node in the tree.Whichallows me to balance thingsUsing C# patterns and methodswhen I wantthemPushing to the databasewhatitdoes best
  • 11. IQueryable goodiesSo, if I wantmythings to be LINQ aware, I caneitherBuildsomemethods and let the IEnumerable<T> do its pure objectmagic (I stillgetlazyeval)Or, playwithIQueryableAnd do myowninterpretation of the treeLet’sseeMongoDB in LINQ
  • 12. Strongly-typed interaction when querying and updating collections.Improved interface to send common Mongo commands (creating indices, getting all the existing dbs and collections, etc.).Ultra-fast de/serialization of BSON to .Net CLR types and back.LINQ-to-MongoSupport for Mono
  • 13. LINQ PatternsHaving a LINQ Expression isnice: youbasicallydelegate the execution to someoneelse’s codePlus, your LINQ Expressions have every good aspect youusuallyexpectfromfunctionalprogramming (ie, they are closures).So, they are perfectlysuited to parallelisationAll you have to do isaddanothernode to the expression treeDemo : AsParallel()
  • 14. WritingMapReduce in LINQ public static IQueryable<R>  MapReduce<S,M,K,R>(this IQueryable<S> source,                                 Expression<Func<S,IEnumerable<M>>> mapper,                                 Expression<Func<M,K>> keySelector,                                 Expression<Func<K,IEnumerable<M>,R>> reducer){    return source.SelectMany(mapper).GroupBy(keySelector, reducer);}Notice that the callingsyntax : Source.MapReduce(lMapper, lKeySelector, lReducer)issimply a new nodethatcanbeinserted in a larger expression tree.This MapReducemethodcanrun on N coresusing PLINQ, or on X machines (and N cores per machine) usingDryadLINQ
  • 15. Collection<T> collection;boolIsLegal(Key k); string Hash(Key);var results = from c in collection where IsLegal(c.key) select new { Hash(c.key), c.value};DryadLINQ = LINQ + DryadVertexcodeQueryplan(Dryad job)DatacollectionC#C#C#C#results
  • 16. Parallel executionvar logentries = from line in logswhere !line.StartsWith("#")select new LogEntry(line);var user = from access in logentrieswhere access.user.EndsWith(@"\ulfar")select access;var accesses =from access in usergroup access by access.page into pagesselect new UserPageCount("ulfar", pages.Key, pages.Count());var htmAccesses =from access in accesseswhere access.page.EndsWith(".htm")orderby access.count descendingselect access;