2013-07-18 160 views
1

我想在RaverDB數據庫中對從XML文件反序列化的某些行進行批量插入。在RavenDB中批量插入

我寫的代碼如下

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 with the same IC_NAME alredy exists in the database."); 
      Console.WriteLine("*******************************************"); 
     } 
     session.SaveChanges(); 
    } 
} 


#region ConnectToDB 
// ConnectToDB - Create Connection with the DB - TestDB 
public static IDocumentStore ConnectToDB() 
    { 
     var documentStore = new Raven.Client.Document.DocumentStore { Url = "http://hyperpc:8080/", DefaultDatabase = "TestDB" }; 
     documentStore.Initialize(); 
     return documentStore; 
    } 

,它被稱爲像這樣...

foreach (PROJECTSRow r in SBIRSTTRSelectedRows) 
    { 
     // ImportToDB Call 
     new RavenDBImport(r); 
    } 

的問題是,有可能已經存在的企業與IC_NAME的數據庫,不完全一樣,但與我想要導入的相似(例如Company1 LLC。和Company1 LTD。)。目前它檢查完全相同的IC_NAME。 我可以做些什麼來識別這些公司,然後手動決定我是否可以導入文檔?

感謝

BTW類是在同一時間下

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 
     { 
      get 
      { 
       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 to 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; } 
     } 

} 

回答