Friday, November 18, 2011

Handle Data in .NET 4.0 and .NET 2.0


Recently i involved in .NET 2.0 project and experienced few technical issues cause of less default support available . Today im going to explain how i overcome those .

Well .NET 4.0 came with lot of user friendly lovely features ( though we have to think 100 ways before use them ) . However i like the way they handle data structures . Especially LINQ queries with lambda expressions . Though there are many  arguments for using LINQ i would personally think , " Eventually LINQ is quite good(may be most ideal ) for small scale projects .


When we have a data set from sq l server we can manipulate it using data structures with in our server side code . Generic lists are favorites . But someone still can use dictionary or hash table up to their requirements . When you want to store ur objects belongs to some key for ease of search and identification , hashtables are good . So now everything is typed ( strongly typed) we have our general person ( employee/ contact / manager ) and product classes ( objects would represent them ) . So we fill them out and store in a generic list . Everything is mapped pretty sweetly and we call it ORM .

Well above is small and common scope in day today programming .

After we fill the list of objects , next task is to utilize the data . LINQ comes to scene and sort our all problems in quick steps . ( LINQ queries are pretty cool and easy to learn / Simply revert our sql query order ) .Say we have 1main list ,

1)managershavecontacts list

You can query it and get whatever data with mentioning the relationship .


Now our lives are cool because of those features introduced with .NET 3.5 / 4.0 .

But you still can involve in 2.0 project . How would you do without linq ?


Basics are same . You create a generic list .as above main list .

  1. First sort the list with some predicate condition . We have default sort() function . Include some custom predicate (if you compare objects ) to notify compiler about your sorting method .You can override Compare To() method and write one .
  2. If you wanna Group the list you need to remove the duplicates .
  3. Write a simple logic ,
  4. create another list of same type and fill that list from your previous list by checking for exist value .
  5. You probably needs a contains() method .
  6. To handle some complex scenarios you may need dictionaries .
  7. Store your object with keeping object's ID field as a key
  8. Then filter and search for whatever your known items in dictionary

    Please note when search for item , list.Contains() method is slow but easy to use .After finalize the programming logic and complete the code we can think about optimizing .  In later article ill come up with tricks .

So above are some information for handle the scenarios with or without LINQ .
Anyway some of my blog readers ask me to write some server side programming articles and here is a beginning .
You guys should keep this in your mind . Server side code is easy since we all are good in logic's and till good debuggers exist in programming world . But client side code is different we should have some rare skills on sort those without debuggers ( there are like firebug though ) . And client side code syntax also kinda difficult and hard to read  . Most of developers dont use concepts in writing client scripts . Therefore work in client is lot more work and harder in programming world and i always encourage everyone to learn it .









2 comments: