Serializing classes derived from dataset

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Serializing classes derived from dataset

    Hi,

    I am trying to store various objects within session. Due
    to the site being hosted in a web farm we are going to
    have to use either State Server or SQL Server to persist
    the data in session. All of the objects are classes which
    inherit from a typed dataset.

    Looking at MSDN I have found the following two (what I
    believe to be) relevent statements (from article Object
    Serialization in the .NET Framework):

    "Derived classes should call the GetObjectData method on
    the base object if the latter implements ISerializable"

    and

    "When you derive a new class from one that implements
    ISerializable, the derived class must implement both the
    constructor as well as the GetObjectData method if it has
    any variables that need to be serialized."

    Since the Dataset implements ISerializable the above
    statements indicate that I should override the
    GetObjectData method. However if I try and override this
    method I get a compile error stating:

    "sub 'GetObjectData' cannot be declared 'Overrides'
    because it does not override a sub in a base class."

    I am also unable to call the method GetObjectData on the
    base class as it is not accessible.

    The classes which I am trying to persist have their own
    properties, some of which are themselves objects which
    inherit from datasets.

    If I create a test class which inherits from a typed
    dataset, and which has two additional properites (named
    Property1 and Property2) the following XML is persisted:

    <?xml version="1.0" encoding="utf-16"?>
    <xs:schema id="dsTemp"
    targetNamespace="http://tempuri.org/dsTemp.xsd"
    xmlns:mstns="http://tempuri.org/dsTemp.xsd"
    xmlns="http://tempuri.org/dsTemp.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
    attributeFormDefault="qualified"
    elementFormDefault="qualified">
    <xs:element name="dsTemp" msdata:IsDataSet="true"
    msdata:Property1="1" msdata:Property2="Aidan">
    <xs:complexType>
    <xs:choice maxOccurs="unbounded">
    <xs:element name="InvoiceHeader">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="InvoiceHeaderID"
    msdata:ReadOnly="true" msdata:AutoIncrement="true"
    type="xs:int" />
    <xs:element name="POHeaderID" type="xs:int"
    minOccurs="0" />
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:choice>
    </xs:complexType>
    <xs:unique name="dsTempKey1" msdata:PrimaryKey="true">
    <xs:selector xpath=".//mstns:InvoiceHeader" />
    <xs:field xpath="mstns:InvoiceHeaderID" />
    </xs:unique>
    </xs:element>
    </xs:schema>

    Note that the properties have been serialized, but have
    been serialized as "<xs:element name="dsTemp"
    msdata:IsDataSet="true" msdata:Property1="1"
    msdata:Property2="Aidan">"

    I can find no way in which I can de-serialize these fields.

    Can someone please explain how I can have a class which
    inherits from a dataset, and which I can then serialize
    and de-serialize without losing the properties.

    Thanks in advance

    Aidan
    Aidan Glendye Guest

  2. Similar Questions and Discussions

    1. #39713 [NEW]: Static variables defined in static methods duplicated in derived classes
      From: paul at digitalbacon dot us Operating system: Linux, Mac OS X 10.4, Windows XP PHP version: 5.2.0 PHP Bug Type: ...
    2. Can a repeater's ItemTemplate instantiate derived classes?
      I posted this in a different group yesterday with no responses, so I'll try here. I would like to have a repeater class like this: ...
    3. Design time support for classes derived from DataGridColumn
      How to get design time support for classes derived from DataGridColumn ? I have created new DataGridColumn type, it uses image from database as...
    4. Ccopying a datatable content from an untyped dataset into a table which is inside a typed dataset
      Hi All, I am facing problem in copying content of table from a untyped dataset into to a table inside the typed dataset. I wanted to copy the data...
    5. exposing derived classes to proxy without fake webmethod?
      Hi, try using on the appropriate WebMethod. This attribute instructs the ASMX engine to include the type description for type bla. Cheers, --...
  3. #2

    Default Serializing classes derived from dataset

    Note that the xml which should have been displayed
    indicated that the properties were included in a dataset
    element as

    msdata:Property1="1"
    msdata:Property2="Aidan"

    >-----Original Message-----
    >Hi,
    >
    >I am trying to store various objects within session. Due
    >to the site being hosted in a web farm we are going to
    >have to use either State Server or SQL Server to persist
    >the data in session. All of the objects are classes
    which
    >inherit from a typed dataset.
    >
    >Looking at MSDN I have found the following two (what I
    >believe to be) relevent statements (from article Object
    >Serialization in the .NET Framework):
    >
    >"Derived classes should call the GetObjectData method on
    >the base object if the latter implements ISerializable"
    >
    >and
    >
    >"When you derive a new class from one that implements
    >ISerializable, the derived class must implement both the
    >constructor as well as the GetObjectData method if it has
    >any variables that need to be serialized."
    >
    >Since the Dataset implements ISerializable the above
    >statements indicate that I should override the
    >GetObjectData method. However if I try and override this
    >method I get a compile error stating:
    >
    >"sub 'GetObjectData' cannot be declared 'Overrides'
    >because it does not override a sub in a base class."
    >
    >I am also unable to call the method GetObjectData on the
    >base class as it is not accessible.
    >
    >The classes which I am trying to persist have their own
    >properties, some of which are themselves objects which
    >inherit from datasets.
    >
    >If I create a test class which inherits from a typed
    >dataset, and which has two additional properites (named
    >Property1 and Property2) the following XML is persisted:
    >
    ><?xml version="1.0" encoding="utf-16"?>
    ><xs:schema id="dsTemp"
    >targetNamespace="http://tempuri.org/dsTemp.xsd"
    >xmlns:mstns="http://tempuri.org/dsTemp.xsd"
    >xmlns="http://tempuri.org/dsTemp.xsd"
    >xmlns:xs="http://www.w3.org/2001/XMLSchema"
    >xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
    >attributeFormDefault="qualified"
    >elementFormDefault="qualified">
    > <xs:element name="dsTemp" msdata:IsDataSet="true"
    >msdata:Property1="1" msdata:Property2="Aidan">
    > <xs:complexType>
    > <xs:choice maxOccurs="unbounded">
    > <xs:element name="InvoiceHeader">
    > <xs:complexType>
    > <xs:sequence>
    > <xs:element name="InvoiceHeaderID"
    >msdata:ReadOnly="true" msdata:AutoIncrement="true"
    >type="xs:int" />
    > <xs:element name="POHeaderID" type="xs:int"
    >minOccurs="0" />
    > </xs:sequence>
    > </xs:complexType>
    > </xs:element>
    > </xs:choice>
    > </xs:complexType>
    > <xs:unique name="dsTempKey1" msdata:PrimaryKey="true">
    > <xs:selector xpath=".//mstns:InvoiceHeader" />
    > <xs:field xpath="mstns:InvoiceHeaderID" />
    > </xs:unique>
    > </xs:element>
    ></xs:schema>
    >
    >Note that the properties have been serialized, but have
    >been serialized as "<xs:element name="dsTemp"
    >msdata:IsDataSet="true" msdata:Property1="1"
    >msdata:Property2="Aidan">"
    >
    >I can find no way in which I can de-serialize these
    fields.
    >
    >Can someone please explain how I can have a class which
    >inherits from a dataset, and which I can then serialize
    >and de-serialize without losing the properties.
    >
    >Thanks in advance
    >
    >Aidan
    >.
    >
    Aidan Glendye Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139