UpdateEntity issue

Posts   
 
    
kdekok
User
Posts: 26
Joined: 07-Apr-2008
# Posted on: 11-Apr-2008 16:15:18   

It's probably because i do not (yet) understand the full range of power of the llblgen generated code and therefore am not using it right,

But this issue is keeping me busy for some time now, so i want to post it to see what's going on.

I use the LLBLGendatasource bound to a gridview. The data comes from 1 table TUser. there is a unique constraint on the field UserName.

When one row is updated and the username is changed to a username already existing, an exception is thrown in the following generated code in the TUserEntity class:

        /// <summary> Performs the update action of an existing Entity to the persistent storage.</summary>
        /// <returns>true if succeeded, false otherwise</returns>
        protected override bool UpdateEntity()
        {
            TUserDAO dao = (TUserDAO)CreateDAOInstance();
                                                 return dao.UpdateExisting(base.Fields, base.Transaction);
}

There is no way for me to catch this exception, other than altering this method myself and enclose it in try catch block, but since it is generated code, that can never be the intention, is it?

I read some posts about having to use validatebeforesave to do my own validation, but oughnestly i do not really know where to start. Do i have to do this for every entitytype? Where should i overload the classes?

Can someone get me started in doing checks for unique constraints in such a way that i can detect or catch errors and display them correctly to the user?

I use the LLBLGenDataSource as SelfServicing and tried both livepersistance true and false.

Thanks a lot!

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 11-Apr-2008 16:40:27   
I use the LLBLGenDataSource as SelfServicing and tried both livepersistance true and false.

Disabling LivePersistence, you may catch the exception in the PerformWork event handler.

kdekok
User
Posts: 26
Joined: 07-Apr-2008
# Posted on: 11-Apr-2008 16:59:15   

This is becoming interesting!

I already tried that before and unfortunately that was not working either:


        void PFMDataSource_PerformWork(object sender, PerformWorkEventArgs e)
        {
            try
            {
                using (Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "PerformWork"))
                {
                    e.Uow.Commit(trans, true);
                }
            }
            catch (Exception ex)
            {
                // It never gets here !
            }
        }

The exception was never bubling up to this layer.

But, when i ran this code without debugging, it was catched! So i'm being dumb obviously! flushed

Can you tell me what to change so that the exception is not thron in the debugger but bubles up to the surface just as it is when running without debugging? Thanks alot!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 12-Apr-2008 09:59:16   

Any exception which isn't caught should bubble up. So remove the try/catch clause and see if it ends up in the page. Disable a custom error page in the web.config obviously

Frans Bouma | Lead developer LLBLGen Pro
kdekok
User
Posts: 26
Joined: 07-Apr-2008
# Posted on: 14-Apr-2008 11:23:40   

I managed now to catch the errors, while doing e.Uow.Commit(),

Any exception is caught, but i do not think this is a proper way.

Now i have to catch queryexecutionexceptions, go through the innerexception(s) and sqlerrors to see what is going on and report this to the user, all in the performwork event.

I now also noted the ValidateEntityBeforeSave, but as soon as i override this method, no work is done, even if there is no problem. I obviously have to tell the calling procedure that everything is validated, or not, but how do i do this? The returnvalue of this method is void, and i do not see any meaningfull properties on the entity to set... How to work with the Validateentitybeforesave routines ?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Apr-2008 06:38:44   

kdekok wrote:

I managed now to catch the errors, while doing e.Uow.Commit(),

Any exception is caught, but i do not think this is a proper way.

Now i have to catch queryexecutionexceptions, go through the innerexception(s) and sqlerrors to see what is going on and report this to the user, all in the performwork event.

IMHO... at some point you have to catch them. Where to catch?: depends upon the software layer and the exception's type.

kdekok wrote:

I now also noted the ValidateEntityBeforeSave, but as soon as i override this method, no work is done, even if there is no problem. I obviously have to tell the calling procedure that everything is validated, or not, but how do i do this? The returnvalue of this method is void, and i do not see any meaningfull properties on the entity to set... How to work with the Validateentitybeforesave routines ?

You can use IDataErrorInfo, also throw _ORMEntityValidationException _instances. Please read LLBLGenPro Help - Using the generated code - Validation per field or per entity. Also there are some validation examples at LLBLGenPro site.

David Elizondo | LLBLGen Support Team