SlideShare ist ein Scribd-Unternehmen logo
1 von 21
LINQ Refresher
          Owen Evans,
          Developer, Xero
          Blogger, http://bgeek.net




Thursday, February 19, 2009
LINQ




Thursday, February 19, 2009
Language INtegrated Query




Thursday, February 19, 2009
SELECT
          lets start at the beginning

Thursday, February 19, 2009
SELECT
               Structured Separated   LINQ
               Query Language (SQL)




Thursday, February 19, 2009
Back Up
          Anonymous Types

Thursday, February 19, 2009
Anonymous Types

               Allow you to create a new type without defining a class
                     two methods of declaration
                              explicit new{ObjectName=object.Name}
                              implicit new{object.Description}
                                new{object.Name} is the same as
                                new{Name=object.Name}



Thursday, February 19, 2009
Revisiting Select
         What does this give us?




Thursday, February 19, 2009
Answer?




           An IEnumerable<T>    Also See IQueriable<T>
                                          and
                               IOrderedEnumerable<T>

Thursday, February 19, 2009
Order
          get in line

Thursday, February 19, 2009
Order By




Thursday, February 19, 2009
Join




Thursday, February 19, 2009
Let




Thursday, February 19, 2009
LINQ as Extension Methods




Thursday, February 19, 2009
Late Evaluation

               LINQ queries are not evaluated until you need the
               results (foreach, count, etc.)
               Allows for optimisation and building up of the query
               over time
               Can produce unexpected results if you don’t know
               what to expect




Thursday, February 19, 2009
Late eval can hide errors




Thursday, February 19, 2009
Things to remember about
          LINQ
               From Comes First (for intellisense purposes)
               can be written using extension methods (helps in
               exploring what is possible)
               Can project to new lists of objects or anonymous
               objects
               Beware hard to follow LINQ
               Late Evaluation: things can change, beware holding
               onto the IEnumerable for too long.


Thursday, February 19, 2009
All in one place




Thursday, February 19, 2009
References

               MSDN: http://msdn.microsoft.com/en-us/library/
               bb308959.aspx
               LINQ over REST (Astoria): http://msdn.microsoft.com/
               en-us/library/bb308959.aspx
               Many many ORM’s now providing LINQ support:
               Lightspeed, NHibernate, LINQ to Entities (LINQ to SQL
               too but abandoned)



Thursday, February 19, 2009
A Few More References
          (thanks to Simon Green)

               http://www.linqpad.net/
               Great for learning LINQ, includes heaps of samples
               Works outside of Visual Studio
               See the generated SQL or lambda
               http://www.albahari.com/nutshell/linqbridge.aspx
               Use LINQ to Objects in projects targeting .NET 2.0




Thursday, February 19, 2009
FIN




Thursday, February 19, 2009

Weitere ähnliche Inhalte

Mehr von buildmaster

DevOps is Dead. Long live devops
DevOps is Dead. Long live devopsDevOps is Dead. Long live devops
DevOps is Dead. Long live devopsbuildmaster
 
API Days: For the Love of Small
API Days: For the Love of SmallAPI Days: For the Love of Small
API Days: For the Love of Smallbuildmaster
 
MEFilicious Applications
MEFilicious ApplicationsMEFilicious Applications
MEFilicious Applicationsbuildmaster
 
Bahaviour Driven Development
Bahaviour Driven DevelopmentBahaviour Driven Development
Bahaviour Driven Developmentbuildmaster
 
ASP.net MVC CodeCamp Presentation
ASP.net MVC CodeCamp PresentationASP.net MVC CodeCamp Presentation
ASP.net MVC CodeCamp Presentationbuildmaster
 

Mehr von buildmaster (7)

DevOps is Dead. Long live devops
DevOps is Dead. Long live devopsDevOps is Dead. Long live devops
DevOps is Dead. Long live devops
 
API Days: For the Love of Small
API Days: For the Love of SmallAPI Days: For the Love of Small
API Days: For the Love of Small
 
MEFilicious Applications
MEFilicious ApplicationsMEFilicious Applications
MEFilicious Applications
 
Bahaviour Driven Development
Bahaviour Driven DevelopmentBahaviour Driven Development
Bahaviour Driven Development
 
Oslo
OsloOslo
Oslo
 
ASP.net MVC CodeCamp Presentation
ASP.net MVC CodeCamp PresentationASP.net MVC CodeCamp Presentation
ASP.net MVC CodeCamp Presentation
 
Mocking 101
Mocking 101Mocking 101
Mocking 101
 

Kürzlich hochgeladen

Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Kürzlich hochgeladen (20)

Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

Linq Refresher

  • 1. LINQ Refresher Owen Evans, Developer, Xero Blogger, http://bgeek.net Thursday, February 19, 2009
  • 4. SELECT lets start at the beginning Thursday, February 19, 2009
  • 5. SELECT Structured Separated LINQ Query Language (SQL) Thursday, February 19, 2009
  • 6. Back Up Anonymous Types Thursday, February 19, 2009
  • 7. Anonymous Types Allow you to create a new type without defining a class two methods of declaration explicit new{ObjectName=object.Name} implicit new{object.Description} new{object.Name} is the same as new{Name=object.Name} Thursday, February 19, 2009
  • 8. Revisiting Select What does this give us? Thursday, February 19, 2009
  • 9. Answer? An IEnumerable<T> Also See IQueriable<T> and IOrderedEnumerable<T> Thursday, February 19, 2009
  • 10. Order get in line Thursday, February 19, 2009
  • 14. LINQ as Extension Methods Thursday, February 19, 2009
  • 15. Late Evaluation LINQ queries are not evaluated until you need the results (foreach, count, etc.) Allows for optimisation and building up of the query over time Can produce unexpected results if you don’t know what to expect Thursday, February 19, 2009
  • 16. Late eval can hide errors Thursday, February 19, 2009
  • 17. Things to remember about LINQ From Comes First (for intellisense purposes) can be written using extension methods (helps in exploring what is possible) Can project to new lists of objects or anonymous objects Beware hard to follow LINQ Late Evaluation: things can change, beware holding onto the IEnumerable for too long. Thursday, February 19, 2009
  • 18. All in one place Thursday, February 19, 2009
  • 19. References MSDN: http://msdn.microsoft.com/en-us/library/ bb308959.aspx LINQ over REST (Astoria): http://msdn.microsoft.com/ en-us/library/bb308959.aspx Many many ORM’s now providing LINQ support: Lightspeed, NHibernate, LINQ to Entities (LINQ to SQL too but abandoned) Thursday, February 19, 2009
  • 20. A Few More References (thanks to Simon Green) http://www.linqpad.net/ Great for learning LINQ, includes heaps of samples Works outside of Visual Studio See the generated SQL or lambda http://www.albahari.com/nutshell/linqbridge.aspx Use LINQ to Objects in projects targeting .NET 2.0 Thursday, February 19, 2009

Hinweis der Redaktion

  1. Who am I?
  2. What does LINQ stand for? Integrated right into the middle of your coding experience.
  3. The most basic form of query is selecting something
  4. You all (i think) would have seen SQL the &#x201C;other&#x201D; query language LINQ has a comparable but different syntax in key areas notice the ordering of from-where-select
  5. First we need some other information, not strictly part of LINQ, anonymous types. What are Anonymous Types?
  6. Anonymouse types allow you to: this is to facilitate projections=> projecting one set of data into a related but different set
  7. So revisiting the original query we&#x2019;re &#x201C;Selecting&#x201D; an Anonymous type so what do we get
  8. We get a container holding a whole bunch of Anonymous Types and IEnumerable<T> where T is our anonymous types, other interfaces you may see in linq are IQueriable and IOrderedEnumerable<T>
  9. So what other functions can we use LINQ to perform
  10. Order by: pretty similar to SQL&#x2019;s ORDER BY statement
  11. inner and outer joins
  12. let statements allow you to do a function within link and assign the value to a variable, kind of like an embedded function
  13. LINQ can also be done using extension methods, which may look a bit friendlier to those who don&#x2019;t want to pepper their code with from syntax
  14. A word about linq: IEnumerables are evaluated only at the time they need to be, (such as on Count, ToList, To Array, Foreach) this allows optimisation of the query you want to perform and composit building of queries. Can hide mistakes or bugs, or at least throw the error much later
  15. eg
  16. recap