private static void Subclass() { using (var session = NHibernateHelper.OpenSession()) { using (var transaction = session.BeginTransaction()) { var parentA = new ParentA() { Name = "Chris" }; var childA = new ChildA() { Name = "Mary", AnotherProperty = "Likes dogs" }; var parentB = new ParentB() { Name = "Chris" }; var childB = new ChildB() { Name = "Mary", AnotherProperty = "Likes dogs" }; var parentC = new ParentC() { Name = "Chris" }; var childC = new ChildC() { Name = "Mary", AnotherProperty = "Likes dogs" }; session.Save(parentA); session.Save(parentB); session.Save(parentC); session.Save(childA); session.Save(childB); session.Save(childC); transaction.Commit(); Console.WriteLine("Done!"); } } }
public void SerializeParentWithUnmarkedChildShouldWork() { var obj = new ParentA(); Serializer.Serialize(Stream.Null, obj); }
public void WriteXml(Stream outputStream) { if (null == outputStream) { throw new ArgumentNullException(nameof(outputStream)); } XmlWriterSettings settings = new XmlWriterSettings { Indent = true }; using (XmlWriter writer = XmlWriter.Create(outputStream, settings)) { writer.WriteStartElement("Profile"); writer.WriteStartElement("Id"); writer.WriteValue(Id.ToString()); writer.WriteEndElement(); if (!string.IsNullOrWhiteSpace(_name)) { writer.WriteStartElement("Name"); writer.WriteValue(_name.Trim()); writer.WriteEndElement(); } writer.WriteStartElement("Generation"); writer.WriteValue(Generation); writer.WriteEndElement(); if (ParentA.HasValue) { writer.WriteStartElement("ParentA"); writer.WriteValue(ParentA.ToString()); writer.WriteEndElement(); } if (ParentB.HasValue) { writer.WriteStartElement("ParentB"); writer.WriteValue(ParentB.ToString()); writer.WriteEndElement(); } writer.WriteStartElement("Records"); for (int i = 0; i < Records.Length; i++) { writer.WriteStartElement("Record"); writer.WriteAttributeString("GameType", EnumUtils.GetExpansionPiecesString((ExpansionPieces)i)); writer.WriteAttributeString("EloRating", Records[i].EloRating.ToString()); writer.WriteAttributeString("Wins", Records[i].Wins.ToString()); writer.WriteAttributeString("Losses", Records[i].Losses.ToString()); writer.WriteAttributeString("Draws", Records[i].Draws.ToString()); writer.WriteAttributeString("AutoTrains", Records[i].AutoTrains.ToString()); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteStartElement("Creation"); writer.WriteValue(CreationTimestamp); writer.WriteEndElement(); writer.WriteStartElement("LastUpdated"); writer.WriteValue(LastUpdatedTimestamp); writer.WriteEndElement(); StartMetricWeights.WriteMetricWeightsXml(writer, "StartMetricWeights"); EndMetricWeights.WriteMetricWeightsXml(writer, "EndMetricWeights"); writer.WriteEndElement(); // </Profile> } }
private void _read() { _childSize = m_io.ReadU1(); _elementA = new ParentA(m_io, this, m_root); _elementB = new ParentB(m_io, this, m_root); }
public void WriteXml(Stream outputStream) { if (null == outputStream) { throw new ArgumentNullException("outputStream"); } XmlWriterSettings settings = new XmlWriterSettings { Indent = true }; using (XmlWriter writer = XmlWriter.Create(outputStream, settings)) { writer.WriteStartElement("Profile"); writer.WriteStartElement("Id"); writer.WriteValue(Id.ToString()); writer.WriteEndElement(); if (!string.IsNullOrWhiteSpace(_name)) { writer.WriteStartElement("Name"); writer.WriteValue(_name.Trim()); writer.WriteEndElement(); } writer.WriteStartElement("Generation"); writer.WriteValue(Generation); writer.WriteEndElement(); if (ParentA.HasValue) { writer.WriteStartElement("ParentA"); writer.WriteValue(ParentA.ToString()); writer.WriteEndElement(); } if (ParentB.HasValue) { writer.WriteStartElement("ParentB"); writer.WriteValue(ParentB.ToString()); writer.WriteEndElement(); } writer.WriteStartElement("EloRating"); writer.WriteValue(EloRating); writer.WriteEndElement(); writer.WriteStartElement("Wins"); writer.WriteValue(Wins); writer.WriteEndElement(); writer.WriteStartElement("Losses"); writer.WriteValue(Losses); writer.WriteEndElement(); writer.WriteStartElement("Draws"); writer.WriteValue(Draws); writer.WriteEndElement(); writer.WriteStartElement("Creation"); writer.WriteValue(CreationTimestamp); writer.WriteEndElement(); writer.WriteStartElement("LastUpdated"); writer.WriteValue(LastUpdatedTimestamp); writer.WriteEndElement(); writer.WriteStartElement("StartMetricWeights"); MetricWeights.IterateOverWeights((bugType, bugTypeWeight) => { string key = MetricWeights.GetKeyName(bugType, bugTypeWeight); double value = StartMetricWeights.Get(bugType, bugTypeWeight); writer.WriteStartElement(key); writer.WriteValue(value); writer.WriteEndElement(); }); writer.WriteEndElement(); // </StartMetricWeights> writer.WriteStartElement("EndMetricWeights"); MetricWeights.IterateOverWeights((bugType, bugTypeWeight) => { string key = MetricWeights.GetKeyName(bugType, bugTypeWeight); double value = EndMetricWeights.Get(bugType, bugTypeWeight); writer.WriteStartElement(key); writer.WriteValue(value); writer.WriteEndElement(); }); writer.WriteEndElement(); // </EndMetricWeights> writer.WriteEndElement(); // </Profile> } }