title: Linq and SubSonic - returning nested complex types
body: <p>I'm new to SubSonic and reasonably new to LINQ as well, so I'm just trying to put a little app together.</p>
  
  <p>I've got the templates all sorted and running okay, but I've run into a bit of trouble with this LINQ statement (simplified slightly, the real statement has some other joins but they don't affect this particular problem so I've removed them for brevity):</p>
  
  <pre><code>var addresses = from address in Database.Addresses.All()
                             select new Address()
                                 {
                                     MyNestedType = new NestedType()
                                         {
                                             Field1 = address.ADDR1
                                         }
                                 };
  </code></pre>
  
  <p>If I execute this statement I get the error <em>Invalid cast from 'System.String' to 'NestedType'.</em> when I try to enumerate the results.</p>
  
  <p>I'm probably overlooking the obvious but I can't see anywhere that I request such a conversion.</p>
  
  <p>Both <em>Field1</em> and <em>address.ADDR1</em>  are strings.</p>
  
  <p>Any ideas what I'm doing wrong?</p>
  
  <p><strong>Edit</strong>:</p>
  
  <p>I've had another look at this and in an effort to provide more information, I've created a small, complete example using SimpleRepository and an SQLite database that demonstrates the issue. Using SimpleRepository the error I get is different (Sequence contains no elements) but the result is the same. Here's the complete code:</p>
  
  <pre><code> public class DatabaseAddress
   {
       public int Id { get; set; }
       public string Address1 { get; set; }
   }
  
   public class Address
   {
       public NestedType MyNestedType;
   }
  
   public class NestedType
   {
       public string Field1 { get; set; }
   }
  
   static class Program
   {
      [STAThread]
      static void Main()
      {
           var repo = new SimpleRepository("Db", SimpleRepositoryOptions.RunMigrations);
           DatabaseAddress address1 = new DatabaseAddress();
           address1.Address1 = "Test";
           repo.Add(address1);
           var all = repo.All&lt;DatabaseAddress&gt;();
           var addresses = from address in repo.All&lt;DatabaseAddress&gt;()
                           select new Address { MyNestedType = new NestedType { Field1 = address.Address1 } };
      }
   }
  </code></pre>
  
  <p>In this example, <code>all</code> contains the object added to the database, but <code>addresses</code> returns "Sequence contains no elements". </p>
  
  <p>If I use anonymous types instead of concrete types in the <code>select</code> statement it works.</p>
  
  <p>There's obviously a gap in my knowledge here; any help appreciated.</p>