It began with a SQL Server stored procedure that looks like this :
CREATE PROCEDURE [dbo].[ExtractionPourFicheSante]
@AnBudg NVARCHAR(4),
@Ecole NVARCHAR(3),
@Fiche NVARCHAR(10),
@grprep NVARCHAR(20),
@classi NVARCHAR(20)
AS
BEGIN
SET NOCOUNT ON;
IF (ISNULL(NULLIF(LTRIM(RTRIM(@Fiche)), ''), 'NA') = 'NA')
IF (ISNULL(NULLIF(LTRIM(RTRIM(@grprep)), ''), 'NA') = 'NA')
IF (ISNULL(NULLIF(LTRIM(RTRIM(@classi)), ''), 'NA') = 'NA')
SELECT
ISNULL(z.FICHE, '123456789') AS TheKey,
z.*
FROM
[gpi].dbo.GPM_E_ELE_Z_DOSSIER Z
ELSE
/* similar query */
ELSE
/* similar query */
ELSE
/* similar query */
END
Then bringing it into an ASP.NET MVC project with EF 6.0 database first approach.
Brought the stored procedure in with auto-mapper by right clicking in the EDMX file.
Now trying to create a list
type view using the contextual MVC menu, with ExtractionPourFicheSante_Result
as the view model is actually returning an error :
'ExtractionPourFicheSante_Result' has no primary key defined. Define the key for this Entity type.
Well OK, the best candidate for being a primary key is TheKey
which I know for sure is UNIQUE. Searched through with google and on SO... Haven't found anything about defining a primary key in a stored procedure. Neither found anything about getting EF to pretend there is one. I could work this around as usual. But I've had enough...
This may be impossible with the current version of EF. It's just weird that they allow to import such a stored procedure and then one can't work with it because there is no primary key involved in the select part.
Any clean solutions ? Someone have been through this ? Thanks a lot for reading.