Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Cannot deserialize ActiveRecord object due to IList<T>
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Michael  
View profile  
 More options Mar 19 2012, 7:32 pm
From: Michael <mhartma...@yahoo.com>
Date: Mon, 19 Mar 2012 16:32:34 -0700 (PDT)
Local: Mon, Mar 19 2012 7:32 pm
Subject: Cannot deserialize ActiveRecord object due to IList<T>
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 must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mauricio Scheffer  
View profile  
 More options Mar 19 2012, 7:37 pm
From: Mauricio Scheffer <mauricioschef...@gmail.com>
Date: Mon, 19 Mar 2012 20:37:22 -0300
Local: Mon, Mar 19 2012 7:37 pm
Subject: Re: Cannot deserialize ActiveRecord object due to IList<T>

Maybe this can help :
http://stackoverflow.com/questions/1958684/nhibernate-how-do-i-xmlser...

Cheers,
Mauricio


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael  
View profile  
 More options Mar 19 2012, 10:51 pm
From: Michael <mhartma...@yahoo.com>
Date: Mon, 19 Mar 2012 19:51:42 -0700 (PDT)
Local: Mon, Mar 19 2012 10:51 pm
Subject: Re: Cannot deserialize ActiveRecord object due to IList<T>
Fantastic!  Using the DataContractSerializer solved my problem.

Many thanks!

On Mar 19, 6:37 pm, Mauricio Scheffer <mauricioschef...@gmail.com>
wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »