Monthly Archives: January 2013

Asp.Net & ORM Tool NHibernate For Dummy Tutorial – Select & Insert Operation

NHibernate is a open source Object-Relational Mapping (ORM) tool. This ORM tool hides sql query complexities by replacing query with mapping and class object.
Every .Net Project can use Nhibernate to work with database.

The purpose of NHibernate is to save developers work time thus increasing productivity. Large application may get more benefit from NHibernate than small app.

This blog post gives Asp.Net & NHibernate dummy examples. These examples cover select / retrieve records and insert a new record.

First thing first, we need to download Nhibernate files. Please download the zip file from http://sourceforge.net/projects/nhibernate/

As a brief, we need xml mapping file, a class which representates DB table, Nhibernate dll file, NHibernate xml configuration file, and Asp.Net file it self that contains NHibernate configuration object, NHibernate session etc to provide data to UI.

I use VS 2010 Express & SQL Server 2008 R2 to build this example.
Continue reading

Advertisements

Abstract Factory Pattern Example With C#

Abstract factory pattern is to “provide an interface for creating families of related or dependent objects without specifying their concrete classes.”

For example a drawing & printing machine can process Low and High Resolution. Both have its own resolution drivers. Those drivers referred to concrete class with draw / print function. However the client implementation code asks the factory object class (not the concrete class) for a driver instance with provides information about resolution required. So this factory object return instance of concrete class.
The factory object implements an abstract class. It can instantiates a concrete class and return to client with casted to factory’s parent which is abstract Resolution driver.
The client uses the resolution driver as abstract without being aware about their concrete implementation.

Benefit of using factory pattern is in client code implementation, new resolution can be added with just providing that new resolution info as argument. So no change in client code.
Continue reading