I'm using .net core(2.1) web application. I'm implementing the web API where it will connect to SQLite DB and get the data and return the query result. Here is the code that I have used.
using (var connection = new SQLiteConnection("Data Source=D:/SQL-Lite/xxxxx/test.db;Version=3;")) {
connection.Open();
using (var transaction = connection.BeginTransaction())
{
var selectCommand = connection.CreateCommand();
selectCommand.Transaction = transaction;
selectCommand.CommandText = "SELECT * FROM Employee";
var ds = new DataSet();
var da = new SQLiteDataAdapter(selectCommand);
da.Fill(ds);
if (ds.Tables != null && ds.Tables.Count > 0)
response = JsonConvert.SerializeObject(ds.Tables[0]);
}
}
previously I have worked with SQL server and ASP.NET where I will get the JSON during serialization in the format of rows and columns. As below
Now I'm also getting some metadata in XML along with the actual data. I'm attaching the serialized data below.
{"DataTable.RemotingVersion":{"Major":2,"Minor":0,"Build":-1,"Revision":-1,"MajorRevision":-1,"MinorRevision":-1},"XmlSchema":"<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<xs:schema xmlns=\"\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\">\r\n <xs:element name=\"Table\">\r\n <xs:complexType>\r\n <xs:sequence>\r\n <xs:element name=\"Id\" type=\"xs:long\" msdata:targetNamespace=\"\" minOccurs=\"0\" />\r\n <xs:element name=\"FirstName\" type=\"xs:string\" msdata:targetNamespace=\"\" minOccurs=\"0\" />\r\n <xs:element name=\"Salary\" type=\"xs:double\" msdata:targetNamespace=\"\" minOccurs=\"0\" />\r\n <xs:element name=\"Department\" type=\"xs:string\" msdata:targetNamespace=\"\" minOccurs=\"0\" />\r\n </xs:sequence>\r\n </xs:complexType>\r\n </xs:element>\r\n <xs:element name=\"tmpDataSet\" msdata:IsDataSet=\"true\" msdata:MainDataTable=\"Table\" msdata:UseCurrentLocale=\"true\">\r\n <xs:complexType>\r\n <xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\" />\r\n </xs:complexType>\r\n </xs:element>\r\n</xs:schema>","XmlDiffGram":"<diffgr:diffgram xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\" xmlns:diffgr=\"urn:schemas-microsoft-com:xml-diffgram-v1\">\r\n <tmpDataSet>\r\n <Table diffgr:id=\"Table1\" msdata:rowOrder=\"0\">\r\n <Id>11</Id>\r\n <FirstName>nithin</FirstName>\r\n <Salary>5000</Salary>\r\n <Department>CSE</Department>\r\n </Table>\r\n </tmpDataSet>\r\n</diffgr:diffgram>"}
How can I avoid these other data and only get the actual query result (rows & columns) during serialization?
