Maybe this can help : http://stackoverflow.com/questions/1958684/nhibernate-how-do-i-xmlserialize-an-isett
Cheers, Mauricio On Mon, Mar 19, 2012 at 8:32 PM, Michael <[email protected]> wrote: > Active record requires collections to be IList<T>, which I can't seem > to deserialize. Does anyone have any suggestions to modify my AR > classes (or serialization/deserialization code) to allow me to > serialize/deserialize these AR classes? > > [Serializable] > [DataContract] > [ActiveRecord("Patients")] > public class Patient : ActiveRecordBase<Patient> > { > [DataMember] > [PrimaryKey(Generator = PrimaryKeyType.Identity, Column = > "PatientId")] > public virtual long Id { get; set; } > > [DataMember] > [Property(NotNull = true, Length = 100)] > public virtual string First { get; set; } > > [DataMember] > [Property(NotNull = true, Length = 100)] > public virtual string Last { get; set; } > > [DataMember] > [XmlArray] > [HasMany(typeof(Address), Cascade = > ManyRelationCascadeEnum.AllDeleteOrphan, Table = "Addresses", > ColumnKey = "PatientId", Inverse = true)] > public virtual IList<Address> Addresses { get; set; } > } > > [Serializable] > [DataContract] > [ActiveRecord("Addresses")] > public class Address : ActiveRecordBase<Address> > { > [DataMember] > [PrimaryKey(Generator = PrimaryKeyType.Identity, Column = > "AddressId")] > public virtual long Id { get; set; } > > [DataMember] > [Property(NotNull = true, Length = 255)] > public virtual string Address1 { get; set; } > > [DataMember] > [Property(NotNull = true, Length = 255)] > public virtual string City { get; set; } > > [DataMember] > [Property(NotNull = true, Length = 10)] > public virtual string PostalCode { get; set; } > > [DataMember] > [Property(NotNull = true, Length = 50)] > public virtual string State { get; set; } > } > > Here's my code to serialize & deserialize: > > public static string Serialize(object objectToSerialize) > { > var ns = new XmlSerializerNamespaces(); > ns.Add(String.Empty, String.Empty); > > var memoryStream = new MemoryStream(); > var settings = new XmlWriterSettings {Indent = false, > OmitXmlDeclaration = true, Encoding = Encoding.UTF8}; > > var serializer = new XmlSerializer(typeof(T)); > var writer = XmlWriter.Create(memoryStream, settings); > serializer.Serialize(writer, objectToSerialize, ns); > > return Utf8ByteArrayToString(memoryStream.ToArray()); > } > > public static object Deserialize(string objectXml, Type[] > additionalTypes) > { > var encoding = new UTF8Encoding(); > var byteArray = encoding.GetBytes(objectXml); > > var memoryStream = new MemoryStream(byteArray); > var xmlRoot = XElement.Load(memoryStream); > > var o = new XmlSerializer(typeof(T), > additionalTypes).Deserialize(xmlRoot.CreateReader()); > return o; > } > > Thanks! > > -- > You received this message because you are subscribed to the Google Groups > "Castle Project Users" group. > To post to this group, send email to [email protected] > . > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/castle-project-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.
