Получение исключения Stackoverflow при попытке выполнить метод GetAllPatients в asp. net framework api - PullRequest
0 голосов
/ 06 марта 2020

Я создаю API для получения сведений о пациенте с понедельника go дБ. Но он выдает «Исключение переполнения стека». Я попытался отладить код, но я не получил никаких исключений в методе, пока он возник после завершения метода.

Контроллер

 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; }
}

Webapiconfig

 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 }
        );



    }

Я не понимаю, где настоящая ошибка? Любая помощь будет оценена.

...