IEntity2 information on

Posts   
 
    
Meindert
User
Posts: 63
Joined: 07-Nov-2012
# Posted on: 10-Mar-2016 08:58:55   

In our controls we have a base class with the following Save function. If the Save entity fails, throws an exception, we call Entity.SetEntityError("Invalid record"). This results in the DevExpressXtraGrid is a error message.


public virtual void SaveChanges( IEntity2 Entity, bool RecurseSave = true)
{
    if (Entity != null) {
        try {
            using (DataAccessAdapter adapter = DataAccessAdapter.CreateInstance()) {
                adapter.SaveEntity(Entity, true, RecurseSave);
                mDataStatus = DataStatuses.DataSaved;
            }
        } catch (ORMQueryExecutionException ex) {
            mDataStatus = DataStatuses.Errors;
            mExceptionMessage = ex.Message;
                        Entity.SetEntityError("Invalid record");
        }
    }
}

After the function is called we like to rebuild the grid and like to make the failed row "red", but to do that we need to ask each entity if it is failed or not. The only property I could find is IsDirty, but than the row is getting red at the moment we change the fields.

Is there a way to ask the entity if it failed writing to the database?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 10-Mar-2016 11:18:53   

The entity which failed is in the exception: ORMQueryExecutionException.InvolvedEntity. You can obtain the entity from the catch handler and use that with rebuilding the grid, I think simple_smile

Frans Bouma | Lead developer LLBLGen Pro