title: Create SQL Server table from user-defined class
body: <p>I am creating a mini-ORM to learn reflection better in C#.</p>
  
  <p>Also I want to use <strong>Native &amp; Pure C#</strong> and do not use Entity Framework or <a href="https://docs.microsoft.com/en-us/sql/relational-databases/server-management-objects-smo/sql-server-management-objects-smo-programming-guide" rel="nofollow noreferrer">SQL Server Management Objects</a>.</p>
  
  <pre><code>public static void CreateTable(Type tableType, string connectionString)
  {
       // codes to create table in database
  }
  </code></pre>
  
  <p>The problem is the <code>CreateTable</code> method, there are lots of problems in it, for example :</p>
  
  <ul>
  <li><p>I could not find any standard way to create a table from user-defined class.
  <a href="https://stackoverflow.com/questions/47239/how-can-i-generate-database-tables-from-c-sharp-classes">How can I generate database tables from C# classes?</a>: this solution is good but not ideal. Maybe it crashes in some situations.</p></li>
  <li><p>DataTypes!<br>
  There is no integration between C# and SQL Server datatypes. For example <code>varchar</code>, <code>nvarchar</code> and <code>text</code> all are (or map to) <code>string</code> !</p></li>
  </ul>
  
  <p>So when a user creates this class :</p>
  
  <pre><code>public class Person
  {        
     public int ID { get; set; }        
     public string Name { get; set; }
  }
  </code></pre>
  
  <p>which SQL Server datatype should I use for <code>Name</code>?</p>
  
  <p>Finally if generating a SQL query and executing it is best way for this question, what is your suggestion?</p>