LINQ to SQL cheat sheet

Thumbnail of the LINQ to SQL Cheat Sheet PDF

A few short words to say I’ve put together a cheat sheet for LINQ to SQL with one page for C# and another for VB.NET.

It shows the syntax for a number of common query operations, manipulations and attributes and can be a very useful quick reference :)

Download LINQ to SQL cheat sheet (PDF) (76 KB)

[)amien

One response

  1. Avatar for Jeff Handley

    This is excellent, thanks!

    Jeff Handley August 13th, 2009
  2. Avatar for Joel

    Thanks for the sheet, I can see this being very helpful. It’s also quite nice that you split the C# & VB into separate pages.

    Joel August 13th, 2009
  3. Avatar for Damien Guard

    @Harry I just enabled it for Google Reader, which one are you using? @Everyone Else: Thanks for the compliments guys. I’ve never been so retweeted.

    Damien Guard August 13th, 2009
  4. Avatar for KristoferA

    Very neat. I think you should put a link to the cheat sheet as a pegged topic in the msdn linq forums…

    KristoferA August 13th, 2009
  5. Avatar for Peter Bromberg

    Nice job, Damien! Your efforts are appreciated!

    Peter Bromberg August 13th, 2009
  6. Avatar for marcobdv

    First of all a nice job, if you’re intrested we designed a poster for linq see http://www.infosupport.com/LINQ (site is in dutch) but google translate shoot help you there

    marcobdv August 14th, 2009
  7. Avatar for Jim Wooley

    On your VB sheet, you should consider using the VB’s additional support of query operators Distinct, Skip, Take, Aggregate, Sum, Count, Etc. For example the Paging and Ordering example could be re-written in VB as:

    Dim page3 = From c In db.Customers _ Order By c.ContactName, c.City Descending _ Distinct _ Skip 10 _ Take 5

    Also, notice the Select is optional in VB if you project the entire object. When using a simple projection, you don’t need the object initializer syntax either. If you just wanted to project the ContactName and City in the above example, you could do the following:

    Dim page3 = From c In db.Customers _ Order By c.ContactName, c.City Descending _ Select Name = c.ContactName, c.City _ Distinct _ Skip 10 _ Take 5

    VB takes away a number of the method syntax hurdles that C# requires.

    Jim Wooley August 14th, 2009
  8. Avatar for Damien Guard

    Thanks Jim, I’ll update the sheet over the weekend with your changes. I have written a fair amount of code in VB.Net but I have to admit it was all prior to .NET 3.5.

    Damien Guard August 14th, 2009
  9. Avatar for William Wegerson

    Excellent and thanks! But one word though: landscape The boxes are cramped horizontally, maybe Landscape would allow for formatted code(?). Yes I know, everyone is a critic.

    William Wegerson August 14th, 2009
  10. Avatar for Milan Negovan

    Damien, Thank you for the cheat sheet! I made a similar one for LINQ Standard Query Operators Hope this helps anyone, Milan

    Milan Negovan August 23rd, 2009
  11. Avatar for KALYAN

    Thanks for the cheat sheet. It is just the one I was looking for.

    KALYAN – August 27th, 2009
  12. Avatar for sshow

    You just managed to teach me LINQ to SQL in one A4 page. Thanks alot!

    sshow – September 3rd, 2009
  13. Avatar for SoCalSam

    Thanks Damien. I’m just starting a project that I wanted to use LINQ with, and this will help me a lot!

    SoCalSam – November 18th, 2009
  14. Avatar for ARLibertarian

    Thanks a LOT. I’m doing a project and having to learn this stuff on the fly. This helps!

    ARLibertarian – March 6th, 2010
  15. Avatar for Arvind Singh

    Thanks, its really shortest way to implement query using LINQ.

    Arvind Singh – December 25th, 2011