title: Tool or a way to create a DataSet.XSD from a Mapping C# .cs file or a NHibernate.hbm.xml file?
body: <p>I need to create a DataSet.xsd file according to a NHibernate.hbm.xml file or a Class File. These are Mapping files and class files than we use to work with our DB.</p>
  
  <p>You may ask me, why I do need a DataSet file, generating from a Nhibernate.hbm.xml file or a .cs file? </p>
  
  <p>It's because we're using Crystal Reports, and we're using <strong>Frameworks, MVVM, INotifyPropertyChanged, NHibernate</strong> and after <strong>a lot of studying</strong>, for our case, would be better if we Convert an object while in executing time of program and use it to generate a report. If this tool exists, it will make easier, 'cause we have over 60, 70 columns per table in our DB. Since we're already with all these components working into our Project, it wouldn't make sense if we start to use sql queries to generate reports.</p>
  
  <p>This tool, or 'the way to' create this DataSet file, need to read those file in these formats:</p>
  
  <p><strong>Nhibernate.hbm.xml file:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;  
  &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="PCT.Domain" namespace="Gerdau.PCT.Kernel.Domain"&gt;
  &lt;class name="Furnace" table="Furnace" lazy="false"&gt;    
  &lt;id name="Id" column="Id_Furnace" type="Int64"&gt;
    &lt;generator class="Geraes.GLib.GDomainBasis.CustomTableHiLoGenerator, GLib.GDomainBasis" /&gt;
  &lt;/id&gt;
  &lt;property name="Name" column="Name" type="String" length="50" not-null="true"/&gt;
  &lt;property name="Code" column="Code" type="Char" not-null="true"/&gt;
  &lt;property name="Mill" column="Mill" type="String" length="2" not-null="true"/&gt;
  &lt;property name="DischEnabled" column="Disch_Enabled" type="Char" not-null="true"/&gt;
  &lt;property name="DischEnabledTemp" column="Disch_Enabled_Temp" type="Char" not-null="true"/&gt;
  &lt;property name="ChargeEnabled" column="Charge_Enabled" type="Char" not-null="true"/&gt;
  &lt;property name="ChargeEnabledTemp" column="Charge_Enabled_Temp" type="Char" not-null="true"/&gt;    
  &lt;/class&gt;  
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p><strong>CSharp .cs File:</strong></p>
  
  <pre><code>public class Furnace : BaseEntity
  {
      public virtual String Name { get; set; }
  
      public virtual Char Code { get; set; }
  
      public virtual String Mill { get; set; }
  
      public virtual Char DischEnabled { get; set; }
  
      public virtual Boolean DischEnabledConv
      {
          get
          {
              return DischEnabled.ConvertYesNoToBoolean();
          }
          set
          {
              DischEnabled = ((Boolean)value).ConvertYesNoToBoolean();
          }
      }
  
      public virtual Boolean DischEnabledTempConv
      {
          get
          {
              return DischEnabledTemp.ConvertYesNoToBoolean();
          }
          set
          {
              DischEnabledTemp = ((Boolean)value).ConvertYesNoToBoolean();
          }
      }
  
      public virtual Char DischEnabledTemp { get; set; }
  
      public virtual Char ChargeEnabled { get; set; }
  
      public virtual Boolean ChargeEnabledConv
      {
          get
          {
              return ChargeEnabled.ConvertYesNoToBoolean();
          }
          set
          {
              ChargeEnabled = ((Boolean)value).ConvertYesNoToBoolean();
          }
      }
  
      public virtual Boolean ChargeEnabledTempConv
      {
          get
          {
              return ChargeEnabledTemp.ConvertYesNoToBoolean();
          }
          set
          {
              ChargeEnabledTemp = ((Boolean)value).ConvertYesNoToBoolean();
          }
      }
      public virtual Char ChargeEnabledTemp { get; set; }
  
      public virtual ConfiguracaoForno MillConv
      {
          get
          {
              if (Mill == ConfiguracaoForno.SM.ToString())
                  return ConfiguracaoForno.SM;
              if (Mill == ConfiguracaoForno.PM.ToString())
                  return ConfiguracaoForno.PM;
              else
                  return ConfiguracaoForno.NN;
          }
      }
  
      public override String ToString()
      {
          return "Forno " + Code + " (" + Name + "): Laminador " + MillConv;
      }
  }
  </code></pre>
  
  <p>I know it's an very specific case, but if you can show to us at least a way, it'll be of great help.</p>
  
  <p>Best regards,</p>
  
  <p>Gustavo</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Found a way to do it: using XSD.EXE, a internal Tool from Visual Studio, i've extracted the mapping from my assembly:</p>
  
  <pre><code>C:\&gt;xsd / c /l:CS -t:Furnace &lt;MyAssembly&gt;.dll -o:"D:\Temp"
  </code></pre>
  
  <p>But now, when I do this:</p>
  
  <pre><code>D:\&gt;xsd /c schema0.xsd
  </code></pre>
  
  <p>Results in these errors:</p>
  
  <blockquote>
    <p>D:\Temp>xsd /c schema0.xsd
    Microsoft (R) Xml Schemas/DataTypes support utility
    [Microsoft (R) .NET Framework, Version 4.0.30319.1]
    Copyright (C) Microsoft Corporation. All rights reserved.</p>
    
    <blockquote>
      <p>Schema validation warning: Type 'char' is not declared, or is not a simple type.
       Line 21, position 5.
      Schema validation warning: Type 'http://microsoft.com/wsdl/types/:char' is not declared. Line 10, position 7.
      Schema validation warning: Type 'http://microsoft.com/wsdl/types/:char' is not declared. Line 12, position 7.
      Schema validation warning: Type 'http://microsoft.com/wsdl/types/:char' is not declared. Line 15, position 7.
      Schema validation warning: Type 'http://microsoft.com/wsdl/types/:char' is not declared. Line 16, position 7.
      Schema validation warning: Type 'http://microsoft.com/wsdl/types/:char' is not declared. Line 19, position 7.
      Warning: Schema could not be validated. Class generation may fail or may produce incorrect results.</p>
    </blockquote>
    
    <p>Error: Error generating classes for schema 'schema0'.
      - The datatype 'char' is missing.</p>
    
    <p>If you would like more help, please type "xsd /?".</p>
  </blockquote>
  
  <p>Here's my generated schema.xsd:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
  &lt;xs:import namespace="http://microsoft.com/wsdl/types/" /&gt;
  &lt;xs:element name="Furnace" nillable="true" type="Furnace" /&gt;
  &lt;xs:complexType name="Furnace"&gt;
      &lt;xs:complexContent mixed="false"&gt;
        &lt;xs:extension base="BaseEntity"&gt;
          &lt;xs:sequence&gt;
            &lt;xs:element minOccurs="0" maxOccurs="1" name="Name" type="xs:string" /&gt;
            &lt;xs:element minOccurs="1" maxOccurs="1" name="Code" xmlns:q1="http://microsoft.com/wsdl/types/" type="q1:char" /&gt;
            &lt;xs:element minOccurs="0" maxOccurs="1" name="Mill" type="xs:string" /&gt;
            &lt;xs:element minOccurs="1" maxOccurs="1" name="DischEnabled" xmlns:q2="http://microsoft.com/wsdl/types/" type="q2:char" /&gt;
            &lt;xs:element minOccurs="1" maxOccurs="1" name="DischEnabledConv" type="xs:boolean" /&gt;
            &lt;xs:element minOccurs="1" maxOccurs="1" name="DischEnabledTempConv" type="xs:boolean" /&gt;
            &lt;xs:element minOccurs="1" maxOccurs="1" name="DischEnabledTemp" xmlns:q3="http://microsoft.com/wsdl/types/" type="q3:char" /&gt;
            &lt;xs:element minOccurs="1" maxOccurs="1" name="ChargeEnabled" xmlns:q4="http://microsoft.com/wsdl/types/" type="q4:char" /&gt;
            &lt;xs:element minOccurs="1" maxOccurs="1" name="ChargeEnabledConv" type="xs:boolean" /&gt;
            &lt;xs:element minOccurs="1" maxOccurs="1" name="ChargeEnabledTempConv" type="xs:boolean" /&gt;
            &lt;xs:element minOccurs="1" maxOccurs="1" name="ChargeEnabledTemp" xmlns:q5="http://microsoft.com/wsdl/types/" type="q5:char" /&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:extension&gt;
      &lt;/xs:complexContent&gt;
  &lt;/xs:complexType&gt;
  &lt;xs:complexType name="BaseEntity"&gt;
      &lt;xs:sequence&gt;
        &lt;xs:element minOccurs="1" maxOccurs="1" name="Id" type="xs:long" /&gt;
      &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>I appreciate for any help.</p>
  
  <p>Gustavo</p>