实体框架存储过程返回类型已更改

时间:2016-02-06 20:33:29

标签: c# sql-server entity-framework stored-procedures

我主要通过删除我的.EDMX文件并再次添加来更新我的数据模型,只是为了确保我获得了数据库中的所有内容。

我遇到了一个奇怪的问题,在删除并重新添加.EDMX后,我的一个存储过程返回类型已被更改。存储过程代码保持不变,可以在下面找到。我不确定我做错了什么?

SQL Server存储过程(从未更改):

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER procedure [dbo].[usp_SearchOrders]
      @orderid int = null, @statusid int = null, 
      @startdate datetime = null, @enddate datetime = null,
      @customername varchar(30) = null, @customeraddress varchar(30) = null
AS
     SELECT 
         O.OrderID Order_ID, O.OrderDate,
         OrderTotal = (SELECT SUM(od.UnitPrice - (od.UnitPrice * od.Discount)) 
                       FROM [Order Details] od 
                       WHERE od.OrderID = O.OrderID),
         Discount = (SELECT SUM(od.UnitPrice * od.Discount) 
                     FROM [Order Details] od 
                     WHERE od.OrderID = O.OrderID),
         CC.Email1, CC.Phone,
         Status = (SELECT OS.OrderStatusName 
                   FROM OrderStatus OS 
                   WHERE OS.OrderStatusID = O.OrderStatusID),
         OrderType = (SELECT OT.OrderTypeName 
                      FROM OrderType OT 
                      WHERE OT.OrderTypeID = O.OrderTypeID)
     FROM
         Orders O 
     JOIN 
         Customers C ON O.CustomerID = C.CustomerID
     JOIN 
         CustomersContactDetails CC ON C.CustomerID = CC.CustomerID
     WHERE 
         (O.OrderID = @orderid OR @orderid IS NULL)
         AND (O.OrderStatusID = @statusid OR @statusid IS NULL)
         AND (O.OrderDate >= @startdate OR @startdate IS NULL)
         AND (O.OrderDate <= @enddate OR @enddate IS NULL)
         AND (C.CustomerName LIKE @customername OR @customername IS NULL)
         AND (CC.Address LIKE @customeraddress OR @customeraddress IS NULL)
         AND (CC.City LIKE @customeraddress OR @customeraddress IS NULL)

C#代码:_dbContext.usp_SearchOrders(1,1,DateTime.Now, DateTime.Now.AddDays(1),'Hitin','BH');

更新前返回类型:usp_SearchOrders_Result

重新添加返回类型后:int

我从未制作任何复杂类型或进行过任何映射,类usp_SearchOrders_Result是自己创建的。

这个问题可能背后的原因是什么?

1 个答案:

答案 0 :(得分:1)

您需要在存储过程的顶部设置“SET NOCOUNT ON”。