dreamdoctor
dreamdoctor
CC#
Created by dreamdoctor on 3/8/2023 in #help
❔ Read a .pdb file in C#
Does anyone have a simple example of opening and reading a Windows PDB (not Portable PDB) file in C#? The examples I can find from Microsoft and others are all in C++, and the couple of examples I can find are very old and no longer work.
19 replies
CC#
Created by dreamdoctor on 3/2/2023 in #help
✅ Suggestions for something like ConcurrentQueue with events
C# beginner question... I have an app with multiple threads. I need to pass data from one thread to the other using some form of FIFO queue. I can use ConcurrentQueue, however it doesn't appear to have any events available for enqueue or dequeue, which means I would need to poll the queue for new items, which doesn't seem like the right thing to do. I could add my own events, but that also seems like reinventing the wheel. Surely this is a very common situation. Are there any threadsafe queue techniques or libraries I can use with events available?
18 replies
CC#
Created by dreamdoctor on 1/18/2023 in #help
✅ ASP.NET API (EF Core) Relationships
Using the following example in my learnings, I'm struggling to make this work the way I want it to.
public class Company
{
public int Id { get; set; }
public string Name { get; set; }
public ICollection<Employee> Employees { get; set; }
}
public class Employee
{
public int Id { get; set; }
public string Name { get; set; }
public string Phone { get; set; }
public Company Company { get; set; }
}
public class Company
{
public int Id { get; set; }
public string Name { get; set; }
public ICollection<Employee> Employees { get; set; }
}
public class Employee
{
public int Id { get; set; }
public string Name { get; set; }
public string Phone { get; set; }
public Company Company { get; set; }
}
When using swagger to POST a new Employee, if I want to specify a related Company I have to Include all the fields from the Company table, and the API creates a new Company record along with the new Employee record. So this is what it requires right now:
{
"name": "New Company",
"phone": "(123) 456 789",
"company": {
"name": "New Company"
}
}
{
"name": "New Company",
"phone": "(123) 456 789",
"company": {
"name": "New Company"
}
}
What I'd like to do is provide just a Company.Id for an existing Company record... So something like the this to add a new Employee, which includes the id 100 of an existing Company record:
{
"name": "New Company",
"phone": "(123) 456 789"
"company": 100
}
{
"name": "New Company",
"phone": "(123) 456 789"
"company": 100
}
I'm not sure how to make that work?
5 replies
CC#
Created by dreamdoctor on 1/17/2023 in #help
ASP.NET Core API - Post to accept JSON array with multiple items
I'm new to C#. I'm working through a tutorial for an ASP.NET Core API, and I'm trying to modify it slightly. The tutorial had the code below in the controller which accepts a single JSON item correctly.
[HttpPost]
public async Task<ActionResult<Mission>> PostMission(Mission mission)
{
if (_context.Missions == null)
{
return Problem("Entity set 'MissionContext.Missions' is null.");
}
_context.Missions.Add(mission);
await _context.SaveChangesAsync();

return CreatedAtAction(nameof(GetMission), new { id = mission.ID }, mission);
}
[HttpPost]
public async Task<ActionResult<Mission>> PostMission(Mission mission)
{
if (_context.Missions == null)
{
return Problem("Entity set 'MissionContext.Missions' is null.");
}
_context.Missions.Add(mission);
await _context.SaveChangesAsync();

return CreatedAtAction(nameof(GetMission), new { id = mission.ID }, mission);
}
I want to modify it to accept a JSON array with multiple items. I've been able to make the modification to accept the array and it works, however the original example returned a result containing the single new record including the new id. I'd like my modifications to do the same but with all the new records created if there are more than one. At the moment it just returns nothing.
[HttpPost]
public async Task<ActionResult<Mission>> PostMission(List<Mission> missions)
{
if (_context.Missions == null)
{
return Problem("Entity set 'MissionContext.Missions' is null.");
}

foreach (Mission _mission in missions)
{
_context.Missions.Add(_mission);
}

await _context.SaveChangesAsync();
//return CreatedAtAction(nameof(GetMission), new { id = mission.ID }, mission);
return NoContent();
}
[HttpPost]
public async Task<ActionResult<Mission>> PostMission(List<Mission> missions)
{
if (_context.Missions == null)
{
return Problem("Entity set 'MissionContext.Missions' is null.");
}

foreach (Mission _mission in missions)
{
_context.Missions.Add(_mission);
}

await _context.SaveChangesAsync();
//return CreatedAtAction(nameof(GetMission), new { id = mission.ID }, mission);
return NoContent();
}
11 replies