title: How can I generate database tables from C# classes?
body: <p>Does anyone know a way to auto-generate database tables for a given class?  I'm not looking for an entire persistence layer - I already have a data access solution I'm using, but I suddenly have to store a lot of information from a large number of classes and I really don't want to have to create all these tables by hand.  For example, given the following class:</p>
  
  <pre><code>class Foo
  {
      private string property1;
      public string Property1
      {
          get { return property1; }
          set { property1 = value; }
      }
  
      private int property2;
      public int Property2
      {
          get { return property2; }
          set { property2 = value; }
      }
  }
  </code></pre>
  
  <p>I'd expect the following SQL:</p>
  
  <pre><code>CREATE TABLE Foo
  (
      Property1 VARCHAR(500),
      Property2 INT
  )
  </code></pre>
  
  <p>I'm also wondering how you could handle complex types.  For example, in the previously cited class, if we changed that to be :</p>
  
  <pre><code>class Foo
  {
      private string property1;
      public string Property1
      {
          get { return property1; }
          set { property1 = value; }
      }
  
      private System.Management.ManagementObject property2;
      public System.Management.ManagementObject Property2
      {
          get { return property2; }
          set { property2 = value; }
      }
  }
  </code></pre>
  
  <p></p>
  
  <p>How could I handle this?</p>
  
  <p>I've looked at trying to auto-generate the database scripts by myself using reflection to enumerate through each class' properties, but it's clunky and the complex data types have me stumped.</p>