Note that there are some explanatory texts on larger screens.

plurals
  1. PODatareader from LINQ Query for SqlBulkCopy
    primarykey
    data
    text
    <p>I'm using this library:</p> <p><a href="http://archive.msdn.microsoft.com/LinqEntityDataReader" rel="nofollow">Link to EntityDataReader</a></p> <p>to put some linq query results from a xml parse to a database with a sqlbulkcopy which us es a datareader to put the data directly without using datatables or such data structures.</p> <p>I am not able to implement it.</p> <p>This is the code I wrote so far without any success:</p> <pre><code>XDocument xdoc = XDocument.Parse(str_XmlToParse); //ORDINI IEnumerable&lt;XDocument&gt; xdod; var orders = from c in xdoc.Descendants("ordersdata").AsEnumerable().Descendants("order").AsEnumerable() select new { Client_ID = (string)c.Element("Client").Element("ID"), Doc_ID = (string)c.Element("ord_ID"), Doc_data = (DateTime)c.Element("ord_datetime"), }; IDataReader dr = orders.AsDataReader(); using (SqlConnection con = new SqlConnection(connectionString)) { con.Open(); using (SqlTransaction tran = con.BeginTransaction()) { var newOrders = from i in Enumerable.Range(0, totalToSend) select new Order { customer_name = "Customer " + i % 100, quantity = i % 9, order_id = i, order_entry_date = DateTime.Now }; SqlBulkCopy bc = new SqlBulkCopy(con, SqlBulkCopyOptions.CheckConstraints | SqlBulkCopyOptions.FireTriggers | SqlBulkCopyOptions.KeepNulls, tran); bc.BatchSize = 1000; bc.DestinationTableName = "order_queue"; bc.WriteToServer(newOrders.AsDataReader()); tran.Commit(); } con.Close(); </code></pre> <p>which is mostly a copy of what is in the examples of that library.</p> <p>I am not even understanding correctly what's going on with all their weird castings, but I need it to work. (believe me I tried to understand)</p> <p>I keep getting this error:</p> <blockquote> <p>Error 1 'System.Collections.Generic.IEnumerable AnonymousType#1>' does not contain a definition for 'AsDataReader' and no extension method 'AsDataReader' accepting a first argument of type 'System.Collections.Generic.IEnumerable AnonymousType#1>' could be found (are you missing a using directive or an assembly reference?)</p> </blockquote> <p>What is it? How do I fix it?</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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