英文:
ASP.NET Core Web API is not returning full object
问题
以下是翻译好的部分:
Model(模型):
public class ReconResults
{
public IEnumerable<int> ReconIds { get; set; }
public IEnumerable<ReconErrorResults> Messages { get; set; }
public bool Success { get; set; }
}
public class ReconErrorResults
{
int ErrNo { get; set; }
string ErrorMessage { get; set; }
}
Repo(数据访问层):
using (var connection = sqlProvider.GetConnection())
{
var aresults = connection.QueryMultipleAsync("recon.usp_pro",
parameters,
commandTimeout: 1500,
commandType: CommandType.StoredProcedure).Result;
results.Messages = await aresults.ReadAsync<ReconErrorResults>();
results.ReconIds = await aresults.ReadAsync<int>();
results.Success = (parameters.Get<int>("@Return") == 0 ? true : false);
}
Results(结果):
{
"reconIds": [
-1
],
"messages": [
{}
],
"success": false
}
英文:
I have an ASP.NET Core Web API returning ReconResults
. The API for some reason is not sending me the messages part of the object. I see the values of the messages prior to leaving the API. I am sure I am missing something pretty dumb.
Model:
public class ReconResults
{
public IEnumerable<int> ReconIds { get; set; }
public IEnumerable<ReconErrorResults> Messages { get; set; }
public bool Success { get; set; }
}
public class ReconErrorResults
{
int ErrNo { get; set; }
string ErrorMessage { get; set; }
}
Repo:
using (var connection = sqlProvider.GetConnection())
{
var aresults = connection.QueryMultipleAsync("recon.usp_pro",
parameters,
commandTimeout: 1500,
commandType: CommandType.StoredProcedure).Result;
results.Messages = await aresults.ReadAsync<ReconErrorResults>();
results.ReconIds = await aresults.ReadAsync<int>();
results.Success = (parameters.Get<int>("@Return") == 0 ? true : false);
}
Results
{
"reconIds": [
-1
],
"messages": [
{}
],
"success": false
}
答案1
得分: 5
Your ReconErrorResults
properties should be marked as Public if you intend to use them outside the ReconErrorResults
class...
public class ReconErrorResults
{
public int ErrNo { get; set; }
public string ErrorMessage { get; set; }
}
英文:
Your ReconErrorResults
properties should be marked as Public if you intend to use them outside the ReconErrorResults
class...
public class ReconErrorResults
{
public int ErrNo { get; set; }
public string ErrorMessage { get; set; }
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论