newcoder
newcoder

Reputation: 25

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);

Upvotes: 0

Views: 163

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1063338

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.

Upvotes: 1

Related Questions