[英]Issue with return Value when calling stored procedure from EF4
我在SQL Server 2008中編寫了以下存儲過程:
ALTER Procedure [dbo].[usp_TodayNumberOfRegisteration]
(
@TodayShamsiDate nvarchar
)
AS
Select COUNT(csci.Id) as cc1 FROM dbo.Complex_Service_Cart_Items csci INNER JOIN dbo.Complex_Service_Cart csc
ON csci.Id_Complex_Service_Cart=csc.Id
WHERE (csci.Id_Complex_Service='2cca1a67-34f4-4837-bebe-f3ba4c72b98d' or csci.Id_Complex_Service='8430cad2-dbb1-4425-bb8b-a7e158f688c4')
and csc.TFIsPaymentComplete=1
and csc.TFDateBackFromBankp= RTRIM( @TodayShamsiDate)
我通過這種方式通過EF4從C#codebehind調用它:
string shamsiDate = Date.getShamsiDate();
returnValue = Convert.ToString(db.getTodayNumberOfRegisteration(shamsiDate).First().Value);
其中getTodayNumberOfRegisteration
是我添加到我的edmx
模型的函數。
現在問題是:當我在SQL Server中執行存儲過程而不是
and csc.TFDateBackFromBankp= RTRIM( @TodayShamsiDate)
我設置了類似的東西:
and csc.TFDateBackFromBankp= RTRIM( '1391/12/05')
此存儲過程返回值6
但是當我從C#codebehind傳遞參數時,我得到返回值'0'
任何幫助,將不勝感激。
我通常這樣做:在Add Function Import
對話框中,選擇你的存儲過程並定義它返回一個Scalars集合:Int32 :
然后在你的代碼中,像這樣調用它:
int value = db.getTodayNumberOfRegisteration(shamsiDate).First().Value;
這通常對我來說很好。
如果你沒有將它定義為返回一個集合:Int32 ,那么你得到的值似乎是存儲過程調用的返回值 ,例如受存儲過程執行影響的行數(對於SELECT
,0或-1,因為您實際上沒有插入,更新或刪除任何行):
我發現了這個問題:我以這種方式設置了參數:
@TodayShamsiDate nvarchar
我應該指定nvarchar的長度
@TodayShamsiDate nvarchar(10)
我做到了,問題解決了!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.