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
La logica diria… en este ejemplo sencillo que tendria que funcionar
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.
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.
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)
Mapeando…
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
- Stored Procedure Mapping (by ADO.NET team blog)
http://blogs.msdn.com/adonet/archive/2008/03/26/stored-procedure-mapping.aspx