How to take input from SQL stored procedure to a return statement

308 Views Asked by At
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

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

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?

1

There are 1 best solutions below

1
On

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