Linq Refresher

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Notes on slide 1

    Who am I?

    What does LINQ stand for? Integrated right into the middle of your coding experience.

    The most basic form of query is selecting something

    You all (i think) would have seen SQL the “other” query language
    LINQ has a comparable but different syntax in key areas
    notice the ordering of from-where-select

    First we need some other information, not strictly part of LINQ, anonymous types.
    What are Anonymous Types?

    Anonymouse types allow you to:
    this is to facilitate projections=> projecting one set of data into a related but different set

    So revisiting the original query we’re “Selecting” an Anonymous type so what do we get

    We get a container holding a whole bunch of Anonymous Types and IEnumerable where T is our anonymous types, other interfaces you may see in linq are IQueriable and IOrderedEnumerable

    So what other functions can we use LINQ to perform

    Order by:
    pretty similar to SQL’s ORDER BY statement

    inner and outer joins

    let statements allow you to do a function within link and assign the value to a variable, kind of like an embedded function

    LINQ can also be done using extension methods, which may look a bit friendlier to those who don’t want to pepper their code with from syntax

    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

    eg


    recap




    Favorites, Groups & Events

    Linq Refresher - Presentation Transcript

    1. LINQ Refresher Owen Evans, Developer, Xero Blogger, http://bgeek.net Thursday, February 19, 2009
    2. LINQ Thursday, February 19, 2009
    3. Language INtegrated Query 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
    11. Order By Thursday, February 19, 2009
    12. Join Thursday, February 19, 2009
    13. Let 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
    21. FIN Thursday, February 19, 2009

    + buildmasterbuildmaster, 9 months ago

    custom

    353 views, 0 favs, 0 embeds more stats

    Slides from the Wellington .net User Group on Wedne more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 353
      • 353 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 12
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories