Page 1 of 1

Updating records using view and stored procedures

Posted: Fri 02 Oct 2009 10:59
by GlennBA
Hi

This may be a trivial Linq question ...
I am using views and stored procedures.
If I update 10 rows in my UI and use SubmitChanges, the Update SP is called for each row, which is fine.
Problem is, the SP might throw an exception for one of the rows due to logic in the procedure. I can easily catch the exception but how do I know which one of the 10 rows that failed ?
ChangeConflicts is empty. ChangeSet.Updates contains all 10 rows.
So I am stuck.
Do we have to provide logic in the SP to return the failed rows primary key ?

Best regards
Glenn

Posted: Mon 05 Oct 2009 09:04
by AndreyR
You should declare the following partial method in your datacontext:

Code: Select all

partial void DataContext.OnSubmitError (Devart.Data.Linq.SubmitErrorEventArgs e);
Then you can select one of possible ContinueActions (Continue, Retry, Abort)

Posted: Mon 05 Oct 2009 11:57
by GlennBA
I am not quite sure how to do that:

In a new file I have defined this:
(my dataContext is called AmKurveregDataContext)

Code: Select all

    
partial class AmKurveregDataContext
    {
        partial void OnSubmitError(Devart.Data.Linq.SubmitErrorEventArgs e)
        {
        }
  }
But I get
Error:
No defining declaration found for implementing declaration of partial method 'AmKurvereg.AmKurveregDataContext.OnSubmitError(Devart.Data.Linq.SubmitErrorEventArgs)'
So what more do I need to do ?

Posted: Tue 06 Oct 2009 10:23
by AndreyR
As a solution, just remove "partial" in the definition.
Then you should be able to maintain errors in this method.

Posted: Tue 06 Oct 2009 10:59
by GlennBA
Sorry, but how should this function be called ?
It looks like an eventhandler but shouldn't it be hooked up to something ?

Posted: Tue 06 Oct 2009 11:59
by GlennBA
Hi

I have solved my problem like this:

Code: Select all

            try
            {
                Context.SubmitChanges();
            }
            catch (Exception ex)
            {
                    foreach (Devart.Data.Linq.ObjectSubmitError ose in Context.Errors)
The ose contains a reference to the object that failed. Perfect!