Generic Problem

Apr 19 2008 3:48 PM

I design simple DAL using Generic, i have 2 business objects matched to each other, one in BusLayer and the other in DAL.
DAL just deal with DAL.Domain.Categories
BusLayer see  Business.BusinessObject.Categorie  and DAL.Domain.Categories
DALProxy  is a class in business layer and it the only class talk with DAL
in Business Layer when developer need to get a recored from DB , he will write the following:

public Business.BusinessObject.Categorie GetCategorie(string primKey)


DALProxy proxy = new DALProxy("Connection string ....");

Business.BusinessObject.Categorie cat = proxy.GetRecord<Business.BusinessObject.Categorie, DAL.Domain.Categories>(primKey);

Return cat;


Then GetRecord Method in DALProxy call DAL DAO

public T GetRecord<T,U>(object key)


DAO dao = new DAO("");
T busObject  = new T();

domainObject = dao.GetRecord<U>(key);
// then map U to T before return T
T busObject = Mapper.Map(domainObject ,busObject );
return busObject ;

My Question is how to make Proxy.get Record take just T, not T and U.
i mean developer not need to know the matching Domain object and type it.
i need it to be implicit, and to be my  problem is explained well i have a stupid solution:
in proxy getrecord i will check type of T, if it a type of Categories then Call DAO.getRecord<DAL.Domain.Categories>, so i will have 150 if statments for each busobject
any smart solution

Answers (2)