views:

250

answers:

2

Can I get return values returned by stored procedure using InsertOnSubmit in LINQ.

The stored procedure return a error number. How can I get this error number InsertOnSubmit (using stored procedure instead of Runtime sql). Many Thanks

A: 

On the data-context are a number of partial methods for insert/update/delete of each entity type; if you implement the other half of this, you can provide your own SP logic:

partial class MyDataContext {
    partial coid UpdateMyEntity(MyEntity instance) {
        // your ADO.NET code and/or ExecuteCommand here...
    }
}

Note that if you use a separate connection you won't have the same transaction etc (unless it uses TransactionScope).

Marc Gravell
Can you please provide an example. Will prefer to use the same to use the same transaction scope and the same connection. Shall we override insertonsubmit or submitchanges. Many thanks.
Sumanta
I will have to investigate... not a quick answer, I'm afraid.
Marc Gravell
A: 

I overloaded the default function generated by LINQ designer and followed the below steps.

  1. Created a public readonly property _ReturnCode
  2. In the overloaded function I used _ReturnCode = CType(result.ReturnValue, Integer)

Public Function FUNC_NAME( ByRef ..... Dim result As IExecuteResult = Me.ExecuteMethodCall(Me, CType(MethodInfo.GetCurrentMethod, MethodInfo), ......)

ID= CType(result.GetParameterValue(0), System.Nullable(Of System.Guid))

_ReturnCode = CType(result.ReturnValue, Integer) Return CType(result.ReturnValue, Integer)

End Function

Let me know if anybody has a better answer. Many Thanks

Sumanta