Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I generally don't like using a <a href="http://msdn.microsoft.com/en-us/library/system.data.dataset.aspx" rel="nofollow"><code>DataSet</code></a> to import XML data into my database; the <code>DataSet</code> class has a very specific way of structuring its data as XML and conversely, reading other XML.</p> <p>That said, I prefer call the <a href="http://msdn.microsoft.com/en-us/library/434atets.aspx" rel="nofollow"><code>WriteToServer</code> overload</a> that takes an <a href="http://msdn.microsoft.com/en-us/library/system.data.idatareader.aspx" rel="nofollow"><code>IDataReader</code></a> implementation.</p> <p>You can easily create an extension method that takes an <a href="http://msdn.microsoft.com/en-us/library/9eekhta0.aspx" rel="nofollow"><code>IEnumerable&lt;T&gt;</code></a> implementation and maps it to an <code>IDataReader</code>; basically, you map the properties of the class to the fields on the table by name and index where the index is also an index into an array of <a href="http://msdn.microsoft.com/en-us/library/system.linq.expressions.expression.aspx" rel="nofollow"><code>Expression</code></a> instances (compiled to lambdas) that you create for <code>T</code> which takes the instance of <code>T</code> and returns the property value.</p> <p>You'd generally map the <a href="http://msdn.microsoft.com/en-us/library/system.data.idatareader.read.aspx" rel="nofollow"><code>IDataReader.Read</code></a> implementation to <a href="http://msdn.microsoft.com/en-us/library/system.collections.ienumerator.movenext.aspx" rel="nofollow"><code>IEnumerable&lt;T&gt;.MoveNext</code></a> method.</p> <p>Once you have something like this in place, you can map your XML to a lightwieght data object which mirrors the table and then pass the sequence of them into an extension method which maps the sequence to an <code>IDataReader</code> implementation.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload