Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Exposing Children From Persistent Storage

Exposing Children From Persistent Storage

Scheduled Pinned Locked Moved C#
question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Christian M Jensen
    wrote on last edited by
    #1

    Hello all... If you had a parent object and wanted to expose its children from persistent storage, would you do it by exposing the children as if the parent was a List or just a few methods for getting the count and a range of child objects... or is there another method I might not be aware of. The children must be editable and retain their data in persistent storage. There could be thousands of children as well. Secondly, if you were to have a function that did something like "Take money from parent and give to child" would you put this function on the parent, child or as a static function?

    P 1 Reply Last reply
    0
    • C Christian M Jensen

      Hello all... If you had a parent object and wanted to expose its children from persistent storage, would you do it by exposing the children as if the parent was a List or just a few methods for getting the count and a range of child objects... or is there another method I might not be aware of. The children must be editable and retain their data in persistent storage. There could be thousands of children as well. Secondly, if you were to have a function that did something like "Take money from parent and give to child" would you put this function on the parent, child or as a static function?

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      If you are using .NET 2, then I would look at generic collections to store your items:

      public class Parent
      {
        List<Child> _children = new List<Child>();
      
        public int Add(Child value)
        {
          _children.Add(value);
        }
      
        public void LoadAll()
        {
          // Read the data from the database into something like a datareader
          // And populate the child before adding it into the collection...
        }
      
        public void Save()
        {
          foreach (Child child in _children)
          {
            child.Save();
          }
        }
      }
      
      public class Child
      {
        // Add the properties...
      
        // Some methods...
        public void Save()
        {
          // Save to database..
        }
      
        // Fill the child record.
        public static Child Fill(IDataRecord row)
        {
          Child child = new Child();
          child.Id = Convert.ToInt32(row["Id"].ToString());
          // Id is a property of Child.
          return child;
        }
      }
      

      This is just a sample of the type of approach you might take. It isn't intended to be directly coded from. -- modified at 4:37 Tuesday 5th December, 2006

      Arthur Dent - "That would explain it. All my life I've had this strange feeling that there's something big and sinister going on in the world." Slartibartfast - "No. That's perfectly normal paranoia. Everybody in the universe gets that." Deja View - the feeling that you've seen this post before.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups