|
-
Dec 30th, 2004, 03:59 PM
#2
PowerPoster
Re: Data Classes
Cool, this is fun exercise. After using mine for a while, I have found that I want to change quite a few things. It works really well (although I never have polished it or did the error corrections that are needed for the masses).
To answer your specific question if I understand itright:
For instance if a table is a child relation of another table should the child data object include every field of the parent as a property? Contain just a Key? Contain a nested object? Do Nested Objects Bind Properly, I've never tried?
I expose a child collection as a collection object from the main object. For instance. I have a User table. I also have a Phone table. A User can have many Phones, so there is a One-To-Many relationship between User and Phone. In an object model, I expose it like this:
Code:
User myUser = new User();
// Do whatever to load your user with data.
//When I want to access the phone numbers this user has, I do this...
myUser.Phones[0].PhoneNumber
// I can loop through them easily using foreach...
foreach (Phone phn in myUser.Phones)
{
// Do something with phn.
}
// I can bind Phones to a datagrid...
dgPhones.DataSource = myUser.Phones
// I can add new Phone objects to the myUser.Phones collection like this...
Phone newPhone = new Phone();
newPhone.PhoneNumber = "123-1231";
myUser.Phones.Add(newPhone);
//This should save any changes to user, along with any changes to any of the phones, added phones, or deleted phones.
myUser.Save();
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|