Bulk insert to SQL Server with linq -


i read xml file linq , create list of objects.

 stringreader stream=new stringreader(xml);  xmltextreader reader=new xmltextreader(stream);  xelement req = xelement.load(reader); var users= (req.descendants("report")            .select(e => new {              fname= e.descendants("firstname").firstordefault().value,             lname = e.descendants("lastname").firstordefault().value,             personalid = e.descendants("id").firstordefault().value,             })).tolist(); 

the users value include 100,000 objects.

i want bulk insert these objects database table.

public static void savedata<t>(ref list<t> list, string destinationtablename, int batchsize) {     using (entitydatareader<t> reader = new entitydatareader<t>(list))     using (system.data.sqlclient.sqlbulkcopy sbc = new system.data.sqlclient.sqlbulkcopy("your connection string"))     {         (int = 0; < reader.fieldcount; i++)         {             string colname = reader.getname(i);             sbc.columnmappings.add(colname, colname);         }         sbc.batchsize = batchsize;         sbc.destinationtablename = destinationtablename;         sbc.writetoserver(reader);     } } 

i'm using code insert large list of items, t should known entity object


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -