title: Inserting a new record pattern in SubSonic 3
body: <p>I'm trying out the new SubSonic 3 preview, but I'm not sure about the patterns I should be using for the basic CRUD operations in my MVC project.</p>
  
  <p>I'm trying to keep as much of my data logic in my models, so I added some static CRUD methods to each model's partial class.</p>
  
  <p>For example, let's say I have a configuration table, which should only have a single record.  So, my partial class may look something like this:</p>
  
  <pre><code>public partial class Configuration{
          // cut down; mocking hooks here IRL
          private static IRepository&lt;Configuration&gt; Table = new MyRepository&lt;Configuration&gt;();
  
          public static Configuration Retrieve()
          {
              var config = Table.GetAll().FirstOrDefault();
              if (config == null)
              {
                  config = new Configuration();
                  Table.Add(config);
              }
              return config;
          }
  
          public static void Update(Configuration target)
          {
              Table.Update(target);
          }
  }
  </code></pre>
  
  <p>Currently, this doesn't work as the config table has an identity column for a primary key, and Add-ing a new record to the table throws the standard "Cannot insert explicit value for identity column" error.  SubSonic 3 doesn't seem to generate classes that, upon new-ing them up, play nice with the rules of the database schema (i.e., no default values, no nullable primitives for values that are nullable in the database, etc).</p>
  
  <p>Now, I can alter my table and pattern to get around these issues, but I'm wondering about when I <em>cannot</em> get around this issue--when I have to add a new record to the database and have an identity as my primary key.</p>
  
  <p>I'm also wondering if this pattern is even correct or not.  SubSonic gives you a number of different ways you can go about your repository business, so I'm not sure which one I should be using.  I'd LIKE to use my models as MUCH as possible (otherwise why not just Linq to Sql?), so I don't want to use SubSonic's query building goodness when trying to CRUD my models.</p>
  
  <p>What should I do here?  Any advice on CRUD patterns for using SubSonic 3 in my MVC project would be welcome and +'d.  Also welcome are links to websites that cover this subject for SubSonic 3 but that don't rank high in Google searches...</p>
  
  <hr>
  
  <p>Asked Rob directly (<a href="http://groups.google.com/group/subsonicproject/browse_thread/thread/d65036df31a37368" rel="nofollow noreferrer">link here</a>).  For my DB, at least, there's a showstopper bug in the generated code.  Aaah, alpha software.  </p>
  
  <hr>
  
  <p><strong>UPDATE</strong></p>
  
  <p>With <a href="http://blog.wekeroad.com/" rel="nofollow noreferrer">the release of Subsonic3</a>, can we have a little bump to reconsider this question?</p>