1

I didn't know if this should be posted here or on Programmers - Sorry.

I want to be able to have a method that I can call like (psuedo code):

RegisterField("FIELD", Variable);

RegisterField then adds a pointer to Variable to a list so that I can loop through it and update database column "FIELD". Whenever Variable changes then the value in the list should represent that (hence the pointer) I am not really sure which direction to start from with this so am looking for some advice.

If the idea is wrong then could somepoint point me in the correct direction?

p.s The idea is I can have a base class that I includes RegisterField so all classes derived from it can support auto updating database changes.

webnoob
  • 15,747
  • 13
  • 83
  • 165

1 Answers1

2

One option is to look at an ORM like the Entity Framework which makes it easy for you to map your C# classes to a database.

There are also other ORMs. See Some suggestions on which .NET ORM to look at learning

If you don't want to do an ORM and do direct sql, I would advise against round tripping to the database on every property set. You would have to have a datastructure internal to the object (base object) that tracks what changed and then have a Save method which rountrips to the DB. Depending on how generic you want it to be (RegisterField suggests generic) then it can get pretty complex in a hurry especially when you start considering object references & hierarchies. If that's the direction you're going, I would definately recommend an ORM.

Community
  • 1
  • 1
bryanmac
  • 38,941
  • 11
  • 91
  • 99