我试图序列化一个对象,但我不能,因为它有外键指向它。我有一个名为" SERVICO"和一个名为" SERVICO_PROCESSAMENTO"的表/模型;使用外键来" SERVICO"。如果我的对象没有指向它的外键,我可以正常序列化它。当我有一个" SERVICO"对象但它有外键指向,该对象不再具有类型" SERVICO",它具有类型" SERVICO_(多个字符)"。如果我在序列化之前删除了他的孩子,那么它可以工作,但我不想删除它们。有没有人知道如何在不删除孩子的情况下序列化?
我的代码如下:
public XRetornConv GravaDadosBanco<T>(object currentObject, object previousObject, string _table, string _owner, string _operation, string _procedureCustom)
{
XmlConverter xmlConv = new XmlConverter();
string currentXml = "";
if (previousObject != null)
{
previousXml = xmlConv.SerializeClass<T>(previousObject, _table, _owner, _operation, _procedureCustom);
}
var currentXml = xmlConv.SerializeClass<T>(currentObject, _table, _owner, _operation, _procedureCustom);
return new XRetornConv(globaisRep.GravarDadosXML(currentXml, previousXml));
}
public string SerializeClass<T>(object objeto, string _table, string _owner, string _operation, string _procedureCustom)
{
XmlSerializer<T> xSerializer = new XmlSerializer<T>();
var serializ = xSerializer.Serialize((T)objeto); //Can't serialize here!
return ConvertXMLOracle(serializ, _table, _owner, _operation, _procedureCustom);
}
谢谢。