我想在 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 的公司,该 IC_NAME 与我要导入的公司(例如 Company1 LLC. 和 Company1 LTD.)不完全相同但相似。目前它检查完全相同的 IC_NAME。我可以做些什么来识别这些公司,然后手动决定是否要导入文件?
谢谢
顺便说一句,课程如下
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; }
}
}