asp.net - 尝试在 asp.net 框架 api 中执行 GetAllPatients 方法时出现 Stackoverflow 异常
问题描述
我正在构建一个 api 来从 mongo db 获取患者详细信息。但它正在抛出“堆栈溢出异常”。我尝试调试代码,但在方法完成后出现该方法时我没有得到任何异常。
控制器
public class PatientController : ApiController
{
readonly MongoContext _dbContext;
public PatientController()
{
_dbContext = new MongoContext();
}
[Route("GetAllPatient")]
public IHttpActionResult GetAllPatient()
{
var documents = _dbContext._database.GetCollection("Patient_Details");
var document = documents.FindAll();
return Content(HttpStatusCode.OK, documents);
}
**模型 **
public class Patient
{
[BsonId]
public ObjectId Id { get; private set; }
[BsonElement("Name")]
[BsonRepresentation(BsonType.String)]
public string Patient_Name { set; get; }
[BsonElement("Patient_Id")]
[BsonRepresentation(BsonType.String)]
public string Patient_ID { set; get; }
[BsonElement("Patient_Age")]
[BsonRepresentation(BsonType.Int32)]
public int Patient_Age { set; get; }
[BsonElement("Patient_Gender")]
[BsonRepresentation(BsonType.String)]
public string Patient_Gender { set; get; }
[BsonElement("Patient_Aadhar")]
[BsonRepresentation(BsonType.String)]
public string Patient_Aadhar { set; get; }
[BsonElement("Patient_Email_ID")]
[BsonRepresentation(BsonType.String)]
public string Patient_Email_ID { set; get; }
[BsonElement("Patient_Phone_No")]
[BsonRepresentation(BsonType.Int64)]
public int Patient_Phone_No { set; get; }
[BsonElement("Patient_Address")]
[BsonRepresentation(BsonType.String)]
public string Patient_Address { set; get; }
[BsonElement("Patient_Old_Clinical_MRI_Records")]
[BsonRepresentation(BsonType.String)]
public string Patient_Old_Clinical_MRI_Records { set; get; }
[BsonElement("Patient_Old_Clinical_Diabetes_Records")]
[BsonRepresentation(BsonType.String)]
public string Patient_Old_Clinical_Diabetes_Records { set; get; }
[BsonElement("Patient_Clinical_Records_for_Mother")]
[BsonRepresentation(BsonType.String)]
public string Patient_Clinical_Records_for_Mother { set; get; }
[BsonElement("Patient_Clinical_Records_for_Father")]
[BsonRepresentation(BsonType.String)]
public string Patient_Clinical_Records_for_Father { set; get; }
[BsonElement("Patient_Clinical_Records_for_Blood_Pressure")]
[BsonRepresentation(BsonType.String)]
public string Patient_Clinical_Records_for_Blood_Pressure { set; get; }
[BsonElement("Patient_Old_Clinical_ECG_Records")]
[BsonRepresentation(BsonType.String)]
public string Patient_Old_Clinical_ECG_Records { set; get; }
[BsonElement("Service_Code")]
[BsonRepresentation(BsonType.String)]
public string Service_Code { set; get; }
[BsonElement("Services_Group")]
[BsonRepresentation(BsonType.String)]
public string Services_Group { set; get; }
[BsonElement("Disease_Code")]
[BsonRepresentation(BsonType.String)]
public string Disease_Code { set; get; }
[BsonElement("State")]
[BsonRepresentation(BsonType.String)]
public string State { set; get; }
[BsonElement("Area")]
[BsonRepresentation(BsonType.String)]
public string Area { set; get; }
[BsonElement("Branch_Code")]
[BsonRepresentation(BsonType.String)]
public string Branch_Code { set; get; }
[BsonElement("Physician_Name")]
[BsonRepresentation(BsonType.String)]
public string Physician_Name { set; get; }
[BsonElement("Consent_form_To_Hospital")]
[BsonRepresentation(BsonType.String)]
public string Consent_form_To_Hospital { set; get; }
[BsonElement("Consent_Form_To_Relatives")]
[BsonRepresentation(BsonType.String)]
public string Consent_Form_To_Relatives { set; get; }
[BsonElement("Consent_Form_To_Corp")]
[BsonRepresentation(BsonType.String)]
public string Consent_Form_To_Corp { set; get; }
}
Webapi配置
public static void Register(HttpConfiguration config)
{
var json = config.Formatters.JsonFormatter;
json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
config.Formatters.Remove(config.Formatters.XmlFormatter);
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
我没有得到实际的错误在哪里?任何帮助将不胜感激。
解决方案
推荐阅读
- c# - 在 IServiceCollection 上注册通用配置的方法
- mql4 - 我对我的代码中的 ordersend 和 orderclose 中的 mql4 有一些疑问
- android-recyclerview - 如何将 onClick 侦听器应用于 CardView 中的 imageView
- javascript - 专业人士在哪里?以下代码不适用于 iOS
- java - 如何单击警报中的按钮?
- branch.io - Branch.io:有没有办法指定分支横幅可以出现在单页应用程序中的哪个页面上?
- javascript - 从谷歌云存储下载文件导致nodejs内存泄漏
- python - Flask 的 send_file() 函数在查找文件时不断更改目录
- php - PHP If/else/elseif 有多个条件
- java - 一个方法怎么可能存在于程序的一个部分而不存在于另一个部分?