title: PetaPoco (DotNetNuke) and SQL - Adding an object with a List property or other composite object
body: <p>I'm using a Data Access Layer based on PetaPoco (DotNetNuke 7.0). I've used it successfully when working with relatively simple objects but I now have to insert an object which contains at least one property which is a List of other objects.</p>
  
  <p>For example:</p>
  
  <pre><code>class Person
  {
     public Person(){}
     public string name { get; set; }
     public List&lt;Address&gt; addresses { get; set; }
  }
  class Address
  {
     ...
  }
  </code></pre>
  
  <p>The actual object I'm working with is much more complex than the example above - there are at least four composite List objects in the object to be inserted into the repository. </p>
  
  <p>What I'd like to be able to do is define the table in SQL and to be able to make a simple call to PetaPoco like this:</p>
  
  <pre><code>public static void AddOrder(Person person)
  {
      using (IDataContext context = DataContext.Instance())
      {
          var repository = context.GetRepository&lt;Person&gt;();
          repository.Insert(person);
      }
  }
  </code></pre>
  
  <p>The background to this is that the object is passed in to a web service from a Knockout/jQuery front-end so a JSON string is converted to a data object which must then be stored on the database.</p>
  
  <p>I think there are three questions really:</p>
  
  <ol>
  <li><p>How do I write the SQL table which represents Person and the contained Addresses List?</p></li>
  <li><p>How do I write the necessary PetaPoco code to insert the Person object together with any objects it contains?</p></li>
  <li><p>Should I forget about trying to store the object on the database and just store the JSON string on the database instead?</p></li>
  </ol>
  
  <p>Thanks for looking :)</p>