c# - Bulk insert in RavenDB -
i want bulk insert in raverdb database of rows deserialized xml file.
the code wrote following
public ravendbimport(projectsrow dsrlizedobject) { idocumentstore docustore = connecttodb(); using (var session = docustore.opensession()) { var existingdoc = session.load<projectsrow>(dsrlizedobject.ic_name); if (existingdoc == null) { error projectsrow row = new projectsrow() { ic_name = dsrlizedobject.ic_name, serial_number = dsrlizedobject.serial_number, total_cost = dsrlizedobject.total_cost, administering_ic = dsrlizedobject.administering_ic, funding_mechanism = dsrlizedobject.funding_mechanism }; session.store(row); } else { console.writeline("*******************************************"); console.write("a document same ic_name alredy exists in database."); console.writeline("*******************************************"); } session.savechanges(); } } #region connecttodb // connecttodb - create connection db - testdb public static idocumentstore connecttodb() { var documentstore = new raven.client.document.documentstore { url = "http://hyperpc:8080/", defaultdatabase = "testdb" }; documentstore.initialize(); return documentstore; }
and called this...
foreach (projectsrow r in sbirsttrselectedrows) { // importtodb call new ravendbimport(r); }
the problem there maybe existing companies in database ic_name not same similar ones want import (eg. company1 llc. , company1 ltd.). @ moment checks same ic_names. can in order identify these companies , decide hand if wand import document or not?
thanks
btw class following
namespace xml2ravendbconverter { [system.codedom.compiler.generatedcodeattribute("xsd", "4.0.30319.17929")] [system.serializableattribute()] [system.diagnostics.debuggerstepthroughattribute()] [system.componentmodel.designercategoryattribute("code")] [system.xml.serialization.xmltypeattribute(anonymoustype = true)] [system.xml.serialization.xmlrootattribute(namespace = "", isnullable = false)] public partial class projects { private projectsrow[] itemsfield; /// <remarks/> [system.xml.serialization.xmlelementattribute("row", form = system.xml.schema.xmlschemaform.unqualified)] public projectsrow[] items { { return this.itemsfield; } set { this.itemsfield = value; } } } [serializable] public class projectsrow { [xmlelement("ic_name")] public string ic_name { get; set; } [xmlelement("serial_number")] public string serial_number { get; set; } [xmlelement("total_cost")] public string total_cost { get; set; } [xmlelement("administering_ic")] public string administering_ic { get; set; } [xmlelement("funding_mechanism")] public string funding_mechanism { get; set; } // // more follow // [xmlelement()] private rowpispi[][] pisfield; [xmlelement("project_termsx")] private rowproject_termsxterm[][] project_termsxfield; } [serializable] public class rowpispi { [xmlelement("pi_name")] public string pi_name {get; set; } [xmlelement("pi_id")] public string pi_id {get; set; } } [serializable] public class rowproject_termsxterm { [xmlelement("term")] public string valuefield { get; set; } } }
you should not upserting 1 record @ time. ravendb has bulk insert feature make things easier , faster. see http://ravendb.net/docs/2.0/client-api/advanced/bulk-inserts
Comments
Post a Comment