Billy
Billy
CC#
Created by Billy on 6/21/2024 in #help
XML Deserialization
Hi, I want to deserialize an XML document and I'm using an XmlSerializer. That's all fine, but the order of the elements in the XML is important to me. For example, I might have some xml that looks like:
<books>
<book>
<header>header one</header>
<title>title one</title>
</book>
<book>
<title>title two</title>
<header>header two</header>
</book>
</books>
<books>
<book>
<header>header one</header>
<title>title one</title>
</book>
<book>
<title>title two</title>
<header>header two</header>
</book>
</books>
Where the title and header order is important to me. Is there any way to pull out the "index" of the xml tag when deserializing?
28 replies
CC#
Created by Billy on 4/13/2024 in #help
SSL error with entity core
Or malformed SQL, it varies... I have web api that access and database using entity core. I have an angular frontend. If I call my endpoints invidually, or successively, it works fine. But for some reason when I do something like this: let patientsObs = forkJoin(neededPatientId.map(id => patientService.getPatientById(id))).pipe(defaultIfEmpty([])); let doctorObs = forkJoin(needDoctorId.map(id => doctorService.getDoctorById(id))).pipe(defaultIfEmpty([])); return combineLatest([patientsObs, doctorObs]).pipe( where neededPatientId and needDoctorId are arrays if integers, the backend throws an exception. But when i get the patientObs first, and then the doctorObs, it works fine
10 replies
CC#
Created by Billy on 4/5/2024 in #help
Passing DateOnly to controller
What's wrong with this snippet? [HttpGet("ondate")] public async Task<IActionResult> GetAppointmentsByDate([FromQuery]DateOnly date) { var appointments = await _appointmentDatabaseService.GetAppointmentByDate(date); if (appointments != null) { return Ok(appointments); } return NotFound(); } I'm using swagger, and the JSON looks like this: { "year": 2024, "month": 5, "day": 5, "dayOfWeek": 1 } yet I get the default(DateOnly) in my request
13 replies
CC#
Created by Billy on 4/5/2024 in #help
Naming conventions with Dto
I've got a PatientDto and it has an Id in it from entity core. Sometimes I want a PatientDto without an Id, i.e. if I've got an endpoint GetPatientById(int id) there isn't much point in returning the Id. Should I just returning it anyway and avoid the hassle or should i have a different dto?
52 replies
CC#
Created by Billy on 4/3/2024 in #help
Entity Framework IQueryable question
I'm trying to get a list of prescriptions from my Patients entity: var kk = await _context.Patients.Where(p => p.Id == id) .Include(p => p.Prescriptions) .ThenInclude(p => p.Medicine) .Include(p => p.Prescriptions) .ThenInclude(p => p.Doctor) .ToListAsync(); var gg = await _context.Patients.Where(p => p.Id == id) .Include(p => p.Prescriptions) .ThenInclude(p => p.Medicine) .Include(p => p.Prescriptions) .ThenInclude(p => p.Doctor) .Select(p => new { Prescription = p.Prescriptions.Select(p => p.ToDto()) }) .ToListAsync(); kk works, but gg returns an empty list;. Any ideas why this might be happening? I know it's a short snippet, but I figured there would be something obvious I am doing wrong... Thanks!
33 replies
CC#
Created by Billy on 4/2/2024 in #help
Model, Dto, Entity - Id?
Hi, I'm messing with a simple CRUD application. My PatientEntity looks like this: public class PatientEntity { public int Id { get; set; } public string FirstName { get; set; } public string Surname { get; set; } public int Age { get; set; } public string Gender { get; set; } } And my model looks like this (no id): public class Patient { public string FirstName { get; set; } public string Surname { get; set; } public int Age { get; set; } public string Gender { get; set; } } And my dto looks like this (no id): public class PatientDto { public string FirstName { get; set; } public string Surname { get; set; } public int Age { get; set; } public string Gender { get; set; } } And currently a method in my DatabaseService looks like this: public async Task<Patient> GetPatientById(int id) { PatientEntity patientEntity = await _context.Patients.FindAsync(id); if (patientEntity != null) { return patientEntity.ToPatient(); // i.e. returning the Patient model } _logger.LogInformation("Patient not found in the database."); return null; } Should my DatabaseService return a PatientEntity i.e. with an id, and my PatientDto contain the Id? My PatientDto is returned by a web api controller. I feel like my PatientDto should contain the Id. I guess the problem is that the DatabaseService is returning a Patient (Model) rather than the PatientEntity. Does it make sense to return the model from the Database service? Here's the git: https://github.com/billymaat/MedTrackDash
81 replies