DataPortal_Insert Cancel

DataPortal_Insert Cancel

Old forum URL: forums.lhotka.net/forums/t/8637.aspx


Imker posted on Wednesday, March 10, 2010

in DataPortal_Insert I use a stored procedure to get

the next free key to assign to my BusinessObject when beeing inserted into the

database. As the key generation saves the used key to the database, I would prefer not to

get the key prior to DataPortal_Insert.

 

What would be the best way to communicate back and cancel the insertion, when no more keys

are available?

I tried to throw an expection, but then I got a DataPortalException was unhandled by user code.

 

Thanks for an ideas and hints.


ajj3085 replied on Wednesday, March 10, 2010

Well, throwing an exception is probably your best bet.  If you don't want the UI to handle a DataPortalException, and instead handle your specific exception, you can override your Save method and throw the BusinessException from the DataPortalException.

Imker replied on Wednesday, March 10, 2010

Hi Andy.

Yep, I thought so too. 

 

In the DataPortal_insert()

I got something like this:

                    if (NoMoreKeys)

                    {

                        throw new DataPortalException("no keys", this);

                    }

and on the UI side

try

                {

                    businessObject= businessObject.Save();

                }

                catch (DataPortalException ex)

                {

                       // do something

                }

but then I got an "DataPortalException was unhandled by user code" error

Where am I missing the point?

 

ajj3085 replied on Wednesday, March 10, 2010

Well you wouldn't throw  a DataPortalException;  create your own exception like NoMoreKeysException.

Although the handler you have should be working, although there is Csla.DataPortalException and Csla.Server.DataPortalException.  Perhaps you're throwing the one in the server namespace (b/c you have using Csla.Server for some reason) and on your UI side you have a using Csla;

Either way still make your own specific exception :-)

Imker replied on Wednesday, March 10, 2010

Thanks for the hint,

the own exception is cleaner code for sure.

but even with this one I get the error, that the NoMoreKeysException was unhandled by user code.

I think I forgot something important, but can not put a finger on it.

 

data portal insert:

 

 

                    if (NoMoreKeys)

                    {

                        throw new NoMoreKeysException("no keys");

                    }

 

and on the UI side

 

try

                {

                    businessObject= businessObject.Save();

                }

                catch (DataPortalException ex)

                {

                       // do something

                }

 

 

ajj3085 replied on Wednesday, March 10, 2010

Remember that an exception thrown inyour DP_I method will be wrapped by a DataPortalException, unless you unwrap it on the client and rethrow (likely in your Save override).

Also keep in mind that if you're debugging, your settings in VS will affect if your exception code gets to run.  Maybe you should try doing a Debug -> Exceptions, and then clicking the Reset All button. 

Imker replied on Thursday, March 11, 2010

Yep, the wrapping was in my mind, but wasn't the problem.

You pointed me into the right direction, its VS.

 

http://blogs.msdn.com/scottno/archive/2005/05/10/416133.aspx

This is where it happens:

Of course, if you really don't want to hear about these events, you can go to Debug->Exceptions and deselect the "user-unhandled" column.


How to: Break on User-Unhandled Exceptions http://msdn.microsoft.com/en-us/library/038tzxdw(VS.80).aspx

 

I knew that I'm a CSLA beginner, now I now that even in VS a lot is still terra incognita to me.

Thanks, that was a great help for me.


 


Copyright (c) Marimer LLC