Nov. 7th, 2008

netbard: (Default)
Yes, its another geeky entry. You'll just have to deal. :)

Anyways. So as anyone who has been reading this knows, I've been working with LINQ-To-SQL in the new project. This has been amazingly productive - things that previously took multiple lines of code and a conversion from the SQL layer to the business logic now takes one line.

For instance - an item on a survey, which may have one or more comments regarding it in a separate table, which we need to copy into a List so that we can serialize it and pass it to javascript using JSON.

The original approach using ADO.NET (but not DataSets, because I hate DataSets with a passion) would have required that I create a SqlConnection, then create a SqlCommand object paramaterized with a SurveyItemId and including a join to the User table so that I can get the user's name who left the last comment. I would then need to get a SqlDataReader from this and iterate through the results, creating a new comment object for each row, while being careful to cast each and every element in the SqlDataReader.

All in all, this would probably have been 10 - 15 lines of code. And some debugging since there is no compile-time checking for SQL statements.

The same code in LINQ:
_priorComments.AddRange(surveyItem.SurveyItemComments.Select(Function(sic) New SerializedComment(sic)))


Uh, yeah.

Profile

netbard: (Default)
netbard

September 2025

S M T W T F S
 123456
78910111213
14151617181920
2122232425 26 27
28 29 30    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Oct. 2nd, 2025 10:57 am
Powered by Dreamwidth Studios