0

I would kindly ask for some help in creating classes that are based on Database diagrams. I am writing my code in C#. And my main doubt is how to create references from one class to another so that it matches my Database diagrams.

For example, in my Database I have 2 initial tables: Screenplay and ScreenplayWriter. Screenplay has attributes screenplayID, movieID, description and ScreenPlayWriter has attributes ScreenplayWriterID, personID. Then I have the 3rd table which connects these 2 initial tables and this one is called WritesScreenplay and this table has attributes screenplayID, screenplayWriterID.

Now I would want to transcribe those tables into C# classes. I am assuming I only need two initial classes Screenplay and ScreenplayWriter and that the 3rd one can be derived only as a reference between those initial two. I don't know how to write these references in code so that it makes sense. Note by, one screenplay can have multiple screenplay writers.

Any help would be greatly appreciated. Regards

Whizzil
  • 1,264
  • 6
  • 22
  • 39
  • Assuming multiple writers per screenplay you'd need an array or a collection to contain writerids in your linking class. – Tim Apr 02 '13 at 13:35
  • But do I really need a linking class? I was thinking only references from one class to another. – Whizzil Apr 02 '13 at 13:38

1 Answers1

0

You can use Entity Framework. It can solve many of your problem if possible.

for your listed problem , ScreenPlay and ScreenPlayWriters has 1 :m relationships

so something like below in which one screenplay object can contain a list of writers

public class ScreenPlay
{
    public IList<ScreenPlayWriter> Writers {get;set}
}

public class ScreenPlayWriter
{
}
TalentTuner
  • 17,262
  • 5
  • 38
  • 63
  • it is just the auto property declaration in c#, see below link. http://msdn.microsoft.com/en-IN/library/bb384054.aspx – TalentTuner Apr 02 '13 at 14:05
  • @Whizzil: the IList is an analog of the array or collection but with different behavior; it is a structure (term loosely used) to hold multiple items. Saurabh is suggesting that your ScreenPlay class contain a "nested" list of its writers. The value inside the angle brackets refers to a class/type. – Tim Apr 02 '13 at 14:11