title: MySqlDataReader: DataTable.Fill(reader) throws ConstraintException
body: <p>I have two tables <code>orders</code> and <code>orderdetails</code></p>
  
  <p>table orders (PK = id, UNIQUE index on orderno)</p>
  
  <pre><code>|id|orderno|
  | 1|1000   |
  | 2|1001   |
  </code></pre>
  
  <p>table orderdetails (PK = id)</p>
  
  <pre><code>|id|orderid|item|qty|
  | 1|      1|ABC |  3|
  | 2|      1|XYZ |  4|
  </code></pre>
  
  <p>Now I want to query the data with:</p>
  
  <pre><code>SELECT o.orderno, od.item, od.qty
    FROM orders o
  </code></pre>
  
  <p>INNER JOIN orderdetails od ON o.orderno = od.order</p>
  
  <p>which returns:</p>
  
  <pre><code>|orderno|item|qty|
  |1000   |ABC |  3|
  |1000   |XYZ |  4|
  </code></pre>
  
  <p>However If I use the following code to load the result into a DataTable it fails:</p>
  
  <pre><code>var connectionString = "Server=localhost;Database=orders;Uid=root;";
  var commandText = "SELECT o.orderno, od.item, od.qty" + Environment.NewLine +
                    "FROM orders o" + Environment.NewLine +
                    "INNER JOIN orderdetails od ON o.orderno = od.order";
  
  var reader = MySqlHelper.ExecuteReader(connectionString, commandText);
  var table = new DataTable("OrdersQuery");
  table.Fill(reader); // throws ConstraintException
  </code></pre>
  
  <p>The problem is, that</p>
  
  <pre><code>table.Constraints[0]
  </code></pre>
  
  <p>is a <code>UniqueConstraints</code> on the orderno column. Propably because</p>
  
  <pre><code>reader.GetSchemaTable() 
  </code></pre>
  
  <p>has a <code>IsUnique=true</code> entry for orderno (which is true in the base table, but not true for the join query).</p>
  
  <p>Even worse, that doesn't help either:</p>
  
  <pre><code>table.BeginLoadData(); // msdn docs claim that this should disable constraints
  table.Load(reader);
  table.EndLoadData();
  </code></pre>
  
  <p>Any ideas how to fix this?</p>
  
  <p>StackTrace:</p>
  
  <pre><code>System.Data.ConstraintException Was Unhandled.
    Message=Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
    Source=System.Data
    StackTrace:
         bei System.Data.DataTable.EnableConstraints()
         bei System.Data.DataTable.set_EnforceConstraints(Boolean value)
         bei System.Data.DataTable.EndLoadData()
         bei System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
         bei System.Data.Common.DataAdapter.Fill(DataTable[] dataTables, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
         bei System.Data.Common.LoadAdapter.FillFromReader(DataTable[] dataTables, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
         bei System.Data.DataTable.Load(IDataReader reader, LoadOption loadOption, FillErrorEventHandler errorHandler)
         bei System.Data.DataTable.Load(IDataReader reader)
  </code></pre>