0

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.

Tony_Henrich
  • 42,411
  • 75
  • 239
  • 374

2 Answers2

0

Look into the various ORMs out there. For mapping a legacy database, NHibernate is perfect.

mxmissile
  • 11,464
  • 3
  • 53
  • 79
  • I can't use third party ORMs. I prefer to do it in .NET or maybe LINQ. – Tony_Henrich Jun 29 '09 at 21:43
  • I don't understand that mentality, that's like saying "I can't use a screwdriver to turn a screw". Oh well I guess... – mxmissile Jun 29 '09 at 22:40
  • Some companies do not allow third part components for simple solutions. You're telling to use a powertoolbox for something simple. Throwing in nHibernate which is a major ORM tool just so that I have to type less is not a good idea. This also means every developer in the team has to learn it. I am looking for a solution a I can code in less than an hour. – Tony_Henrich Jun 29 '09 at 23:14
0

If you can't use NHibernate (and I would strongly suggest you do) or are not able to use LINQ to SQL (perhaps you're code base is .NET 2.0) then...

You will probably want to implement some form of factory pattern. Inside your factory object you might want to return a strongly data-set then use an object to object mapper to translate between your data-set and DTO/View/Entity objects. Jimmy from Los Techies has created a great open source object to object mapper which you might find very useful: AutoMapper.

Happy coding.

kit
  • 1,166
  • 5
  • 16
  • 23
Kane
  • 16,471
  • 11
  • 61
  • 86