I need your help. I am developing a web application with C# ASP.NET and I have a problem. I am using the N-layer architecture and I am using services. So, I don't know how to implement the many-to-many relationship in the create method.
Interface Class
public interface IInformacionBasicaEstudianteService
{
Task<List<InformacionBasicaEstudiante>> Lista();
Task<InformacionBasicaEstudiante> ObtenerInformacionBasicaEstudiante(int pIdUsuario);
Task<InformacionBasicaEstudiante> Crear(InformacionBasicaEstudiante modelo);
Task<InformacionBasicaEstudiante> Editar(InformacionBasicaEstudiante modelo);
}
Method within the service class
public async Task<InformacionBasicaEstudiante> Crear(InformacionBasicaEstudiante entidad)
{
try
{
InformacionBasicaEstudiante infoCreada = await _repository.Crear(entidad);
if (infoCreada.IdInfoBasEstudiante == 0)
throw new TaskCanceledException("NO SE PUDO GUARDAR LA INFORMACIÓN");
IQueryable<InformacionBasicaEstudiante> query = await _repository.Consultar(u => u.IdInfoBasEstudiante == infoCreada.IdInfoBasEstudiante);
infoCreada = query.Include(r => r.IdDptoExpDocNavigation).Include(r => r.IdDptoNacNavigation)
.Include(r => r.IdDptoResidenciaNavigation).Include(r => r.IdEpsNavigation)
.Include(r => r.IdEstratoNavigation).Include(r => r.IdEtniaNavigation)
.Include(r => r.IdFrecCambioDomicNavigation).Include(r => r.IdGeneroNavigation)
.Include(r => r.IdInfoBasAcudienteNavigation).Include(r => r.IdMpioExpDocNavigation)
.Include(r => r.IdMpioNacNavigation).Include(r => r.IdMpioResidenciaNavigation)
.Include(r => r.IdPaisOrigenNavigation).Include(r => r.IdParentescoNavigation)
.Include(r => r.IdPobVictConfNavigation).Include(r => r.IdPropiedadViviendaNavigation)
.Include(r => r.IdResguardoNavigation).Include(r => r.IdSisbenNavigation)
.Include(r => r.IdTipoSangreNavigation).Include(r => r.IdTipoViviendaNavigation)
.Include(r => r.IdUsuarioNavigation).Include(r => r.IdZonaResidenciaNavigation)
.First();
return infoCreada;
}
catch (Exception ex)
{
throw;
}
}
ER-Diagram enter image description here
I need to know how to implement those relationships within the create service method so that when I create a register, it is directly saved in the many-to-many table.
Thank you very much.