我想在RaverDB数据库中对从XML文件反序列化的某些行进行批量插入。
我写的代码如下
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; }
}
}
答案 0 :(得分:1)
您可能不应该一次发送一条记录。 RavenDB具有批量插入功能,可以使事情变得更加容易和快捷。见http://ravendb.net/docs/2.0/client-api/advanced/bulk-inserts