Skip to content

My first LINQ Experience. How to do a simple COUNT() with LINQ to SQL

Updated: at 06:25 PM

So, nothing extraordinary here, but I've finally taken the dive into LINQ.  I've got a great book that helping me a lot that I recently review called Pro LINQ by Joseph Rattz (his humor is a little odd, but the book is great).  At anyrate, moving right a long, all I did was right click on my web projects app_code directory, choose LINQ to SQL classes,

appcode

Then, choose some tables from my database. Then, in my code, all I had to write was the class in my c# code (part of my database layer classes).  Here is what the code looks like (sorry about the jpg, I'm still trying to figure out how to get Copy SourceAsHTML working in vs2008)

linq1

And, without LINQ, this is what I would have had to do.  No type safety and took 3 times as long to write.

linq2

You can tell what I'll be doing for now on (climbing the curve!)