-2

Ok, I have a question, wich might sound weird.

Let's say I have the following home made objects : cTask ,cPriority, cResource

My task object has a property Priority (as cPriority) and a property Resource (as cResouce). In my data model, a task got a priorityID and I have a table 1 to many for the resources (having TaskID and ResourceID)

So I get something like : task.priority.id, task.priority.name, task.resource(1).name, and so on.

I also have the following methods in cTask : Add(), Delete(), Update().

What would be the best way to handle those methods ?

Here are the option I can think about :

  1. Look at the propertys to save the "normal" fields and add optionnal parameters to save the ResourceID in the same call (like task.update(SomePriorityID)). But it's ugly.

  2. Doing something like :

dim xPriority as new cPriority(somecontrol.selectedvalue) 

dim xTask as new cTask 

xTask.Priority = xPriority 

... more code 

xTask.Add()

Again here, I find this solution ... not perfect.

  1. Finally I could add other propertys to cTask such as ResourceID.

What is the best practice for this situation ?

Thanks !

David
  • 429
  • 1
  • 4
  • 10
  • 8
    Your class names should not start with `c`. Do not use Hungarian notation, especially for types. – SLaks Aug 10 '11 at 18:07
  • 1
    http://msdn.microsoft.com/en-us/library/ms229045.aspx `Do not use Hungarian notation.` – SLaks Aug 10 '11 at 18:12
  • @David: Because it conflicts with the C# style recommendations / coding standards - see FxCop – BrokenGlass Aug 10 '11 at 18:13
  • 1
    @SLaks thanks ! But that doesn't help with my issue. – David Aug 10 '11 at 18:13
  • That's why it was a comment and not an answer – Oskar Kjellin Aug 10 '11 at 18:23
  • @David: here are more informations why you should avoid hungarian notation: http://www.joelonsoftware.com/articles/Wrong.html And here is a SO-question on this topic: http://stackoverflow.com/questions/768255/hungarian-notation-in-c – Tim Schmelter Aug 10 '11 at 18:47
  • Consider rewording your question and explaining it better, I want to help but I'm not sure whats being asked here. – Odnxe Aug 10 '11 at 20:16

1 Answers1

0

I'm afraid you are rinventing the wheel. You should look into ORM's to solve your problem.

Something that is based on activerecord would suit your style of programming perfectly.

Look into CSLA.Net.

chrissie1
  • 5,014
  • 3
  • 26
  • 26
  • Most of these solutions are open source so go ahead and look at their code and see how they resolved your problem. – chrissie1 Aug 11 '11 at 07:31