IEntityValidator and Transactions

Posts   
 
    
Posts: 33
Joined: 31-May-2005
# Posted on: 09-Jul-2009 17:45:13   

We're having trouble with deadlocks when trying to validate an entity within a transaction. The issue is that the Validator must perform a FetchEntityCollection which also contains the item being validated (we're still using v1 on this app, only our newer stuff has v2).

Note that the FetchEntityCollection code below is within a separate manager class, I just combined/simplified the code for readability:

class BankEntityValidator : IEntityValidator
{
   bool IEntityValidator.Validate(object containingEntity)
   {
      BankEntity entity = (BankEntity)containingEntity;

      //Get list of all banks (normally BankEntityManager.FetchAllBanks())
      EntityCollection allBanks = new EntityCollection(new BankEntityFactory());
      RelationPredicateBucket bucket = new RelationPredicateBucket();
      using (DataAccessAdapter adapter = new DataAccessAdapter(CONN_STRING, false, CatalogNameUsage.ForceName, "testDB"))
      {
         adapter.FetchEntityCollection(tempCollection, bucket);
      }

      //Verify that there is only 1 active bank
      Int32 iNumActive = 0;
      foreach (BankEntity bank in allBanks)
      {
         if (bank.IsActive == "Y")
         {
            iNumActive++;
         } 
      }
      if (iNumActive > 1)
      {
         throw new ORMEntityValidationException("Can only have 1 active bank.", entity);
      }

      //A-OK
      return true;
   }
}

Is there a way that the FetchEntityCollection can use the same adapter was used by the SaveEntity (that kicked off this validation)?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 09-Jul-2009 20:13:56   
David Elizondo | LLBLGen Support Team