This question is locked. New answers and comments are not allowed.
Hi
I'm trying to learn OO programming and I've read two books on OOP and LINQ before I started on the OA documentation, but I think I'm still missing some core understanding.
I've managed to set up a vertical hierarchy of classes where "Administrator" is an "Employee" is a "Person". However I'm still stuck in relational thinking as I can't figure out how to connect lookup tables.
The Person class has four properties; PersonID (int), FirstName, LastName, StatusID (int).
In my old non-OO solution Person.StatusID was linked in the database to table Statuses with fields StatusID (int) and Name. In the application I would then add a combo box that showed the list of Statuses.Name, but saved the value to Person.StausID.
In the OA documentation the examples creates (using my solution) a Status object in Person, rather than having StatusID as an int. And here my understanding breaks down...
Using copy and paste rather than understanding I changed my Person class to add property
First of all, when forward mapping this to the database, I get an int field named Status in my Persons table. Is that correct, being an int?
Secondly, how would I go about accessing this information?
I'm trying to learn OO programming and I've read two books on OOP and LINQ before I started on the OA documentation, but I think I'm still missing some core understanding.
I've managed to set up a vertical hierarchy of classes where "Administrator" is an "Employee" is a "Person". However I'm still stuck in relational thinking as I can't figure out how to connect lookup tables.
The Person class has four properties; PersonID (int), FirstName, LastName, StatusID (int).
In my old non-OO solution Person.StatusID was linked in the database to table Statuses with fields StatusID (int) and Name. In the application I would then add a combo box that showed the list of Statuses.Name, but saved the value to Person.StausID.
In the OA documentation the examples creates (using my solution) a Status object in Person, rather than having StatusID as an int. And here my understanding breaks down...
Using copy and paste rather than understanding I changed my Person class to add property
private Status _status; |
public Status Status |
{ |
get |
{ |
return _status; |
} |
set |
{ |
_status = value; |
} |
} |
First of all, when forward mapping this to the database, I get an int field named Status in my Persons table. Is that correct, being an int?
Secondly, how would I go about accessing this information?
namespace Training |
{ |
class Program |
{ |
static void Main(string[] args) |
{ |
using (IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope()) |
{ |
scope.Transaction.Begin(); |
Person p = new Person(); |
p.FirstName = "Dennis"; |
p.LastName = "Gundersen"; |
//p.StatusID = 2; OLD VERSION |
//p.Status WHAT HAPPENS NEXT? |
scope.Add(p); |
scope.Transaction.Commit(); |
} |
} |
} |
} |
p.StatusID= the PK of the chosen Staus I understand, but my brain melts over p.Status = something. Should I use LINQ to SQL to lookup the values? Should Status be some sort of List instead of a class? Should I use a Struct? Aaaaargh!!!
I'm convinced that this is very easy, but I just can't grasp it to my great annoyance!
Somebody, please help!! I promise I've done a lot of searching and reading on my own already, but it's difficult to find answers when you don't know what to search for.
TIA!
Re
Dennis