我有 2 个 API,其中一个是 Sybase 报告的数据访问代理。这是在 Framework 4.7.2 中编写的,并返回一个 DTO,其中包含一个属性,该属性是由 DbFactory 系统或至少围绕它们的包装器填充的 Dataset。
另一个 API 接收 DTO 很好,除了当数据表为“空”时,如仅在标题但没有行中,我只收到数据表的名称,但没有任何标题,因为我将其解析为 Excel 工作表构成尝试写入工作表时出现“列超出范围”异常的问题。
我发现这方面的信息有限,解决方案也不多。有人说 .Net Standard 2+ 应该解决 Framework 和 Core 如何序列化数据集之间的兼容性问题。
我需要一种方法来可靠地从此 API 获取数据表/数据集,以便在没有行的情况下返回仅包含标题的 Excel 工作簿。
using (connection)
{
try
{
connection.ChangeDatabase(schema.DatabaseName);
command.CommandText = $"{schema.Name}.{spName}";
command.CommandType = CommandType.StoredProcedure;
if (pList != null)
{
for (int i = 0; i < pList.Count; i++)
{
command.Parameters.Add(GetParameter(pList[i].DefaultValue, pList[i].Name, pList[i].BaseParameter?.DbTypeName));
}
}
command.Fill(ds);
for (int i = 0; i < ds.Tables.Count; i++)
{
ds.Tables[i].TableName = $"{spName}{i + 1}";
}
}
catch (Exception e)
{
ErrorLogger.Error($"{e.Message}, {e.InnerException} with a trace of {e.StackTrace}", e);
if(e.Source.Contains("SQL Anywhere .NET Data Provider"))
throw new Exception($"An error has occurred that has to do with the Stored Procedure and needs correcting at that level: {e.Message}");
throw e;
}
}
我只是像这样在核心端进行标准反序列化:
report = await response.Content.ReadAsAsync<ResponseObject>();
更新:因此,在 4.7.2 API 中,该对象似乎包含数据表中的元数据并显示标题,但是当我返回 Postman 时,它只是有一个命名数组。
"Table": {
"ReportHighRiskEntityAccounts1": []
},
如何确保 Datatable 元数据在从 4.7.2 API 传输时被序列化?