Thursday, April 28, 2011

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

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

From stackoverflow
  • 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).

    Sumanta : 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.
    Marc Gravell : I will have to investigate... not a quick answer, I'm afraid.
  • 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

0 comments:

Post a Comment