I am used to making separate Business Object and List<> classes for my DB tables. Sometimes I just have a basic task in hand as displaying a list of year for a search box or having some values in a drop down.
Right now I am ending up with a lot of separate classes and List classes<> for these basic operations.
How can I make a single class for some basic tasks as these by using generics?
I want to have single class for some methods like get current year, employee names, Department Name/Code, Title etc. Please give me an example. I am using .NET 2.0.
Edit
After some searching, I found that I can achieve similar tasks by creating a DTO namespace.
What I don’t get right now is how to create multiple classes inside my DTO class. Say 1 class for just returning ‘year’, One for ‘Employee Name/Code’ and so on inside the single DTO class.
You can map your classes with DB Table manually or you can use NHibernate which is an advanced ORM which works quiet well with .Net 2.0.
Basically you can map your plain c# classes to DB table using a simple xml mapping file.
Example a class called Product can
can be mapped to a DB table using following mapping file.
This also has good support for .Net Collections. There is sure some learning curve but the productivity benefit is worth.
More example can be found here.
http://nhforge.org/wikis/howtonh/your-first-nhibernate-based-application.aspx