generic Data fetcher
I'd like to know a way to assign any query result to a generic List based on the mapping between column names开发者_如何学C and object's property names.
public List getData(string sql, Type object_type)
for example, I have the following sql and an object:
Select name, address, phone from ''' where ...
Class Person { string name; string address; string phone; }
public List getData(string sql, Type type) { ... }
There are packages that already do this -- it's called object-relational mapping.
http://en.wikipedia.org/wiki/Object-relational_mapping
NHibernate is a popular one.
精彩评论