0

我编写了以下存储过程,效果很好。我想用它做的是将它用作实体数据模型。但是,在实体数据模型中使用它会映射到整数的返回类型和零值。

如何让 SP 使用 DataContext 返回实际数据而不是整数?

IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE TYPE = 'P' AND NAME = 'myProc') DROP PROCEDURE myProc;
GO
CREATE PROCEDURE [dbo].myProc
@START DateTime, @STOP DateTime
AS
BEGIN TRY

    CREATE TABLE #Temp (download_Pk int);
    INSERT INTO #Temp 
    SELECT      download_pk FROM t1
    UNION       ALL
    SELECT      download_pk FROM t2;    

    WITH 
    x as 
    (
        SELECT      ID as Caps_Pk,
                    rootID as [Caps_RootId],
                    Case400Series as [Case],
                    SUBSTRING(c1, CHARINDEX('_', c1,1)+1, LEN(c1)) as [Customer],
                    run as Run,                     
                    SUBSTRING(c2, 1, CHARINDEX('_', c2, 1) -1) as [Sample], 
                    SUBSTRING(c2, CHARINDEX('_', c2,1)+1, len(c2)) as [Amplification],
                    projectTitle,
                    DateAdded as [UploadTime],                  
                    UserId as [User]
        FROM        t3 
        WHERE       DateAdded >= @START AND DateAdded <= @STOP AND
                    [User] in (SELECT name FROM ViewUsers WHERE Site = 'abc' AND Role = 'def')
    )   

    SELECT      *
    FROM        x
    WHERE       Caps_Pk NOT IN (Select download_Pk from #Temp)

    DROP TABLE #Temp;

END TRY

BEGIN CATCH
    DROP TABLE #Temp;       

END CATCH

提前致谢。

4

2 回答 2

1

你看过这个Code First Stored Procudure 吗,这对我很有用,它还有一个你可以安装的NuGet Pckage

于 2013-04-02T13:13:59.733 回答
1

在这里找到答案:EF4 - 选定的存储过程不返回任何列

“EF 不支持导入从:动态查询临时表中构建结果集的存储过程,原因是要导入过程 EF 必须执行它。”

于 2013-04-08T07:42:14.810 回答