I have those two main classes, I am trying to read the record and its related one but I am getting a broken JSON, The only way I got it to work is by using Automapper. but why is this happening,
[Table("PatientsRegistry")]publicclassPatientRegistry{[DatabaseGenerated(DatabaseGeneratedOption.Identity)][Display(Name="Record Id")]publiclongRecordId{ get;set;}[Key,DatabaseGenerated(DatabaseGeneratedOption.None)][Display(Name="Patient File Number")]publiclongPatientFileId{ get;set;}[Required,StringLength(50)][Display(Name="First Name")]publicstringFirstName{ get;set;}[Required,StringLength(50)]publicstringSecondName{ get;set;}[Required,StringLength(50)]publicstringLastName{ get;set;}publicintGenderId{ get;set;}publicGenderGender{ get;set;}publicDateTimeDateCreated{ get;set;}=DateTime.UtcNow;[Timestamp]publicbyte[]RowVersion{ get;set;}publicICollection<PartnerRegistry>Partners{ get;set;}publicPatientRegistry(){Partners=newCollection<PartnerRegistry>();}}publicclassPartnerRegistry{[Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)]publiclongRecordId{ get;set;}publiclongPatientFileId{ get;set;}publiclongPartnerFileId{ get;set;}publicPatientRegistryPatientsRegistry{ get;set;}publicDateTimeStartDate{ get;set;}publicDateTime?EndDate{ get;set;}}
[HttpGet("{ids}")] public async Task<IActionResult> getAll(long Ids) { var patient = await context.PatientsRegistry .Include(pt => pt.Gender) .Include(pt => pt.Partners) .SingleOrDefaultAsync(pt => pt.PatientFileId == Ids); return Ok(patient); }
{"recordId": 1,"patientFileId": 1111,"firstName": "John","secondName": "M","lastName": "Doe","genderId": 1,"gender": {"id": 1,"name": "Male" },"dateCreated": "2017-11-25T08:40:07.75444","rowVersion": "AAAAAAAAB9E=","partners": [{"recordId": 1,"patientFileId": 1111,"partnerFileId": 2222<div class="grammarly-disable-indicator"></div>