I'm querying data with parent/child result sets using Entity Framework and I want to export this data to an XML document.
var agreement = storeops.Agreements.SingleOrDefault(a => a.AgreementNumber == AgreementTextBox.Text);
XmlSerializer serializer = new XmlSerializer(agreement.GetType());
XmlWriter writer = XmlWriter.Create("Agreement.xml");
serializer.Serialize(writer, agreement);
This works well except it only serializes the parent without including the related child records in the XML. How can I get the children to serialize as well?
I also tried using POCO generated code and the child collections attempt to be serialized except they are ICollections which can't be serialized.
Cannot serialize member DataSnapshots.Agreement.AgreementItems of type System.Collections.Generic.ICollection`1[[DataSnapshots.AgreementItem, DataSnapshots, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] because it is an interface.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…