[Entity Framework] Error “AssociationSets must be consistently mapped for all operations”. Mapear asociaciones en Store Procedure de Delete

Con un proyecto donde estoy probando Entity Framework, para ir mas alla de lo simple a lo que estamos acostumbrados y tambien para poder testear esta tecnologia, llego el momento del mapeo a mis procedimientos almacenados.

Aclaracion: Todavía tengo el SP1 Beta del VS2008… (porque según el ADO.NET Team esta issue se debera solucionar en futuras versiones)

Problema

Estaba probando el Mapeo a Procedimientos Almacenados de una entidad de mi DataModel

image

La logica diria… en este ejemplo sencillo que tendria que funcionar

image

Pero dos errores afloraron

Error:
Error 2048: The EntitySet ‘Pacientes’ includes function mappings for AssociationSet ‘FK_Pacientes_EstadoCivil’, but none exists in element ‘DeleteFunction’ for type ‘{Proyecto}.{Entidad}’. AssociationSets must be consistently mapped for all operations.
   

image

 

El problema:
     AssociationSets must be consistently mapped for all operations.   

Es decir el conjunto de asociaciones debe ser “CONSISTENTE” en todas las operaciones (Insert/Update/Delete).

 

Solucion

Tenemos que mantener estas relaciones hasta en el delete.

image

O sea que en mi querida prueba simple el PA

ALTER PROCEDURE Pacientes_Eliminar
      @PacienteId int      
AS
BEGIN    
    DELETE [Pacientes]          
    WHERE PacienteId = @PacienteId
END


Quedo de esta manera

ALTER PROCEDURE Pacientes_Eliminar
      @PacienteId int,
      @TipoDocumentoId  tinyint,
      @EstadoCivilId  tinyint  
AS
BEGIN    
    DELETE [Pacientes]          
    WHERE PacienteId = @PacienteId
END

Con el unico objetivo de MAPEAR

Para eso actualizamos el modelo… un Refresh (casi desde cualquier menu contextual de nuestro modelo)

image  image

luego…

image

Mapeando…

image

 

NOTA 1:

(from ADO.NET Team)…We hope to provide a solution for this issue in future versions of the Entity Framework, but for now, this is what needs to be done for associations whose target multiplicity, with respect to the type being mapped, is 1 or 0..1. In other words, the “reference” end of the association needs to be mapped to the keys of the target type.

 

NOTA 2:

Me canse de configurar todo esto… quisiera algo que se configure “automaticamente” 🙂

 

 

Enlaces

2 comentarios sobre “[Entity Framework] Error “AssociationSets must be consistently mapped for all operations”. Mapear asociaciones en Store Procedure de Delete”

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *