ssteenkiste / nettiers

Automatically exported from code.google.com/p/nettiers
1 stars 0 forks source link

Entity is Validated multiple times during service save. #377

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.  Save an invalid Entity via its Service Layer 

2.  Note how it checks if the entity IsValid, and then throws an 
EntityNotValidException if it is invalid.

3. When the entity.Error is passed as a parameter to the new instance of the 
EntityNotValidException, the get method in the Error property of the 
EntityBaseCore then checks to see if the entity is valid for a second time.  

What is the expected output? What do you see instead?

I only want my entity to be validated once.  When the error string is produced, 
It should check to see if the entity was already validated.

What version of .netTiers and CodeSmith are you using?
Using the latest of both.

Please provide any additional information below.
Not sure how to fix this one, without removing the "IsValid" check in the Error 
Parameter of the EntityBaseCore.

Original issue reported on code.google.com by beriniw...@gmail.com on 2 Mar 2011 at 7:16

GoogleCodeExporter commented 9 years ago

Original comment by bniemyjski on 4 Mar 2011 at 8:07

GoogleCodeExporter commented 9 years ago
Yes, This behavior with the IsValid property causes that validation process 
will be performed two times, causing slow response in the UI layer (assuming 
that you have a lot of records, let me say 200000), now load the records and 
set this TList<T> of records as datasource in a GridView control with edit 
feature enabled. You will see the red warning icon with the errors in the data 
being retrieved in the grid. I think that IsValid property MUST to be verified 
if and only if the IsDirty property is true. If you see the 
EntityBaseCore.generated.cst file, the IsValid property call to Validate() 
method, reviewing the code generated by templates, let me say Processors, first 
call the Validate() method and next verify the result evaluating the IsValid 
property, causing with this two validations. For solves this issue I  wrote 
following code in the EntityBase.cst template:

public override bool IsValid
{
    get
    {
        if (IsDirty)
            return base.IsValid;
        else
            return true;
    }
}  

Doing this override, you don't need to call the Validate() method, you only 
evaluate the IsValid property.

Regards
César F. Qüeb Montejo
Senior Software Developer Engineer
MJJ Briliant, Inc

Original comment by cesar.q...@gmail.com on 2 Feb 2012 at 3:53

GoogleCodeExporter commented 9 years ago
Additional comments to my previous post:

Obviously you need to call the GetPaged() method to avoid retrieve all records 
in the source, but let me say that I'm implementing this approach and the 
performance is slow anyway. What if your entity requires five or ten rules for 
validation?..

Check code in the ProcesorBase class, specifically in the Process() method that 
drop in this issue (i.e. country entity):

public override IProcessorResult Process()
{
  _country.AddValidationRuleHandler(ValidateIfCountryExists, "CountryExists");
  // check country
  _country.Validate();
  if ( !_country.IsValid )
      ProcessResult.AddBrokenRulesList(typeof(Entities.Country), _country.BrokenRulesList);

  return ProcessResult;
}

Regards

Original comment by cesar.q...@gmail.com on 2 Feb 2012 at 4:10