Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeserializeDataSet with multiple tables #71

Open
dbenson2000 opened this issue Dec 15, 2023 · 0 comments
Open

DeserializeDataSet with multiple tables #71

dbenson2000 opened this issue Dec 15, 2023 · 0 comments

Comments

@dbenson2000
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant