Mapping class properties to generic columns in table .NET
Posted
by Tony_Henrich
on Stack Overflow
See other posts from Stack Overflow
or by Tony_Henrich
Published on 2009-06-29T21:37:45Z
Indexed on
2010/03/31
20:03 UTC
Read the original article
Hit count: 332
I have have a SQL Server table which has generic names like Text1, Text2.. etc. The table was designed like this because the same structure is used for different projects.
I have a class in .NET which has properties. Say a Customer class has a property called FirstName.
How can I do the mapping from FirstName to Text1 just once (central place) in the application so that I don't have to remember and hard code the mappings all over the app when I create the different DAL methods?
For example, I want the app to know when I want to update, insert a FirstName, the DAL automatically uses Text1. Basically I don't have to remember which property goes to which column. The idea is so the developers do not map the properlies/columns in a wrong way. It's always consistent.
Note: Database inserts, updates and deletes are allowed through stored procedures only.
© Stack Overflow or respective owner