public void SerializeDataSet2() { DataSet quota = new DataSet("Quota"); // Dimension DataTable dt = new DataTable("Dimension"); quota.Tables.Add(dt); dt.Columns.Add("Number", typeof(int)); dt.Columns["Number"].AllowDBNull = false; dt.Columns["Number"].ColumnMapping = MappingType.Attribute; dt.Columns.Add("Title", typeof(string)); dt.Columns["Title"].AllowDBNull = false; dt.Columns["Title"].ColumnMapping = MappingType.Attribute; dt.Rows.Add(new object[] { 0, "Hospitals" }); dt.Rows.Add(new object[] { 1, "Doctors" }); dt.Constraints.Add("PK_Dimension", dt.Columns["Number"], true); quota.AcceptChanges(); XmlSerializer ser = new XmlSerializer(quota.GetType()); StringWriter sw = new StringWriter(); ser.Serialize(sw, quota); DataSet ds = (DataSet)ser.Deserialize(new StringReader(sw.ToString())); }
public void SerializeDataSet3() { string xml = @"<?xml version=""1.0"" encoding=""utf-8""?><DataSet><xs:schema id=""Example"" xmlns="""" xmlns:xs=""http://www.w3.org/2001/XMLSchema"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata""><xs:element name=""Example"" msdata:IsDataSet=""true""><xs:complexType><xs:choice maxOccurs=""unbounded"" minOccurs=""0""><xs:element name=""Packages""><xs:complexType><xs:attribute name=""ID"" type=""xs:int"" use=""required"" /><xs:attribute name=""ShipDate"" type=""xs:dateTime"" /><xs:attribute name=""Message"" type=""xs:string"" /><xs:attribute name=""Handlers"" type=""xs:int"" /></xs:complexType></xs:element></xs:choice></xs:complexType></xs:element></xs:schema><diffgr:diffgram xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"" xmlns:diffgr=""urn:schemas-microsoft-com:xml-diffgram-v1""><Example><Packages diffgr:id=""Packages1"" msdata:rowOrder=""0"" ID=""0"" ShipDate=""2004-10-11T17:46:18.6962302-05:00"" Message=""Received with no breakage!"" Handlers=""3"" /><Packages diffgr:id=""Packages2"" msdata:rowOrder=""1"" ID=""1"" /></Example></diffgr:diffgram></DataSet>"; DataSet ds = new DataSet("Example"); // Add a DataTable DataTable dt = new DataTable("Packages"); ds.Tables.Add(dt); // Add an ID DataColumn w/ ColumnMapping = MappingType.Attribute dt.Columns.Add(new DataColumn("ID", typeof(int), "", MappingType.Attribute)); dt.Columns["ID"].AllowDBNull = false; // Add a nullable DataColumn w/ ColumnMapping = MappingType.Attribute dt.Columns.Add(new DataColumn("ShipDate", typeof(DateTime), "", MappingType.Attribute)); dt.Columns["ShipDate"].AllowDBNull = true; // Add a nullable DataColumn w/ ColumnMapping = MappingType.Attribute dt.Columns.Add(new DataColumn("Message", typeof(string), "", MappingType.Attribute)); dt.Columns["Message"].AllowDBNull = true; // Add a nullable DataColumn w/ ColumnMapping = MappingType.Attribute dt.Columns.Add(new DataColumn("Handlers", typeof(int), "", MappingType.Attribute)); dt.Columns["Handlers"].AllowDBNull = true; // Add a non-null value row DataRow newRow = dt.NewRow(); newRow["ID"] = 0; newRow["ShipDate"] = DateTime.Now; newRow["Message"] = "Received with no breakage!"; newRow["Handlers"] = 3; dt.Rows.Add(newRow); // Add a null value row newRow = dt.NewRow(); newRow["ID"] = 1; newRow["ShipDate"] = DBNull.Value; newRow["Message"] = DBNull.Value; newRow["Handlers"] = DBNull.Value; dt.Rows.Add(newRow); ds.AcceptChanges(); XmlSerializer ser = new XmlSerializer(ds.GetType()); StringWriter sw = new StringWriter(); ser.Serialize(sw, ds); string result = sw.ToString(); Assert.Equal(xml, result); }
public string MetadataLink(DataSet dataset) { return String.Format("<span class=\"metadata-link\">{0}</span>", Link( "View Metadata", DictHelper.Create( "controller=metadata", "action=view", "querystring=owner=" + dataset.Id.ToString() + "&type=" + dataset.GetType().Name ))); }