[英]returning scopeidentity from a stored proc in linq to sql
我有一個存儲過程返回范圍標識。 我將表和存儲過程放到了dbml中。 該函數的返回類型為
return ((ISingleResult<storedocumentResult>)(result.ReturnValue));
在C#代碼中,我正在使用datacontext通過存儲過程將新條目插入表中。 我需要將scopeidentity返回給調用方法,但是我不知道如何訪問它。
ISingleResult<storedocumentResult> result = dbc.storedocument(doc.DocumentName, doc.FileExtension);
它可以在result.ReturnValue
(它是object
)中,也可以在result.ReturnValue
( result.Single().Foo
,其中Foo
是(生成的) storedocumentResult
上的某些屬性。
如果是前者,請注意SCOPE_IDENTITY()
為numeric(38,0)
,因此您可能需要int id = (int)(decimal)result.ReturnValue;
正確進行轉換和轉換。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.