Skip to content

DeserializeDataSet with multiple tables #71

@dbenson2000

Description

@dbenson2000

I'm hoping to use protobuf-net-data to replace the use of BinaryFormatter in a generic SQL caching solution. When retrieving from cache we don't know the number of tables in the DataSet. Could protobuf-net-data be extended to support this? It already supports an arbitrary number of columns and rows.

In the nunit test below, if I pass the right number of tables to the DeserializeDataSet call it will work. I would like to not specify any tables at all.

        [Test]
        public void MultipleDataSetTest()
        {
            // GIVEN: a DataSet with multiple tables
            DataSet expected = new DataSet();
            DataTable dt = expected.Tables.Add("Table1");
            dt.Columns.Add(new DataColumn("column1", typeof(int)));
            dt.Columns.Add(new DataColumn("column2", typeof(double)));
            dt.Rows.Add(1234, 100.10);

            DataTable dt2 = expected.Tables.Add("Table2");
            dt2.Columns.Add(new DataColumn("column1", typeof(string)));
            dt2.Columns.Add(new DataColumn("column2", typeof(int)));
            dt2.Rows.Add("serialization", 100);

            // WHEN: we serialize into cache
            var stream = new MemoryStream();
            DataSerializer.Serialize(stream, expected);
            stream.Position = 0;

            // THEN: we can deserialize the object with the same number of tables
            var actual = DataSerializer.DeserializeDataSet(stream, new List<string> { "Table1" });
            Assert.AreEqual(expected.Tables.Count, actual.Tables.Count);
            for (var table = 0; table < expected.Tables.Count; table++)
            {
                Assert.AreEqual(expected.Tables[table].Rows.Count, actual.Tables[table].Rows.Count);
                Assert.AreEqual(expected.Tables[table].Columns.Count, actual.Tables[table].Columns.Count);
            }
        }

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions