Wednesday, April 8, 2009

Fascination with LINQ

I was walking on my trail today and came across this item called, Lambda expression.

Speaking of which, "what are these?" one may ask.

It is basically simplification of LINQ query statements.

For example, the where-clause in LINQ.

From s In Someone _
Where s.Age > 0 _
Select s

can be simplified to a 1-liner.

Someone.Where(Function(s) s.Age > 0)

A point to note however is that my 1-liner is in VB.

Interesting, don't you think?

For more on this, visit Wiki-LINQ here

Friday, April 3, 2009

Properties (Getters and Setters)

Today is another break-through or relevation so to speak.

This might be trivial, although I recently discovered that storing the data for later use may not require caching, viewstates or sessions.

Interesting as it be, data can be stored in properties (VB.Net specific) or simply Getters and Setters in the general object-orientation methology sense.

It is important to note that this will only work if you are not deviating from the current class.

How did this came in handy for me? Web development tends to rely on UI objects on the web page. So much so that we forget that essentially the "code-behind" contains of methods wrap within a class.

Hence, using OO methology, we can simply create a property (getters and setters) to maintain data for any data that we would like to preserve.

Example. (VB.Net code)
Public Property orderByStr() As String
Get Return _OrderBy End Get
Set(ByVal value As String) _OrderBy = value End Set
End Property

In this case, for example, I had a data table that I wanted to sort by a certain order.

To determine whether I would have the table ordered by ascending or descending order, I simply use the property above. This can also be expanded to determine how to sort if the previous sorting column is different than the current one.

So much so for a relevation. I was brought down despite thinking that this may work.
Someone proof me wrong but I ended up caching.