无法在实体框架中获得此存储过程的返回值

本文关键字:存储过程 返回值 实体 框架 | 更新日期: 2023-09-27 18:06:33

我不知道为什么这次不工作,我已经这样做了几次了,但这个给我带来了麻烦。

这是我的c#代码:
RT_TYPE_STRING query = dba.Database.SqlQuery<RT_TYPE_STRING>("EXEC dbo.CSDN_CreateDemandeAppro @sp1, @sp2, @sp3, @sp4", new SqlParameter("sp1", "20162017"), new SqlParameter("sp2", "590"), new SqlParameter("sp3", "430614451421"), new SqlParameter("sp4", 22.18m)).First();
if (query.NO_DA == "")
{
}

不知何故,query为空。我尝试直接在Management Studio中执行存储过程,它正确地返回了一个nvarchar

这是我的RT_TYPE_STRING
CREATE TABLE [dbo].[RT_TYPE_STRING]
(
    [NO_DA] [nvarchar](8) NOT NULL,
    CONSTRAINT [PK_RT_TYPE_STRING] 
        PRIMARY KEY CLUSTERED ([NO_DA] ASC)
                WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, 
                      IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, 
                      ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

这是我的存储过程,如果你想看的话:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[CSDN_CreateDemandeAppro]
    @EXER_FIN   nvarchar(8),
    @UNIT_ADM   nvarchar(6),
    @NOM_CONT   nvarchar(30),
    @MNT_TOTAL  numeric(15, 2)
AS
    DECLARE
            @NO_DA  nvarchar(8),
            @TYPE   nchar(1),
            @STAT   nchar(1),
            @ETAT   nchar(1),
            @IND_ENG    nchar(1),
            @IND_APPR   nchar(1),
            @TYPE_TRAIT nchar(1),
            @TEL    nvarchar(11),
            @POSTE  nvarchar(5),
            @NOM_ACHET  nvarchar(30),
            @COMMENT_ACHET  nvarchar(255),
            @DATE_CREAT smalldatetime,
            @DATE_MAJ   smalldatetime,
            @DATE_APPR  smalldatetime,
            @CODE_FOND  tinyint,
            @NO_COMM_DOFIN  nvarchar(9),
            @NO_MAG nvarchar(6),
            @NO_SEQ int,
            @NO_DA_OUT int
    BEGIN TRAN
        SELECT @NO_DA = PROC_NO_DA FROM ACH_UNIT_ADM_NUM WHERE UNIT_ADM = @UNIT_ADM and EXER_FIN = @EXER_FIN ;
        UPDATE ACH_UNIT_ADM_NUM SET PROC_NO_DA = @NO_DA + 1 WHERE UNIT_ADM = @UNIT_ADM and EXER_FIN = @EXER_FIN ;
    COMMIT;
    SET @TYPE = '0';
    SET @STAT = '3';
    SET @ETAT = 'C';
    SET @IND_ENG = '0';
    SET @IND_APPR = '0';
    SET @TYPE_TRAIT = '1';
    SET @TEL = NULL;
    SET @POSTE = NULL;
    SET @NOM_ACHET = NULL;
    SET @COMMENT_ACHET = 'APPROVISIONNEMENT.CSDN.QC.CA';
    SET @DATE_CREAT = GETDATE();
    SET @DATE_MAJ = GETDATE();
    SET @DATE_APPR = NULL;
    SET @CODE_FOND = '1';
    SET @NO_COMM_DOFIN = NULL;
    SET @NO_MAG = NULL;
    SET @NO_SEQ = 1;
    SET @NO_DA_OUT = 0;


    INSERT INTO DBO.ACH_DA 
    VALUES (
        @EXER_FIN,
        @NO_DA,
        @UNIT_ADM,
        @TYPE,
        @STAT,
        @ETAT,
        @IND_ENG,
        @IND_APPR,
        @TYPE_TRAIT,
        @NOM_CONT,
        @TEL,
        @POSTE,
        @NOM_ACHET,
        @COMMENT_ACHET,
        @DATE_CREAT,
        @DATE_MAJ,
        @DATE_APPR,
        @MNT_TOTAL,
        @NO_SEQ,
        @CODE_FOND,
        @NO_COMM_DOFIN,
        @NO_MAG);
    Select @NO_DA;

SSMS trace:

exec sp_executesql N'EXEC dbo.CSDN_CreateDemandeAppro @sp1, @sp2, @sp3, @sp4',N'@sp1 nvarchar(8),@sp2 nvarchar(3),@sp3 nvarchar(12),@sp4 decimal(4,2)',@sp1=N'20162017',@sp2=N'590',@sp3=N'430614451421',@sp4=22.18

无法在实体框架中获得此存储过程的返回值

哈哈哈…在存储过程的末尾替换:

Select @NO_DA;

Select @NO_DA NO_DA;

所以列实际上得到了一个名称…NO_DA…

一个未命名的列不能在实体中返回,原因很明显…