SelfServicing Entity Save Return Values

Posts   
 
    
DaveH
User
Posts: 6
Joined: 01-Oct-2007
# Posted on: 03-Mar-2008 16:28:06   

We have been curious as to under what conditions would the Save() overrides in the **EntityBase **for the **selfservicing **model return false?

I have been unable to find any documentation other than ...

true if all changed fields were successfully persisted to the database, false otherwise

Currently all of our calls to the save methods on entities are wrapped in an if statement which will throw an exception in our framework to ensure it is logged and that we become aware that a save (rather an update or insert) was not persisted. If there are actual scenarios where the Save() overrides will return false, then we will consider wrapping this check somewhere so we have it in one place.

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 03-Mar-2008 17:05:30   

I hope I'm in the same page here, the reasons for the save method to return false (i.e. the entity wasn't successfully persisted to the database) could vary from incorrect values of the fields to any database related issue (lost connection, foreign keys or some other kind of logic).

DaveH
User
Posts: 6
Joined: 01-Oct-2007
# Posted on: 03-Mar-2008 17:38:07   

But I think one of those issues would throw an exception. So I am trying to figure out which scenarios throw an exception and which would return a value of false.

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 03-Mar-2008 18:02:43   

As a good practice I'll advice you to wrap all the functions that persist data with a try-catch statement additionally to the if method that you're using.

DaveH
User
Posts: 6
Joined: 01-Oct-2007
# Posted on: 03-Mar-2008 18:15:45   

Thank you for the prompt responses...

Let me start over. I simply want to know under what condition will the save return 'false'?

Everything I have seen would cause an exception to be thrown if the persistence fails. Assuming that is the case, what is the reason for the return value if exceptions are always thrown?

Assuming a failed save does NOT always throw an exception, what specific scenarios would cause save to return false?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 04-Mar-2008 03:02:03   

For example, if the entity isn't dirty (there is nothing to save).

David Elizondo | LLBLGen Support Team
DaveH
User
Posts: 6
Joined: 01-Oct-2007
# Posted on: 04-Mar-2008 14:46:40   

Thanks David. So if there is nothing to save because an entity is not dirty, then False will be returned. That makes sense...

The way you posed the answer makes it seem like there are other conditions where this would occur.

If so could those be listed? I ask because we may care about the return value under certain circumstances.

Thanks for you help.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 04-Mar-2008 16:39:44   

Dave, sorry if my answer was too tiny.

If there is nothing to save, Save returns true. (everything is O.K., it's just there is nothing to persist.

If the user is denied from insert/update an entity, Save returns false. (See authorization at docs for more info).

If you update an entity, or you update an entity with an update restriction, and the execute action return that 0 rows was affected, Save returns false.

You receive exceptions if, for example, the fields are null.

David Elizondo | LLBLGen Support Team