I will appreciate your help, because I don't know how I can obtain child data from parent data list
Study the Entity Framework documentation link below. The LINQ pattern to filter child records is straight forward.
Sample JSON based on the model in your initial post.
[
{
"suiviBEId": 1,
"actionItems": [
{
"actionItemId": 1,
"suiviBEId": 1
},
{
"actionItemId": 2,
"suiviBEId": 1
}
]
},
{
"suiviBEId": 2,
"actionItems": [
{
"actionItemId": 3,
"suiviBEId": 2
},
{
"actionItemId": 4,
"suiviBEId": 2
}
]
}
]
Controller example that filters child records.
namespace WebApiSqlite.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class EtudeController : ControllerBase
{
private readonly ILogger<EtudeController> _logger;
private readonly ApplicationDbContext _context;
public EtudeController(ILogger<EtudeController> logger, ApplicationDbContext context)
{
_logger = logger;
_context = context;
}
[HttpGet]
public async Task<IActionResult> Get()
{
List<Models.SuiviBE> dev = await _context.SuiviBEs
.Include(s => s.ActionItems).ToListAsync();
return Ok(dev);
}
[HttpGet("{suiviBEId}/{actionItemId}")]
public async Task<IActionResult> Get(int suiviBEId, int actionItemId)
{
Models.SuiviBE? dev = await _context.SuiviBEs.Include(
a => a.ActionItems
.Where(a => a.ActionItemId == actionItemId)
).FirstOrDefaultAsync(s => s.SuiviBEId == suiviBEId);
return Ok(dev);
}
}
}
Filtered results and URL
https://localhost:7250/api/Etude/2/3
{
"suiviBEId": 2,
"actionItems": [
{
"actionItemId": 3,
"suiviBEId": 2
}
]
}
Routing to controller actions in ASP.NET Core
If you only want a single ActionItem, then write a query to fetch the ActionItem by Id.