DEV Community

loading...

Discussion on: One-to-One Relationship with Entity Framework Core

Collapse
samselfridge profile image
samselfridge • Edited

So curious about something. I used this to get as far as the migrations then tried to implement the rest without help. Ended up pretty close, but the big difference is instead of creating a separate controller for weapons, since they maintain a 1to1 relationship, it made sense to add the add weapon to the character controller and specify the characterId in the url so the completed character controller now has:

    [HttpPost("{id}/weapon")]
    public async Task<IActionResult> AddWeapon(int id, AddWeaponDto newWeapon)
    {
      newWeapon.CharacterId = id;
      return Ok(await _weaponService.AddWeapon(newWeapon));
    }
Enter fullscreen mode Exit fullscreen mode

The only drawback that I can see immediately is using a separate weapon controller keeps the weapon/character logic more separate where as mine introduces uses a service from a different class in the character controller.

Am I missing anything else that would come back to bite me with this implementation?

Forem Open with the Forem app