简体   繁体   中英

returning scopeidentity from a stored proc in linq to sql

I have a stored procedure which is returning the scopeidentity. I dropped the table and the stored procedure to the dbml. The return type of the function is

return ((ISingleResult<storedocumentResult>)(result.ReturnValue));

In the C# code I am using the datacontext to insert a new entry into the table via the stored procedure. I need to return the scopeidentity to a calling method, but I don't know how to access it.

ISingleResult<storedocumentResult> result = dbc.storedocument(doc.DocumentName, doc.FileExtension);

It will either be in result.ReturnValue (which is object ), or via result.Single().Foo , where Foo is some property on the (generated) storedocumentResult .

If the former, note that SCOPE_IDENTITY() is numeric(38,0) , so you may need int id = (int)(decimal)result.ReturnValue; to do the casts and conversions correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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