run validations on an entire database

Posts   
 
    
jspanocsi
User
Posts: 145
Joined: 04-Mar-2005
# Posted on: 02-Mar-2012 20:00:22   

I've been tasked with running llbl gen validators against entire databases. Basically when we bring on a new client and convert their data, they want to loop through all the entities and validate them all since the conversions are rarely fully correct.

While most of this is straight forward, i just wanted to throw a question out there for anyone that may have done something similar or has any input on this. For the most part it's pretty easy, but in some cases it gets more complicated. For instance, if you have a purchaseorder entity with detail line items, the amount paid on the PO has to equal the line items. This is one of our validators. This complicates it some since it's not always single entity validations.

Any ideas/thoughts/stuff i didn't think of?

is there an easy way to serialize an entity data into xml or something easy to read when one fails that i can write to a database table?

Thanks!

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 02-Mar-2012 20:27:00   

I thing LLBLGen Validators is not you need here. LLBLGen Validation is triggered by certain events like setting a field value, or validate it before a save action, etc. However there also a genral method called ValidateEntity(), which isn't used internally by the LLBLGen Pro runtime, but can be used by your own code to validate an entity in any context.

So, an approximation code could be like this:

// fetch entities to validate
var orders = SomeMethodToFetchThem();

foreach(var o in orders)
{
     try
    {
          o.ValidateEntity();
     }
     catch (Exception e)
    {
           // log the error.. this is somehow you can serialize the entity.
           MemoryStream ms = new MemoryStream();
           BinaryFormatter bf = new BinaryFormatter(null, new          StreamingContext(StreamingContextStates.Clone));
           bf.Serialize(ms, o);
     }
}
David Elizondo | LLBLGen Support Team