title: Entity Framework - how to get database column datatype from metadata
body: <p>Is there a way to get the database column DataType length information given a table's EntityType?</p>
  
  <p>Example SQL (SQL Server) that you can run to see precisely what information I am looking for:</p>
  
  <pre><code>select 
      sys.tables.name as 'Table Name', 
      sys.columns.name as 'Column Name', 
      sys.systypes.name as 'DataType', 
      sys.columns.max_length as 'Max Length', 
      sys.columns.precision as 'Precision'
  from 
      sys.columns, sys.systypes, sys.tables
  where 
      sys.columns.system_type_id = sys.systypes.xtype 
      and sys.systypes.name &lt;&gt; 'sysname' 
      and sys.tables.type = 'U' 
      and sys.tables.name &lt;&gt; 'sysdiagrams'
      and sys.columns.object_id=sys.tables.object_id
  order by 
      sys.tables.name, sys.columns.column_id;
  </code></pre>
  
  <p>The last 3 columns contain the data that I would like to have access to because I'm generating some documentation. One example reason for the documentation is: Entity Framework will throw an Exception by default if a string is set on a property that can't support it's length. A developer without access to the database metadata has a challenge with the discoverability of length requirements in this case.</p>
  
  <p>Thanks,
  Aaron</p>