简体   繁体   English

如何将输入从SQL存储过程输入到return语句

[英]How to take input from SQL stored procedure to a return statement

alter procedure [dbo].[XXX] 
(
    @vendorworksationID uniqueidentifier  ,
    @sdate date,
    @edate date,
    @total int out 
)
begin 
   select @total = COUNT(*)    
   from AdvertisedCampaignHistory a  
   where 
       CAST(a.CreationDate AS DATE) BETWEEN CAST(@sdate as DATE) AND CAST(@edate as DATE)   
       and a.CampaignID in (select cc.BCampaignID 
                            from BeaconCampaign cc, VendorWorkStation vw 
                            where cc.VendorWorkStationID = vw.VendorWorkStationID 
                              and VendorID = @vendorworksationID) 
   return @total 
end 

The above code shows the stored procedure that return an integer value from SQL Server 上面的代码显示了从SQL Server返回整数值的存储过程

ObjectParameter Output = new ObjectParameter("total", typeof(Int32));
var resBC = this.Context.getTotalSentBeaconCampaign(VendorWorkstationID, sdate,edate,Output).FirstOrDefault();

The above code shows how I am passing parameters and retrieving the value on the C# side 上面的代码显示了我如何在C#端传递参数并检索值

While running the code I am getting following error 运行代码时出现以下错误

The data reader returned by the store data provider does not have enough columns for the query requested. 商店数据提供者返回的数据读取器没有足够的列用于请求的查询。

What could be the possible cause for this error? 造成此错误的可能原因是什么?

Entity Framework cannot support Stored Procedure Return scalar values out of the box.To get this to work with Entity Framework, you need to use "Select" instead of "Return" to return back the value. 实体框架不支持开箱即用的存储过程返回标量值。要使其与实体框架一起使用,您需要使用“选择”而不是“返回”来返回该值。

More Ref : http://www.devtoolshed.com/using-stored-procedures-entity-framework-scalar-return-values 更多参考资料: http : //www.devtoolshed.com/using-stored-procedures-entity-framework-scalar-return-values

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM